Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.common.db')
-rw-r--r--plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/db/CDOCommonDBUtil.java78
-rw-r--r--plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/DBRevisionCacheUtil.java (renamed from plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/DBRevisionCacheUtils.java)53
-rw-r--r--plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/cache/DBRevisionCache.java21
3 files changed, 84 insertions, 68 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/db/CDOCommonDBUtil.java b/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/db/CDOCommonDBUtil.java
index 657189bff7..bf961feb39 100644
--- a/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/db/CDOCommonDBUtil.java
+++ b/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/db/CDOCommonDBUtil.java
@@ -7,28 +7,78 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Andre Dietisheim - further implementations
*/
package org.eclipse.emf.cdo.common.db;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.text.MessageFormat;
+
import org.eclipse.emf.cdo.common.internal.db.cache.DBRevisionCache;
import org.eclipse.emf.cdo.common.revision.cache.CDORevisionCache;
+import org.eclipse.net4j.db.DBException;
/**
* @author Eike Stepper
* @since 2.0
*/
-public final class CDOCommonDBUtil
-{
- private CDOCommonDBUtil()
- {
- }
-
- /**
- * Creates and returns a new JDBC-based revision cache.
- */
- public static CDORevisionCache createDBCache()
- {
- DBRevisionCache cache = new DBRevisionCache();
- return cache;
- }
+public final class CDOCommonDBUtil {
+ private CDOCommonDBUtil() {
+ }
+
+ /**
+ * Creates and returns a new JDBC-based revision cache.
+ */
+ public static CDORevisionCache createDBCache() {
+ DBRevisionCache cache = new DBRevisionCache();
+ return cache;
+ }
+
+ public static void mandatoryInsertUpdate(PreparedStatement preparedStatement)
+ throws SQLException {
+ insertUpdate(preparedStatement);
+ if (preparedStatement.getUpdateCount() == 0) {
+ rollback(preparedStatement.getConnection());
+ throw new DBException(MessageFormat.format(
+ "No row inserted by statement \"{0}\"", preparedStatement));
+ }
+ }
+
+ public static void insertUpdate(PreparedStatement preparedStatement)
+ throws SQLException {
+ if (preparedStatement.execute()) {
+ rollback(preparedStatement.getConnection());
+ throw new DBException("No result set expected");
+ }
+ commit(preparedStatement.getConnection());
+ }
+
+ public static void rollback(Connection connection) throws SQLException {
+ assertIsNotNull(connection);
+ connection.rollback();
+ }
+
+ public static void commit(Connection connection) throws SQLException {
+ assertIsNotNull(connection);
+ connection.commit();
+ }
+
+ /**
+ * Asserts the given {@link Connection} is not <tt>null</tt>.
+ *
+ * @param connection
+ * the connection to check
+ * @return the connection
+ * @throws DBException
+ * if the given connection's <tt>null</tt>
+ */
+ public static Connection assertIsNotNull(Connection connection) {
+ if (connection == null) {
+ throw new DBException("connection is null!");
+ } else {
+ return connection;
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/DBRevisionCacheUtils.java b/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/DBRevisionCacheUtil.java
index 53eec39b96..ddef341cdc 100644
--- a/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/DBRevisionCacheUtils.java
+++ b/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/DBRevisionCacheUtil.java
@@ -26,36 +26,7 @@ import org.eclipse.net4j.util.CheckUtil;
/**
* @author Andre Dietisheim
*/
-public class DBRevisionCacheUtils {
-
- public static void mandatoryInsertUpdate(PreparedStatement preparedStatement)
- throws SQLException {
- insertUpdate(preparedStatement);
- if (preparedStatement.getUpdateCount() == 0) {
- rollback(preparedStatement.getConnection());
- throw new DBException(MessageFormat.format(
- "No row inserted by statement \"{0}\"", preparedStatement));
- }
- }
-
- public static void insertUpdate(PreparedStatement preparedStatement)
- throws SQLException {
- if (preparedStatement.execute()) {
- rollback(preparedStatement.getConnection());
- throw new DBException("No result set expected");
- }
- commit(preparedStatement.getConnection());
- }
-
- public static void rollback(Connection connection) throws SQLException {
- assertIsNotNull(connection);
- connection.rollback();
- }
-
- public static void commit(Connection connection) throws SQLException {
- assertIsNotNull(connection);
- connection.commit();
- }
+public class DBRevisionCacheUtil {
/**
* Asserts the given {@link CDORevision} is <tt>null</tt>.
@@ -74,22 +45,16 @@ public class DBRevisionCacheUtils {
}
/**
- * Asserts the given {@link Connection} is not <tt>null</tt>.
+ * Gets the name of a revision of a CDOResourceNode.
*
- * @param connection
- * the connection to check
- * @return the connection
- * @throws DBException
- * if the given connection's <tt>null</tt>
+ * @param revision
+ * the revision
+ *
+ * @return the resource node name
*/
- public static Connection assertIsNotNull(Connection connection) {
- if (connection == null) {
- throw new DBException("connection is null!");
- } else {
- return connection;
- }
- }
-
+ // TODO: this should be refactored and put in a place, that's more generic
+ // than this class. The same snippet's used in LRURevisionCache and
+ // MemRevisionCache
public static String getResourceNodeName(CDORevision revision) {
CheckUtil.checkArg(revision.isResourceNode(),
"the revision is not a resource node!");
diff --git a/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/cache/DBRevisionCache.java b/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/cache/DBRevisionCache.java
index 5a9c6b21d4..c497c39f7f 100644
--- a/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/cache/DBRevisionCache.java
+++ b/plugins/org.eclipse.emf.cdo.common.db/src/org/eclipse/emf/cdo/common/internal/db/cache/DBRevisionCache.java
@@ -23,11 +23,12 @@ import java.util.List;
import javax.sql.DataSource;
+import org.eclipse.emf.cdo.common.db.CDOCommonDBUtil;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDObjectFactory;
import org.eclipse.emf.cdo.common.id.CDOIDProvider;
import org.eclipse.emf.cdo.common.internal.db.AbstractPreparedStatementFactory;
-import org.eclipse.emf.cdo.common.internal.db.DBRevisionCacheUtils;
+import org.eclipse.emf.cdo.common.internal.db.DBRevisionCacheUtil;
import org.eclipse.emf.cdo.common.internal.db.IPreparedStatementFactory;
import org.eclipse.emf.cdo.common.internal.db.bundle.OM;
import org.eclipse.emf.cdo.common.io.CDODataInput;
@@ -119,7 +120,7 @@ public class DBRevisionCache extends Lifecycle implements CDORevisionCache {
private void setResourceNodeValues(InternalCDORevision cdoRevision,
PreparedStatement preparedStatement) throws SQLException {
if (cdoRevision.isResourceNode()) {
- preparedStatement.setString(6, DBRevisionCacheUtils
+ preparedStatement.setString(6, DBRevisionCacheUtil
.getResourceNodeName(cdoRevision));
CDOID containerID = (CDOID) cdoRevision.getContainerID();
preparedStatement.setString(7, containerID.toURIFragment());
@@ -271,7 +272,7 @@ public class DBRevisionCache extends Lifecycle implements CDORevisionCache {
private void createTable() throws SQLException {
Connection connection = getConnection();
DBRevisionCacheSchema.INSTANCE.create(dbAdapter, connection);
- DBRevisionCacheUtils.commit(connection);
+ CDOCommonDBUtil.commit(connection);
}
/**
@@ -284,12 +285,12 @@ public class DBRevisionCache extends Lifecycle implements CDORevisionCache {
*/
public boolean addRevision(InternalCDORevision revision) {
try {
- DBRevisionCacheUtils
+ CDOCommonDBUtil
.mandatoryInsertUpdate(insertRevisionStatementFactory
.getPreparedStatement(revision, getConnection()));
if (revision.getVersion() > 1) {
// update former latest revision
- DBRevisionCacheUtils.insertUpdate(updateRevisedStatementFactory
+ CDOCommonDBUtil.insertUpdate(updateRevisedStatementFactory
.getPreparedStatement(revision, getConnection()));
}
@@ -306,7 +307,7 @@ public class DBRevisionCache extends Lifecycle implements CDORevisionCache {
*/
public void clear() {
try {
- DBRevisionCacheUtils.insertUpdate(clearStatementFactory
+ CDOCommonDBUtil.insertUpdate(clearStatementFactory
.getPreparedStatement(null, getConnection()));
clearStatementFactory.getPreparedStatement(null, getConnection())
.executeUpdate();
@@ -420,7 +421,7 @@ public class DBRevisionCache extends Lifecycle implements CDORevisionCache {
IDBRowHandler rowHandler = new IDBRowHandler() {
public boolean handle(int row, final Object... values) {
try {
- DBRevisionCacheUtils
+ DBRevisionCacheUtil
.assertIsNull(
cdoRevisionArray[0],
"database inconsistent: there's more than 1 revision with the same id and timestamp!");
@@ -456,7 +457,7 @@ public class DBRevisionCache extends Lifecycle implements CDORevisionCache {
IDBRowHandler rowHandler = new IDBRowHandler() {
public boolean handle(int row, final Object... values) {
try {
- DBRevisionCacheUtils
+ DBRevisionCacheUtil
.assertIsNull(cdoRevisionArray[0],
"database inconsistent: there's more than 1 revision with the same version!");
cdoRevisionArray[0] = toCDORevision(values[0], values[1]);
@@ -522,7 +523,7 @@ public class DBRevisionCache extends Lifecycle implements CDORevisionCache {
try {
InternalCDORevision cdoRevision = getRevisionByVersion(id, version);
if (cdoRevision != null) {
- DBRevisionCacheUtils
+ CDOCommonDBUtil
.mandatoryInsertUpdate(deleteRevisionStatementFactory
.getPreparedStatement(cdoRevision,
getConnection()));
@@ -555,7 +556,7 @@ public class DBRevisionCache extends Lifecycle implements CDORevisionCache {
protected Connection getConnection() {
try {
if (connection == null || connection.isClosed()) {
- connection = DBRevisionCacheUtils
+ connection = CDOCommonDBUtil
.assertIsNotNull(dbConnectionProvider.getConnection());
connection.setAutoCommit(false);
}

Back to the top