Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8261564d5baa428926d49fdd7af9197907dd3e50 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/**
 * Copyright (c) 2004 - 2011 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:
 *    Ibrahim Sallam - initial API and implementation
 */
package org.eclipse.emf.cdo.server.internal.objectivity.utils;

import org.eclipse.emf.cdo.server.internal.objectivity.bundle.OM;
import org.eclipse.emf.cdo.server.internal.objectivity.db.ObjyCommitInfoHandler;
import org.eclipse.emf.cdo.server.internal.objectivity.db.ObjyObject;
import org.eclipse.emf.cdo.server.internal.objectivity.db.ObjyPackageHandler;
import org.eclipse.emf.cdo.server.internal.objectivity.db.ObjyPropertyMapHandler;
import org.eclipse.emf.cdo.server.internal.objectivity.db.ObjyScope;
import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyBranchManager;
import org.eclipse.emf.cdo.server.internal.objectivity.schema.ObjyResourceList;

import org.eclipse.net4j.util.om.trace.ContextTracer;

import com.objy.db.ObjyRuntimeException;
import com.objy.db.app.ooId;

public class ObjyDb
{

  public static final String CONFIGDB_NAME = "ConfigDb";

  public static final String RESOURCELIST_NAME = "ResourceList";

  public static final String RESOURCELIST_CONT_NAME = "ResourceListCont";

  public static final String PACKAGESTORE_CONT_NAME = "PackageCont";

  public static final String COMMITINFOSET_CONT_NAME = "CommitInfoCont";

  public static final String COMMITINFOSET_NAME = "CommitInfoSet";

  public static final String PROPERTYMAP_NAME = "PropertyMap";

  public static final String PROPERTYMAP_CONT_NAME = "PropertyCont";

  public static final String OBJYSTOREINFO_NAME = "ObjyStoreInfo";

  public static final String DEFAULT_CONT_NAME = "_ooDefaultContObj"; // this is objy default cont name.

  public static final String BRANCHMANAGER_NAME = "BranchManager";

  public static final String BRANCHING_CONT_NAME = "BranchingCont";

  private static final ContextTracer TRACER_DEBUG = new ContextTracer(OM.DEBUG, ObjyDb.class);

  // private static final ContextTracer TRACER_INFO = new ContextTracer(OM.INFO, ObjyDb.class);

  private static final String PACKAGEMAP_NAME = "PackageMap";

  /***
   * Unitily functions..
   */

  /***
   * This function will return the resourceList after creation. Each repository (stored in its own DB) will have its own
   * ResourceList.
   */
  public static ObjyObject getOrCreateResourceList(String repositoryName)
  {
    if (TRACER_DEBUG.isEnabled())
    {
      TRACER_DEBUG.format("getOrCreateResourceList() for " + repositoryName); //$NON-NLS-1$
    }
    ObjyScope objyScope = new ObjyScope(repositoryName, ObjyDb.RESOURCELIST_CONT_NAME);
    ObjyObject objyObject = null;
    try
    {
      objyObject = objyScope.lookupObjyObject(ObjyDb.RESOURCELIST_NAME);
    }
    catch (ObjyRuntimeException ex)
    {
      // we need to create the resource.
      objyObject = createResourceList(objyScope);
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }

    return objyObject;
  }

  protected static ObjyObject createResourceList(ObjyScope objyScope)
  {
    if (TRACER_DEBUG.isEnabled())
    {
      TRACER_DEBUG.format("createResourceList()"); //$NON-NLS-1$
    }
    // TODO - this need refactoring...
    ObjyObject resourceList = ObjyResourceList.create(objyScope.getScopeContOid());
    objyScope.nameObj(ObjyDb.RESOURCELIST_NAME, resourceList);
    return resourceList;
  }

  protected static ooId createCommitInfoList(ObjyScope objyScope)
  {
    // TODO - this need refactoring...
    ooId commitInfoListId = ObjyCommitInfoHandler.create(objyScope.getScopeContOid());
    objyScope.nameObj(ObjyDb.COMMITINFOSET_NAME, commitInfoListId);
    return commitInfoListId;
  }

  public static ooId getOrCreateCommitInfoList(String repositoryName)
  {
    ObjyScope objyScope = new ObjyScope(repositoryName, ObjyDb.COMMITINFOSET_CONT_NAME);
    ooId commitInfoListId = null;
    try
    {
      commitInfoListId = objyScope.lookupObjectOid(ObjyDb.COMMITINFOSET_NAME);
    }
    catch (ObjyRuntimeException ex)
    {
      commitInfoListId = createCommitInfoList(objyScope);
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
    return commitInfoListId;
  }

  protected static ooId createPropertyMap(ObjyScope objyScope)
  {
    // TODO - this need refactoring...
    ooId propertyMapId = ObjyPropertyMapHandler.create(objyScope.getScopeContOid());
    objyScope.nameObj(ObjyDb.PROPERTYMAP_NAME, propertyMapId);
    return propertyMapId;
  }

  public static ooId getOrCreatePropertyMap(String repositoryName)
  {
    ObjyScope objyScope = new ObjyScope(repositoryName, ObjyDb.PROPERTYMAP_CONT_NAME);
    ooId propertyMapId = null;
    try
    {
      propertyMapId = objyScope.lookupObjectOid(ObjyDb.PROPERTYMAP_NAME);
    }
    catch (ObjyRuntimeException ex)
    {
      propertyMapId = createPropertyMap(objyScope);
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
    return propertyMapId;
  }

  protected static ObjyBranchManager createBranchManager(ObjyScope objyScope)
  {
    ObjyBranchManager objyBranchManager = ObjyBranchManager.create(objyScope.getScopeContOid());
    objyScope.nameObj(ObjyDb.BRANCHMANAGER_NAME, objyBranchManager.getOid());
    return objyBranchManager;
  }

  public static ObjyBranchManager getOrCreateBranchManager(String repositoryName)
  {
    ObjyScope objyScope = new ObjyScope(repositoryName, ObjyDb.BRANCHING_CONT_NAME);
    ObjyBranchManager objyBranchManager = null;
    try
    {
      objyBranchManager = (ObjyBranchManager)objyScope.lookupObject(ObjyDb.BRANCHMANAGER_NAME);
    }
    catch (ObjyRuntimeException ex)
    {
      objyBranchManager = createBranchManager(objyScope);
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
    return objyBranchManager;
  }

  protected static ooId createPackageMap(ObjyScope objyScope)
  {
    // TODO - this need refactoring...
    ooId packageMapId = ObjyPackageHandler.create(objyScope.getScopeContOid());
    objyScope.nameObj(ObjyDb.PACKAGEMAP_NAME, packageMapId);
    return packageMapId;
  }

  public static ooId getOrCreatePackageMap(String repositoryName)
  {
    ObjyScope objyScope = new ObjyScope(repositoryName, ObjyDb.PACKAGESTORE_CONT_NAME);
    ooId packageMapId = null;
    try
    {
      packageMapId = objyScope.lookupObjectOid(ObjyDb.PACKAGEMAP_NAME);
    }
    catch (ObjyRuntimeException ex)
    {
      packageMapId = createPackageMap(objyScope);
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
    return packageMapId;
  }

}

Back to the top