diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java')
-rw-r--r-- | plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java | 62 |
1 files changed, 39 insertions, 23 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 48036885cd..0fe72fcd33 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 @@ -436,18 +436,10 @@ public class DBStore extends LongIDStore implements IDBStore, CDOAllRevisionsPro Connection connection = getConnection(); LifecycleUtil.activate(mappingStrategy); + Set<IDBTable> createdTables = null; try { - Set<IDBTable> createdTables = CDODBSchema.INSTANCE.create(dbAdapter, connection); - if (createdTables.contains(CDODBSchema.PROPERTIES)) - { - firstStart(connection); - } - else - { - reStart(connection); - } - + createdTables = CDODBSchema.INSTANCE.create(dbAdapter, connection); connection.commit(); } finally @@ -455,6 +447,15 @@ public class DBStore extends LongIDStore implements IDBStore, CDOAllRevisionsPro DBUtil.close(connection); } + if (createdTables.contains(CDODBSchema.PROPERTIES)) + { + firstStart(); + } + else + { + reStart(); + } + externalReferenceManager = createExternalReferenceManager(); externalReferenceManager.setStore(this); LifecycleUtil.activate(externalReferenceManager); @@ -488,7 +489,7 @@ public class DBStore extends LongIDStore implements IDBStore, CDOAllRevisionsPro super.doDeactivate(); } - protected void firstStart(Connection connection) + protected void firstStart() { creationTime = getRepository().getTimeStamp(); firstTime = true; @@ -500,7 +501,7 @@ public class DBStore extends LongIDStore implements IDBStore, CDOAllRevisionsPro OM.LOG.info(MessageFormat.format(Messages.getString("DBStore.8"), creationTime)); //$NON-NLS-1$ } - protected void reStart(Connection connection) + protected void reStart() { Set<String> names = new HashSet<String>(); names.add(PROP_REPOSITORY_CREATED); @@ -529,21 +530,36 @@ public class DBStore extends LongIDStore implements IDBStore, CDOAllRevisionsPro } else { - OM.LOG.info(Messages.getString("DBStore.9")); //$NON-NLS-1$ - long[] result = mappingStrategy.repairAfterCrash(dbAdapter, connection); + Connection connection = getConnection(); + try + { + connection.setAutoCommit(false); + connection.setReadOnly(true); + OM.LOG.info(Messages.getString("DBStore.9")); //$NON-NLS-1$ + long[] result = mappingStrategy.repairAfterCrash(dbAdapter, connection); - setNextLocalObjectID(result[0]); - setLastObjectID(result[1]); - setLastMetaID(DBUtil.selectMaximumLong(connection, CDODBSchema.PACKAGE_INFOS_META_UB)); + setNextLocalObjectID(result[0]); + setLastObjectID(result[1]); + setLastMetaID(DBUtil.selectMaximumLong(connection, CDODBSchema.PACKAGE_INFOS_META_UB)); - int branchID = DBUtil.selectMaximumInt(connection, CDODBSchema.BRANCHES_ID); - setLastBranchID(branchID > 0 ? branchID : 0); + int branchID = DBUtil.selectMaximumInt(connection, CDODBSchema.BRANCHES_ID); + setLastBranchID(branchID > 0 ? branchID : 0); - int localBranchID = DBUtil.selectMinimumInt(connection, CDODBSchema.BRANCHES_ID); - setLastLocalBranchID(localBranchID < 0 ? localBranchID : 0); + int localBranchID = DBUtil.selectMinimumInt(connection, CDODBSchema.BRANCHES_ID); + setLastLocalBranchID(localBranchID < 0 ? localBranchID : 0); - setLastCommitTime(result[2]); - OM.LOG.info(MessageFormat.format(Messages.getString("DBStore.10"), getLastObjectID(), getLastMetaID())); //$NON-NLS-1$ + setLastCommitTime(result[2]); + OM.LOG.info(MessageFormat.format(Messages.getString("DBStore.10"), getLastObjectID(), getLastMetaID())); //$NON-NLS-1$ + } + catch (SQLException e) + { + OM.LOG.error(Messages.getString("DBStore.12"), e); //$NON-NLS-1$ + throw new DBException(e); + } + finally + { + DBUtil.close(connection); + } } removePropertyValues(Collections.singleton(PROP_GRACEFULLY_SHUT_DOWN)); |