Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 015b4c8a3cc3984f78cd367fba1e1af275f6b44d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.server.internal.mongodb;

import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * @author Eike Stepper
 */
public class Props extends Coll
{
  public static final String NAME = "props";

  public static final String ID = "_id";

  public static final String VALUE = "value";

  public static final String REPOSITORY_CREATED = "org.eclipse.emf.cdo.server.mongodb.repositoryCreated"; //$NON-NLS-1$

  public static final String REPOSITORY_STOPPED = "org.eclipse.emf.cdo.server.mongodb.repositoryStopped"; //$NON-NLS-1$

  public static final String NEXT_LOCAL_CDOID = "org.eclipse.emf.cdo.server.mongodb.nextLocalCDOID"; //$NON-NLS-1$

  public static final String LAST_CDOID = "org.eclipse.emf.cdo.server.mongodb.lastCDOID"; //$NON-NLS-1$

  public static final String LAST_CLASSIFIERID = "org.eclipse.emf.cdo.server.mongodb.lastClassiferID"; //$NON-NLS-1$

  public static final String LAST_BRANCHID = "org.eclipse.emf.cdo.server.mongodb.lastBranchID"; //$NON-NLS-1$

  public static final String LAST_LOCAL_BRANCHID = "org.eclipse.emf.cdo.server.mongodb.lastLocalBranchID"; //$NON-NLS-1$

  public static final String LAST_COMMITTIME = "org.eclipse.emf.cdo.server.mongodb.lastCommitTime"; //$NON-NLS-1$

  public static final String LAST_NONLOCAL_COMMITTIME = "org.eclipse.emf.cdo.server.mongodb.lastNonLocalCommitTime"; //$NON-NLS-1$

  public static final String GRACEFULLY_SHUT_DOWN = "org.eclipse.emf.cdo.server.mongodb.gracefullyShutDown"; //$NON-NLS-1$

  public Props(MongoDBStore store)
  {
    super(store, NAME);
  }

  public Map<String, String> get(Set<String> names)
  {
    Map<String, String> result = new HashMap<String, String>();
    for (String name : names)
    {
      DBObject query = new BasicDBObject(ID, name);
      DBCursor cursor = collection.find(query);

      try
      {
        if (cursor.hasNext())
        {
          DBObject doc = cursor.next();
          result.put(name, (String)doc.get(VALUE));
        }
      }
      finally
      {
        cursor.close();
      }
    }

    return result;
  }

  public void set(Map<String, String> properties)
  {
    for (Entry<String, String> property : properties.entrySet())
    {
      DBObject doc = new BasicDBObject();
      doc.put(ID, property.getKey());
      doc.put(VALUE, property.getValue());

      collection.save(doc);

    }
  }

  public void remove(Set<String> names)
  {
    BasicDBList list = new BasicDBList();
    for (String name : names)
    {
      list.add(name);
    }

    DBObject ref = new BasicDBObject();
    ref.put(ID, new BasicDBObject("$in", list));

    collection.remove(ref);
  }
}

Back to the top