From d96d5ec4e92fcd30a3e89b8b4219a1f72396799a Mon Sep 17 00:00:00 2001 From: Eike Stepper Date: Fri, 14 Sep 2007 16:43:51 +0000 Subject: [202833] Horizontal Mapping Strategy https://bugs.eclipse.org/bugs/show_bug.cgi?id=202833 --- .../emf/cdo/server/internal/db/DBStore.java | 145 +++++++++++---------- 1 file 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 0089d5d315..0e0beb3fe5 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 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 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 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) -- cgit v1.2.3