diff options
author | Eike Stepper | 2016-10-05 05:33:22 +0000 |
---|---|---|
committer | Eike Stepper | 2016-10-05 05:33:22 +0000 |
commit | 95d11d623b78209da114873fe169995fee7af59c (patch) | |
tree | 7f214e0b0a42ef63cd22cf83d167b30f3277ed98 /plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo | |
parent | 023a17a1a415b2c6272ff1a81f54c0b6f7b4e51a (diff) | |
download | cdo-95d11d623b78209da114873fe169995fee7af59c.tar.gz cdo-95d11d623b78209da114873fe169995fee7af59c.tar.xz cdo-95d11d623b78209da114873fe169995fee7af59c.zip |
[504014] Make merge information available in CDOCommitInfo
https://bugs.eclipse.org/bugs/show_bug.cgi?id=504014
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo')
5 files changed, 506 insertions, 163 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java index 3c1bd04c72..19fb5be943 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java @@ -24,7 +24,7 @@ import java.sql.Connection; * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. */ -public interface IDBStoreAccessor extends IStoreAccessor.Raw, UnitSupport +public interface IDBStoreAccessor extends IStoreAccessor.Raw2, UnitSupport { public IDBStore getStore(); diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java index a72dda6515..6dd6f157f6 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java @@ -135,39 +135,6 @@ public class CDODBSchema + " FROM " + BRANCHES + " WHERE " + BRANCHES_ID + " BETWEEN ? AND ? ORDER BY " + BRANCHES_ID; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ /** - * DBTable cdo_commit_infos - */ - public static final IDBTable COMMIT_INFOS = INSTANCE.addTable("cdo_commit_infos"); //$NON-NLS-1$ - - public static final IDBField COMMIT_INFOS_TIMESTAMP = // - COMMIT_INFOS.addField("commit_time", DBType.BIGINT, true); //$NON-NLS-1$ - - public static final IDBField COMMIT_INFOS_PREVIOUS_TIMESTAMP = // - COMMIT_INFOS.addField("previous_time", DBType.BIGINT); //$NON-NLS-1$ - - public static final IDBField COMMIT_INFOS_BRANCH = // - COMMIT_INFOS.addField("branch_id", DBType.INTEGER); //$NON-NLS-1$ - - public static final IDBField COMMIT_INFOS_USER = // - COMMIT_INFOS.addField("user_id", DBType.VARCHAR); //$NON-NLS-1$ - - public static final IDBField COMMIT_INFOS_COMMENT = // - COMMIT_INFOS.addField("commit_comment", DBType.VARCHAR); //$NON-NLS-1$ - - public static final IDBIndex INDEX_COMMIT_INFOS_PK = // - COMMIT_INFOS.addIndex(IDBIndex.Type.PRIMARY_KEY, COMMIT_INFOS_TIMESTAMP); - - public static final IDBIndex INDEX_COMMIT_INFOS_BRANCH = // - COMMIT_INFOS.addIndex(IDBIndex.Type.NON_UNIQUE, COMMIT_INFOS_BRANCH); - - public static final IDBIndex INDEX_COMMIT_INFOS_USER = // - COMMIT_INFOS.addIndex(IDBIndex.Type.NON_UNIQUE, COMMIT_INFOS_USER); - - public static final String SQL_CREATE_COMMIT_INFO = "INSERT INTO " + COMMIT_INFOS + "(" + COMMIT_INFOS_TIMESTAMP //$NON-NLS-1$ //$NON-NLS-2$ - + ", " + COMMIT_INFOS_PREVIOUS_TIMESTAMP + ", " + COMMIT_INFOS_BRANCH + ", " + COMMIT_INFOS_USER + ", " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - + COMMIT_INFOS_COMMENT + ") " + "VALUES (?, ?, ?, ?, ?)"; //$NON-NLS-2$ - - /** * DBTable cdo_lobs */ public static final IDBTable LOBS = INSTANCE.addTable("cdo_lobs"); //$NON-NLS-1$ diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CommitInfoTable.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CommitInfoTable.java new file mode 100644 index 0000000000..b42431b0a3 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CommitInfoTable.java @@ -0,0 +1,370 @@ +/* + * Copyright (c) 2016 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.db; + +import org.eclipse.emf.cdo.common.CDOCommonRepository.CommitInfoStorage; +import org.eclipse.emf.cdo.common.branch.CDOBranch; +import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; +import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler; +import org.eclipse.emf.cdo.common.protocol.CDODataInput; +import org.eclipse.emf.cdo.common.protocol.CDODataOutput; +import org.eclipse.emf.cdo.server.db.IDBStoreAccessor; +import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch; +import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager; +import org.eclipse.emf.cdo.spi.common.commit.CDOCommitInfoUtil; +import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager; +import org.eclipse.emf.cdo.spi.server.InternalRepository; + +import org.eclipse.net4j.db.DBException; +import org.eclipse.net4j.db.DBType; +import org.eclipse.net4j.db.DBUtil; +import org.eclipse.net4j.db.IDBDatabase; +import org.eclipse.net4j.db.IDBDatabase.RunnableWithSchema; +import org.eclipse.net4j.db.IDBPreparedStatement; +import org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability; +import org.eclipse.net4j.db.ddl.IDBField; +import org.eclipse.net4j.db.ddl.IDBIndex; +import org.eclipse.net4j.db.ddl.IDBSchema; +import org.eclipse.net4j.db.ddl.IDBTable; +import org.eclipse.net4j.util.lifecycle.Lifecycle; +import org.eclipse.net4j.util.om.monitor.OMMonitor; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * @author Eike Stepper + * @since 4.6 + */ +public class CommitInfoTable extends Lifecycle +{ + private static final String COMMIT_INFOS = "cdo_commit_infos"; //$NON-NLS-1$ + + private static final String TIMESTAMP = "commit_time"; //$NON-NLS-1$ + + private static final String PREVIOUS_TIMESTAMP = "previous_time"; + + private static final String BRANCH = "branch_id"; //$NON-NLS-1$ + + private static final String USER = "user_id"; //$NON-NLS-1$ + + private static final String COMMENT = "commit_comment"; //$NON-NLS-1$ + + private static final String MERGED_BRANCH = "merged_branch"; //$NON-NLS-1$ + + private static final String MERGED_TIMESTAMP = "merged_time"; //$NON-NLS-1$ + + private DBStore store; + + private boolean withMergeSource; + + private IDBTable table; + + private String sqlInsert; + + public CommitInfoTable(DBStore store) + { + this.store = store; + } + + public void writeCommitInfo(IDBStoreAccessor accessor, CDOBranch branch, long timeStamp, long previousTimeStamp, + String userID, String comment, CDOBranchPoint mergeSource, OMMonitor monitor) + { + IDBPreparedStatement stmt = accessor.getDBConnection().prepareStatement(sqlInsert, ReuseProbability.HIGH); + + try + { + stmt.setLong(1, timeStamp); + stmt.setLong(2, previousTimeStamp); + stmt.setInt(3, branch.getID()); + stmt.setString(4, userID); + stmt.setString(5, comment); + + if (withMergeSource) + { + if (mergeSource != null) + { + stmt.setInt(6, mergeSource.getBranch().getID()); + stmt.setLong(7, mergeSource.getTimeStamp()); + } + else + { + stmt.setNull(6, DBType.INTEGER.getCode()); + stmt.setNull(7, DBType.BIGINT.getCode()); + } + } + + DBUtil.update(stmt, true); + } + catch (SQLException ex) + { + throw new DBException(ex); + } + finally + { + DBUtil.close(stmt); + } + } + + public void loadCommitInfos(IDBStoreAccessor accessor, CDOBranch branch, long startTime, long endTime, + CDOCommitInfoHandler handler) + { + int count = CDOCommitInfoUtil.decodeCount(endTime); + + StringBuilder builder = new StringBuilder(); + builder.append("SELECT "); //$NON-NLS-1$ + builder.append(TIMESTAMP); + builder.append(", "); //$NON-NLS-1$ + builder.append(PREVIOUS_TIMESTAMP); + builder.append(", "); //$NON-NLS-1$ + builder.append(USER); + builder.append(", "); //$NON-NLS-1$ + builder.append(COMMENT); + + if (branch == null) + { + builder.append(", "); //$NON-NLS-1$ + builder.append(BRANCH); + } + + if (withMergeSource) + { + builder.append(", "); //$NON-NLS-1$ + builder.append(MERGED_BRANCH); + builder.append(", "); //$NON-NLS-1$ + builder.append(MERGED_TIMESTAMP); + } + + builder.append(" FROM "); //$NON-NLS-1$ + builder.append(COMMIT_INFOS); + boolean where = false; + + if (branch != null) + { + builder.append(where ? " AND " : " WHERE "); //$NON-NLS-1$ //$NON-NLS-2$ + builder.append(BRANCH); + builder.append("="); //$NON-NLS-1$ + builder.append(branch.getID()); + where = true; + } + + if (startTime != CDOBranchPoint.UNSPECIFIED_DATE) + { + builder.append(where ? " AND " : " WHERE "); //$NON-NLS-1$ //$NON-NLS-2$ + builder.append(TIMESTAMP); + builder.append(count < 0 ? "<=" : ">="); //$NON-NLS-1$ + builder.append(startTime); + where = true; + } + + if (endTime > CDOBranchPoint.UNSPECIFIED_DATE) + { + builder.append(where ? " AND " : " WHERE "); //$NON-NLS-1$ //$NON-NLS-2$ + builder.append(TIMESTAMP); + builder.append("<="); //$NON-NLS-1$ + builder.append(endTime); + where = true; + } + + builder.append(" ORDER BY "); //$NON-NLS-1$ + builder.append(TIMESTAMP); + builder.append(count < 0 || CDOBranchPoint.UNSPECIFIED_DATE <= endTime && endTime <= startTime ? " DESC" : " ASC"); //$NON-NLS-1$ + String sql = builder.toString(); + + IDBPreparedStatement stmt = accessor.getDBConnection().prepareStatement(sql, ReuseProbability.LOW); + ResultSet resultSet = null; + + InternalRepository repository = store.getRepository(); + InternalCDOBranchManager branchManager = repository.getBranchManager(); + InternalCDOCommitInfoManager commitInfoManager = repository.getCommitInfoManager(); + count = Math.abs(count); + + try + { + resultSet = stmt.executeQuery(); + while (count-- > 0 && resultSet.next()) + { + int column = 0; + + long timeStamp = resultSet.getLong(++column); + long previousTimeStamp = resultSet.getLong(++column); + String userID = resultSet.getString(++column); + String comment = resultSet.getString(++column); + + CDOBranch infoBranch = branch; + if (infoBranch == null) + { + int id = resultSet.getInt(++column); + infoBranch = branchManager.getBranch(id); + } + + CDOBranchPoint mergeSource = null; + if (withMergeSource) + { + int id = resultSet.getInt(++column); + if (!resultSet.wasNull()) + { + InternalCDOBranch mergedBranch = branchManager.getBranch(id); + + long mergedTimeStamp = resultSet.getLong(++column); + mergeSource = mergedBranch.getPoint(mergedTimeStamp); + } + } + + CDOCommitInfo commitInfo = commitInfoManager.createCommitInfo(infoBranch, timeStamp, previousTimeStamp, userID, + comment, mergeSource, null); + handler.handleCommitInfo(commitInfo); + } + } + catch (SQLException ex) + { + throw new DBException(ex); + } + finally + { + DBUtil.close(resultSet); + DBUtil.close(stmt); + } + } + + public void rawExport(Connection connection, CDODataOutput out, long fromCommitTime, long toCommitTime) + throws IOException + { + out.writeBoolean(withMergeSource); + + String where = " WHERE " + TIMESTAMP + " BETWEEN " + fromCommitTime + " AND " + toCommitTime; + DBUtil.serializeTable(out, connection, table, null, where); + } + + public void rawImport(Connection connection, CDODataInput in, long fromCommitTime, long toCommitTime, + OMMonitor monitor) throws IOException + { + boolean actualWithMergeSource = in.readBoolean(); + if (actualWithMergeSource != withMergeSource) + { + throw new IllegalStateException("Commit info data mismatch. Expected: " + (withMergeSource ? "with" : "without") + + " merge source. Actual: " + (actualWithMergeSource ? "with" : "without") + " merge source."); + } + + DBUtil.deserializeTable(in, connection, table, monitor.fork()); + } + + public void repairAfterCrash(Connection connection) + { + IDBField timeStampField = table.getField(TIMESTAMP); + + long lastCommitTime = DBUtil.selectMaximumLong(connection, timeStampField); + long lastNonLocalCommitTime = DBUtil.selectMaximumLong(connection, timeStampField, + CDOBranch.MAIN_BRANCH_ID + "<=" + BRANCH); + + if (lastNonLocalCommitTime == CDOBranchPoint.UNSPECIFIED_DATE) + { + lastNonLocalCommitTime = lastCommitTime; + } + + store.setLastCommitTime(lastCommitTime); + store.setLastNonLocalCommitTime(lastNonLocalCommitTime); + } + + @Override + protected void doActivate() throws Exception + { + super.doActivate(); + + InternalRepository repository = store.getRepository(); + withMergeSource = repository.getCommitInfoStorage() == CommitInfoStorage.WITH_MERGE_SOURCE; + + IDBDatabase database = store.getDatabase(); + table = database.getSchema().getTable(COMMIT_INFOS); + if (table == null) + { + database.updateSchema(new RunnableWithSchema() + { + public void run(IDBSchema schema) + { + table = schema.addTable(COMMIT_INFOS); + table.addField(TIMESTAMP, DBType.BIGINT, true); + table.addField(PREVIOUS_TIMESTAMP, DBType.BIGINT); + table.addField(BRANCH, DBType.INTEGER); + table.addField(USER, DBType.VARCHAR); + table.addField(COMMENT, DBType.VARCHAR); + table.addIndex(IDBIndex.Type.PRIMARY_KEY, TIMESTAMP); + table.addIndex(IDBIndex.Type.NON_UNIQUE, BRANCH); + + if (withMergeSource) + { + table.addField(MERGED_BRANCH, DBType.INTEGER); + table.addField(MERGED_TIMESTAMP, DBType.BIGINT); + table.addIndex(IDBIndex.Type.NON_UNIQUE, MERGED_BRANCH, MERGED_TIMESTAMP); + } + } + }); + } + else + { + if (withMergeSource && table.getField(MERGED_BRANCH) == null) + { + database.updateSchema(new RunnableWithSchema() + { + public void run(IDBSchema schema) + { + IDBTable table = schema.getTable(COMMIT_INFOS); + table.addField(MERGED_BRANCH, DBType.INTEGER); + table.addField(MERGED_TIMESTAMP, DBType.BIGINT); + table.addIndex(IDBIndex.Type.NON_UNIQUE, MERGED_BRANCH, MERGED_TIMESTAMP); + } + }); + } + } + + StringBuilder builder = new StringBuilder(); + builder.append("INSERT INTO "); //$NON-NLS-1$ + builder.append(COMMIT_INFOS); + builder.append("("); //$NON-NLS-1$ + builder.append(TIMESTAMP); + builder.append(", "); //$NON-NLS-1$ + builder.append(PREVIOUS_TIMESTAMP); + builder.append(", "); //$NON-NLS-1$ + builder.append(BRANCH); + builder.append(", "); //$NON-NLS-1$ + builder.append(USER); + builder.append(", "); //$NON-NLS-1$ + builder.append(COMMENT); + + if (withMergeSource) + { + builder.append(", "); //$NON-NLS-1$ + builder.append(MERGED_BRANCH); + builder.append(", "); //$NON-NLS-1$ + builder.append(MERGED_TIMESTAMP); + } + + builder.append(") VALUES (?, ?, ?, ?, ?"); //$NON-NLS-1$ + if (withMergeSource) + { + builder.append(", ?, ?"); //$NON-NLS-1$ + } + + builder.append(")"); //$NON-NLS-1$ + sqlInsert = builder.toString(); + } + + @Override + protected void doDeactivate() throws Exception + { + sqlInsert = null; + table = null; + super.doDeactivate(); + } +} 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 d5a314979b..15e383d1f3 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 @@ -14,6 +14,7 @@ */ package org.eclipse.emf.cdo.server.internal.db; +import org.eclipse.emf.cdo.common.CDOCommonRepository.CommitInfoStorage; import org.eclipse.emf.cdo.common.CDOCommonRepository.IDGenerationLocation; import org.eclipse.emf.cdo.common.branch.CDOBranch; import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; @@ -80,6 +81,10 @@ public class DBStore extends Store implements IDBStore, IMappingConstants, CDOAl public static final int SCHEMA_VERSION = 4; + // public static final int SCHEMA_VERSION = 3; // Bug 404047: Indexed columns must be NOT NULL. + // public static final int SCHEMA_VERSION = 2; // Bug 344232: Rename cdo_lobs.size to cdo_lobs.lsize. + // public static final int SCHEMA_VERSION = 1; // Bug 351068: Delete detached objects from non-auditing stores. + private static final int FIRST_START = -1; private static final String PROP_SCHEMA_VERSION = "org.eclipse.emf.cdo.server.db.schemaVersion"; //$NON-NLS-1$ @@ -118,6 +123,8 @@ public class DBStore extends Store implements IDBStore, IMappingConstants, CDOAl private DurableLockingManager durableLockingManager = new DurableLockingManager(this); + private CommitInfoTable commitInfoTable; + private UnitMappingTable unitMappingTable; private IMappingStrategy mappingStrategy; @@ -247,6 +254,11 @@ public class DBStore extends Store implements IDBStore, IMappingConstants, CDOAl return durableLockingManager; } + public CommitInfoTable getCommitInfoTable() + { + return commitInfoTable; + } + public UnitMappingTable getUnitMappingTable() { return unitMappingTable; @@ -667,6 +679,12 @@ public class DBStore extends Store implements IDBStore, IMappingConstants, CDOAl LifecycleUtil.activate(durableLockingManager); LifecycleUtil.activate(mappingStrategy); + if (repository.getCommitInfoStorage() != CommitInfoStorage.NO) + { + commitInfoTable = new CommitInfoTable(this); + commitInfoTable.activate(); + } + if (repository.isSupportingUnits()) { unitMappingTable = new UnitMappingTable(mappingStrategy); @@ -693,6 +711,7 @@ public class DBStore extends Store implements IDBStore, IMappingConstants, CDOAl protected void doDeactivate() throws Exception { LifecycleUtil.deactivate(unitMappingTable); + LifecycleUtil.deactivate(commitInfoTable); LifecycleUtil.deactivate(mappingStrategy); LifecycleUtil.deactivate(durableLockingManager); LifecycleUtil.deactivate(metaDataManager); @@ -799,7 +818,8 @@ public class DBStore extends Store implements IDBStore, IMappingConstants, CDOAl protected void repairAfterCrash() { - String name = getRepository().getName(); + InternalRepository repository = getRepository(); + String name = repository.getName(); OM.LOG.warn(MessageFormat.format(Messages.getString("DBStore.9"), name)); //$NON-NLS-1$ Connection connection = getConnection(); @@ -811,7 +831,7 @@ public class DBStore extends Store implements IDBStore, IMappingConstants, CDOAl mappingStrategy.repairAfterCrash(dbAdapter, connection); // Must update the idHandler - boolean storeIDs = getRepository().getIDGenerationLocation() == IDGenerationLocation.STORE; + boolean storeIDs = repository.getIDGenerationLocation() == IDGenerationLocation.STORE; CDOID lastObjectID = storeIDs ? idHandler.getLastObjectID() : CDOID.NULL; CDOID nextLocalObjectID = storeIDs ? idHandler.getNextLocalObjectID() : CDOID.NULL; @@ -821,12 +841,63 @@ public class DBStore extends Store implements IDBStore, IMappingConstants, CDOAl int localBranchID = DBUtil.selectMinimumInt(connection, CDODBSchema.BRANCHES_ID); setLastLocalBranchID(localBranchID < 0 ? localBranchID : 0); - long lastCommitTime = DBUtil.selectMaximumLong(connection, CDODBSchema.COMMIT_INFOS_TIMESTAMP); - setLastCommitTime(lastCommitTime); + if (commitInfoTable != null) + { + commitInfoTable.repairAfterCrash(connection); + } + else + { + boolean branching = repository.isSupportingBranches(); + + long lastCommitTime = CDOBranchPoint.UNSPECIFIED_DATE; + long lastNonLocalCommitTime = CDOBranchPoint.UNSPECIFIED_DATE; - long lastNonLocalCommitTime = DBUtil.selectMaximumLong(connection, CDODBSchema.COMMIT_INFOS_TIMESTAMP, - CDOBranch.MAIN_BRANCH_ID + "<=" + CDODBSchema.COMMIT_INFOS_BRANCH); - setLastNonLocalCommitTime(lastNonLocalCommitTime); + // Unfortunately the package registry is still inactive, so the class mappings can not be used at this point. + // Use all tables with a "CDO_CREATED" field instead. + for (String tableName : DBUtil.getAllTableNames(connection, repository.getName())) + { + try + { + if (CDODBSchema.CDO_OBJECTS.equals(tableName)) + { + continue; + } + + IDBTable table = database.getSchema().getTable(tableName); + IDBField createdField = table.getField(IMappingConstants.ATTRIBUTES_CREATED); + if (createdField == null) + { + continue; + } + + if (branching) + { + IDBField branchField = table.getField(IMappingConstants.ATTRIBUTES_BRANCH); + if (branchField == null) + { + continue; + } + + lastNonLocalCommitTime = Math.max(lastNonLocalCommitTime, DBUtil.selectMaximumLong(connection, + branchField, CDOBranch.MAIN_BRANCH_ID + "<=" + IMappingConstants.ATTRIBUTES_BRANCH)); + } + + lastCommitTime = Math.max(lastCommitTime, DBUtil.selectMaximumLong(connection, createdField)); + } + catch (Exception ex) + { + OM.LOG.warn(ex.getMessage()); + } + } + + if (lastNonLocalCommitTime == CDOBranchPoint.UNSPECIFIED_DATE) + { + lastNonLocalCommitTime = lastCommitTime; + } + + setLastCommitTime(lastCommitTime); + setLastNonLocalCommitTime(lastNonLocalCommitTime); + } if (storeIDs) { @@ -994,8 +1065,10 @@ public class DBStore extends Store implements IDBStore, IMappingConstants, CDOAl } }; + private static final SchemaMigrator NULLABLE_COLUMNS_MIGRATION = null; + private static final SchemaMigrator[] SCHEMA_MIGRATORS = { NO_MIGRATION_NEEDED, NON_AUDIT_MIGRATION, - LOB_SIZE_MIGRATION, NO_MIGRATION_NEEDED }; + LOB_SIZE_MIGRATION, NULLABLE_COLUMNS_MIGRATION }; static { diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java index 80f45e7846..2b3c84870e 100644 --- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java +++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java @@ -19,7 +19,6 @@ import org.eclipse.emf.cdo.common.branch.CDOBranch; import org.eclipse.emf.cdo.common.branch.CDOBranchHandler; import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; import org.eclipse.emf.cdo.common.branch.CDOBranchVersion; -import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler; import org.eclipse.emf.cdo.common.id.CDOID; import org.eclipse.emf.cdo.common.lob.CDOLobHandler; @@ -55,8 +54,6 @@ import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranch; import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager; import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager.BranchLoader3; import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment; -import org.eclipse.emf.cdo.spi.common.commit.CDOCommitInfoUtil; -import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager; import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry; import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit; import org.eclipse.emf.cdo.spi.common.revision.DetachedCDORevision; @@ -166,7 +163,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor, public IDBPreparedStatement getPreparedStatement(String sql, ReuseProbability reuseProbability) { org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability converted = // - org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability.values()[reuseProbability.ordinal()]; + org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability.values()[reuseProbability.ordinal()]; return connection.prepareStatement(sql, converted); } @@ -504,29 +501,23 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor, } } + @Deprecated @Override protected void writeCommitInfo(CDOBranch branch, long timeStamp, long previousTimeStamp, String userID, String comment, OMMonitor monitor) { - IDBPreparedStatement stmt = connection.prepareStatement(CDODBSchema.SQL_CREATE_COMMIT_INFO, ReuseProbability.HIGH); - - try - { - stmt.setLong(1, timeStamp); - stmt.setLong(2, previousTimeStamp); - stmt.setInt(3, branch.getID()); - stmt.setString(4, userID); - stmt.setString(5, comment); + writeCommitInfo(branch, timeStamp, previousTimeStamp, userID, comment, null, monitor); + } - DBUtil.update(stmt, true); - } - catch (SQLException ex) - { - throw new DBException(ex); - } - finally + @Override + protected void writeCommitInfo(CDOBranch branch, long timeStamp, long previousTimeStamp, String userID, + String comment, CDOBranchPoint mergeSource, OMMonitor monitor) + { + CommitInfoTable commitInfoTable = getStore().getCommitInfoTable(); + if (commitInfoTable != null) { - DBUtil.close(stmt); + commitInfoTable.writeCommitInfo(this, branch, timeStamp, previousTimeStamp, userID, comment, mergeSource, + monitor); } } @@ -1089,101 +1080,10 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor, public void loadCommitInfos(CDOBranch branch, long startTime, long endTime, CDOCommitInfoHandler handler) { - int count = CDOCommitInfoUtil.decodeCount(endTime); - - StringBuilder builder = new StringBuilder(); - builder.append("SELECT "); //$NON-NLS-1$ - builder.append(CDODBSchema.COMMIT_INFOS_TIMESTAMP); - builder.append(", "); //$NON-NLS-1$ - builder.append(CDODBSchema.COMMIT_INFOS_PREVIOUS_TIMESTAMP); - builder.append(", "); //$NON-NLS-1$ - builder.append(CDODBSchema.COMMIT_INFOS_USER); - builder.append(", "); //$NON-NLS-1$ - builder.append(CDODBSchema.COMMIT_INFOS_COMMENT); - if (branch == null) + CommitInfoTable commitInfoTable = getStore().getCommitInfoTable(); + if (commitInfoTable != null) { - builder.append(", "); //$NON-NLS-1$ - builder.append(CDODBSchema.COMMIT_INFOS_BRANCH); - } - - builder.append(" FROM "); //$NON-NLS-1$ - builder.append(CDODBSchema.COMMIT_INFOS); - boolean where = false; - - if (branch != null) - { - builder.append(where ? " AND " : " WHERE "); //$NON-NLS-1$ //$NON-NLS-2$ - builder.append(CDODBSchema.COMMIT_INFOS_BRANCH); - builder.append("="); //$NON-NLS-1$ - builder.append(branch.getID()); - where = true; - } - - if (startTime != CDOBranchPoint.UNSPECIFIED_DATE) - { - builder.append(where ? " AND " : " WHERE "); //$NON-NLS-1$ //$NON-NLS-2$ - builder.append(CDODBSchema.COMMIT_INFOS_TIMESTAMP); - builder.append(count < 0 ? "<=" : ">="); //$NON-NLS-1$ - builder.append(startTime); - where = true; - } - - if (endTime > CDOBranchPoint.UNSPECIFIED_DATE) - { - builder.append(where ? " AND " : " WHERE "); //$NON-NLS-1$ //$NON-NLS-2$ - builder.append(CDODBSchema.COMMIT_INFOS_TIMESTAMP); - builder.append("<="); //$NON-NLS-1$ - builder.append(endTime); - where = true; - } - - builder.append(" ORDER BY "); //$NON-NLS-1$ - builder.append(CDODBSchema.COMMIT_INFOS_TIMESTAMP); - builder.append(count < 0 || CDOBranchPoint.UNSPECIFIED_DATE <= endTime && endTime <= startTime ? " DESC" : " ASC"); //$NON-NLS-1$ - String sql = builder.toString(); - - IDBPreparedStatement stmt = connection.prepareStatement(sql, ReuseProbability.MEDIUM); - ResultSet resultSet = null; - - InternalRepository repository = getStore().getRepository(); - InternalCDOBranchManager branchManager = repository.getBranchManager(); - InternalCDOCommitInfoManager commitInfoManager = repository.getCommitInfoManager(); - count = Math.abs(count); - - try - { - resultSet = stmt.executeQuery(); - while (resultSet.next()) - { - long timeStamp = resultSet.getLong(1); - long previousTimeStamp = resultSet.getLong(2); - String userID = resultSet.getString(3); - String comment = resultSet.getString(4); - CDOBranch infoBranch = branch; - if (infoBranch == null) - { - int id = resultSet.getInt(5); - infoBranch = branchManager.getBranch(id); - } - - CDOCommitInfo commitInfo = commitInfoManager.createCommitInfo(infoBranch, timeStamp, previousTimeStamp, userID, - comment, null); - handler.handleCommitInfo(commitInfo); - - if (--count == 0) - { - break; - } - } - } - catch (SQLException ex) - { - throw new DBException(ex); - } - finally - { - DBUtil.close(resultSet); - DBUtil.close(stmt); + commitInfoTable.loadCommitInfos(this, branch, startTime, endTime, handler); } } @@ -1204,7 +1104,9 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor, throws IOException { DBStore store = getStore(); - if (store.getRepository().getIDGenerationLocation() == IDGenerationLocation.STORE) + InternalRepository repository = store.getRepository(); + + if (repository.getIDGenerationLocation() == IDGenerationLocation.STORE) { out.writeCDOID(store.getIDHandler().getLastObjectID()); // See bug 325097 } @@ -1214,8 +1116,16 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor, String where = " WHERE " + CDODBSchema.BRANCHES_ID + " BETWEEN " + fromBranchID + " AND " + toBranchID; DBUtil.serializeTable(out, connection, CDODBSchema.BRANCHES, null, where); - where = " WHERE " + CDODBSchema.COMMIT_INFOS_TIMESTAMP + " BETWEEN " + fromCommitTime + " AND " + toCommitTime; - DBUtil.serializeTable(out, connection, CDODBSchema.COMMIT_INFOS, null, where); + CommitInfoTable commitInfoTable = store.getCommitInfoTable(); + if (commitInfoTable != null) + { + out.writeBoolean(true); + commitInfoTable.rawExport(connection, out, fromCommitTime, toCommitTime); + } + else + { + out.writeBoolean(false); + } DurableLockingManager durableLockingManager = store.getDurableLockingManager(); durableLockingManager.rawExport(connection, out, fromCommitTime, toCommitTime); @@ -1251,7 +1161,24 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor, try { DBUtil.deserializeTable(in, connection, CDODBSchema.BRANCHES, monitor.fork()); - DBUtil.deserializeTable(in, connection, CDODBSchema.COMMIT_INFOS, monitor.fork()); + + CommitInfoTable commitInfoTable = store.getCommitInfoTable(); + if (in.readBoolean()) + { + if (commitInfoTable == null) + { + throw new IllegalStateException("Commit info table is missing"); + } + + commitInfoTable.rawImport(connection, in, fromCommitTime, toCommitTime, monitor.fork()); + } + else + { + if (commitInfoTable != null) + { + throw new IllegalStateException("Commit info data is expected but missing"); + } + } DurableLockingManager durableLockingManager = store.getDurableLockingManager(); durableLockingManager.rawImport(connection, in, fromCommitTime, toCommitTime, monitor.fork()); @@ -1308,7 +1235,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor, Connection connection = getConnection(); Collection<InternalCDOPackageUnit> imported = // - metaDataManager.rawImport(connection, in, fromCommitTime, toCommitTime, monitor.fork()); + metaDataManager.rawImport(connection, in, fromCommitTime, toCommitTime, monitor.fork()); packageUnits.addAll(imported); if (!packageUnits.isEmpty()) @@ -1390,7 +1317,13 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor, public void rawStore(CDOBranch branch, long timeStamp, long previousTimeStamp, String userID, String comment, OMMonitor monitor) { - writeCommitInfo(branch, timeStamp, previousTimeStamp, userID, comment, monitor); + writeCommitInfo(branch, timeStamp, previousTimeStamp, userID, comment, null, monitor); + } + + public void rawStore(CDOBranch branch, long timeStamp, long previousTimeStamp, String userID, String comment, + CDOBranchPoint mergeSource, OMMonitor monitor) + { + writeCommitInfo(branch, timeStamp, previousTimeStamp, userID, comment, mergeSource, monitor); } public void rawDelete(CDOID id, int version, CDOBranch branch, EClass eClass, OMMonitor monitor) |