summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-14 12:43:51 (EDT)
committerEike Stepper2007-09-14 12:43:51 (EDT)
commitd96d5ec4e92fcd30a3e89b8b4219a1f72396799a (patch)
tree33d0701a681abc2b32e477993c33c7c03550fe87
parentb42106615879659c36254dd3da6d5bb3ab40aa22 (diff)
downloadcdo-d96d5ec4e92fcd30a3e89b8b4219a1f72396799a.zip
cdo-d96d5ec4e92fcd30a3e89b8b4219a1f72396799a.tar.gz
cdo-d96d5ec4e92fcd30a3e89b8b4219a1f72396799a.tar.bz2
[202833] Horizontal Mapping Strategy
https://bugs.eclipse.org/bugs/show_bug.cgi?id=202833
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java145
1 files changed, 78 insertions, 67 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
index 0089d5d..0e0beb3 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.internal.server.Store;
import org.eclipse.emf.cdo.protocol.model.CDOType;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IView;
+import org.eclipse.emf.cdo.server.db.IClassMapping;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
@@ -139,29 +140,31 @@ public class DBStore extends Store implements IDBStore
protected void doActivate() throws Exception
{
super.doActivate();
- Set<IDBTable> createdTables = CDODBSchema.INSTANCE.create(dbAdapter, connectionProvider);
- DBStoreAccessor writer = getWriter(null);
- Connection connection = writer.getConnection();
+ activateOrDeactivate(true);
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ activateOrDeactivate(false);
+ super.doDeactivate();
+ }
+
+ protected void activateOrDeactivate(boolean started)
+ {
+ Repository repository = (Repository)getRepository();
+ Connection connection = connectionProvider.getConnection();
try
{
- if (createdTables.contains(CDODBSchema.REPOSITORY))
+ if (started)
{
- insertRepositoryRow(writer);
+ activateStore(repository, connection);
}
else
{
- Repository repository = (Repository)getRepository();
- repository.setNextOIDValue(DBUtil.selectMaximum(connection, CDODBSchema.REPOSITORY_NEXT_CDOID));
- repository.setNextMetaIDValue(DBUtil.selectMaximum(connection, CDODBSchema.REPOSITORY_NEXT_METAID));
- updateRepositoryRow(writer, true);
+ deactivateStore(repository, connection);
}
-
- nextPackageID = DBUtil.selectMaximum(connection, CDODBSchema.PACKAGES_ID) + 1;
- nextClassID = DBUtil.selectMaximum(connection, CDODBSchema.CLASSES_ID) + 1;
- nextFeatureID = DBUtil.selectMaximum(connection, CDODBSchema.FEATURES_ID) + 1;
-
- writer.release();
}
finally
{
@@ -169,47 +172,33 @@ public class DBStore extends Store implements IDBStore
}
}
- @Override
- protected void doDeactivate() throws Exception
+ protected void activateStore(Repository repository, Connection connection)
{
- DBStoreAccessor writer = getWriter(null);
- Connection connection = writer.getConnection();
-
- try
- {
- updateRepositoryRow(writer, false);
- writer.release();
- }
- finally
+ Set<IDBTable> createdTables = CDODBSchema.INSTANCE.create(dbAdapter, connectionProvider);
+ if (createdTables.contains(CDODBSchema.REPOSITORY))
{
- DBUtil.close(connection);
+ // First start
+ DBUtil.insertRow(connection, dbAdapter, CDODBSchema.REPOSITORY, repository.getName(), repository.getUUID(), 1,
+ System.currentTimeMillis(), 0, 0, 0);
+
+ MappingStrategy mappingStrategy = (MappingStrategy)getMappingStrategy();
+ IClassMapping resourceClassMapping = mappingStrategy.getResourceClassMapping();
+ Set<IDBTable> tables = resourceClassMapping.getAffectedTables();
+ if (dbAdapter.createTables(tables, connection).size() != tables.size())
+ {
+ throw new DBException("CDOResource tables not completely created");
+ }
}
-
- super.doDeactivate();
- }
-
- protected IDBSchema createSchema()
- {
- String name = getRepository().getName();
- return new DBSchema(name);
- }
-
- protected void insertRepositoryRow(DBStoreAccessor writer)
- {
- Repository repository = (Repository)getRepository();
- DBUtil.insertRow(writer.getConnection(), dbAdapter, CDODBSchema.REPOSITORY, repository.getName(), repository
- .getUUID(), 1, System.currentTimeMillis(), 0, 0, 0);
- }
-
- protected void updateRepositoryRow(DBStoreAccessor writer, boolean started)
- {
- Repository repository = (Repository)getRepository();
- StringBuilder builder = new StringBuilder();
- builder.append("UPDATE ");
- builder.append(CDODBSchema.REPOSITORY);
- builder.append(" SET ");
- if (started)
+ else
{
+ // Restart
+ repository.setNextOIDValue(DBUtil.selectMaximum(connection, CDODBSchema.REPOSITORY_NEXT_CDOID));
+ repository.setNextMetaIDValue(DBUtil.selectMaximum(connection, CDODBSchema.REPOSITORY_NEXT_METAID));
+
+ StringBuilder builder = new StringBuilder();
+ builder.append("UPDATE ");
+ builder.append(CDODBSchema.REPOSITORY);
+ builder.append(" SET ");
builder.append(CDODBSchema.REPOSITORY_STARTS);
builder.append("=");
builder.append(CDODBSchema.REPOSITORY_STARTS);
@@ -224,30 +213,52 @@ public class DBStore extends Store implements IDBStore
builder.append("=0, ");
builder.append(CDODBSchema.REPOSITORY_NEXT_METAID);
builder.append("=0");
+
+ String sql = builder.toString();
+ int count = DBUtil.update(connection, sql);
+ if (count == 0)
+ {
+ throw new DBException("No row updated in table " + CDODBSchema.REPOSITORY);
+ }
}
- else
- {
- builder.append(CDODBSchema.REPOSITORY_STOPPED);
- builder.append("=");
- builder.append(System.currentTimeMillis());
- builder.append(", ");
- builder.append(CDODBSchema.REPOSITORY_NEXT_CDOID);
- builder.append("=");
- builder.append(repository.getNextOIDValue());
- builder.append(", ");
- builder.append(CDODBSchema.REPOSITORY_NEXT_METAID);
- builder.append("=");
- builder.append(repository.getNextMetaIDValue());
- }
+
+ nextPackageID = DBUtil.selectMaximum(connection, CDODBSchema.PACKAGES_ID) + 1;
+ nextClassID = DBUtil.selectMaximum(connection, CDODBSchema.CLASSES_ID) + 1;
+ nextFeatureID = DBUtil.selectMaximum(connection, CDODBSchema.FEATURES_ID) + 1;
+ }
+
+ protected void deactivateStore(Repository repository, Connection connection)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("UPDATE ");
+ builder.append(CDODBSchema.REPOSITORY);
+ builder.append(" SET ");
+ builder.append(CDODBSchema.REPOSITORY_STOPPED);
+ builder.append("=");
+ builder.append(System.currentTimeMillis());
+ builder.append(", ");
+ builder.append(CDODBSchema.REPOSITORY_NEXT_CDOID);
+ builder.append("=");
+ builder.append(repository.getNextOIDValue());
+ builder.append(", ");
+ builder.append(CDODBSchema.REPOSITORY_NEXT_METAID);
+ builder.append("=");
+ builder.append(repository.getNextMetaIDValue());
String sql = builder.toString();
- int count = DBUtil.update(writer.getConnection(), sql);
+ int count = DBUtil.update(connection, sql);
if (count == 0)
{
throw new DBException("No row updated in table " + CDODBSchema.REPOSITORY);
}
}
+ protected IDBSchema createSchema()
+ {
+ String name = getRepository().getName();
+ return new DBSchema(name);
+ }
+
public static DBType getDBType(CDOType type)
{
if (type == CDOType.BOOLEAN || type == CDOType.BOOLEAN_OBJECT)