Skip to main content
summaryrefslogtreecommitdiffstats
blob: 64c43c53823f742dc23774260aaf134c59eae661 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * 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 org.eclipse.emf.cdo.eresource.EresourcePackage;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Eike Stepper
 */
public class Classes
{
  public static final String PROPERTIES = "props";

  private Map<EClassifier, Integer> classifierToIDs = new HashMap<EClassifier, Integer>();

  private Map<Integer, EClassifier> idToClassifiers = new HashMap<Integer, EClassifier>();

  private MongoDBStore store;

  private boolean initialized;

  private int lastClassifierID;

  private int resourceNodeClassID;

  private int resourceFolderClassID;

  private int resourceClassID;

  public Classes(MongoDBStore store)
  {
    this.store = store;
  }

  public MongoDBStore getStore()
  {
    return store;
  }

  public int getLastClassifierID()
  {
    return lastClassifierID;
  }

  public void setLastClassifierID(int lastClassifierID)
  {
    this.lastClassifierID = lastClassifierID;
  }

  public synchronized int getResourceNodeClassID()
  {
    initialize();
    return resourceNodeClassID;
  }

  public synchronized int getResourceFolderClassID()
  {
    initialize();
    return resourceFolderClassID;
  }

  public synchronized int getResourceClassID()
  {
    initialize();
    return resourceClassID;
  }

  public synchronized int mapNewClassifier(EClassifier classifier)
  {
    int id = ++lastClassifierID;
    mapClassifier(classifier, id);
    return id;
  }

  public synchronized void mapClassifier(EClassifier classifier, int id)
  {
    classifierToIDs.put(classifier, id);
    idToClassifiers.put(id, classifier);

    if (classifier == EresourcePackage.eINSTANCE.getCDOResourceNode())
    {
      resourceNodeClassID = id;
    }
    else if (classifier == EresourcePackage.eINSTANCE.getCDOResourceFolder())
    {
      resourceFolderClassID = id;
    }
    else if (classifier == EresourcePackage.eINSTANCE.getCDOResource())
    {
      resourceClassID = id;
    }
  }

  public synchronized int getClassifierID(EClassifier classifier)
  {
    initialize();
    return classifierToIDs.get(classifier);
  }

  public synchronized EClassifier getClassifier(int id)
  {
    initialize();
    return idToClassifiers.get(id);
  }

  public synchronized EClass getClass(int id)
  {
    return (EClass)getClassifier(id);
  }

  private void initialize()
  {
    if (!initialized)
    {
      Commits commits = store.getCommits();
      commits.initializeClassifiers();
      initialized = true;
    }
  }
}

Back to the top