Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-03-11 14:38:22 +0000
committerEike Stepper2013-03-11 14:38:22 +0000
commit009e556a0fda4a93b878bbc7f99115f7f9e6b047 (patch)
tree468a1bad4ecf02d6e6bc2947cbb4b93856c4ad46
parent95e9abf2c58f24f845ca8e771701a7c937095cee (diff)
downloadcdo-009e556a0fda4a93b878bbc7f99115f7f9e6b047.tar.gz
cdo-009e556a0fda4a93b878bbc7f99115f7f9e6b047.tar.xz
cdo-009e556a0fda4a93b878bbc7f99115f7f9e6b047.zip
[401763] Make CDO Server more robust against data dictionary changes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=401763
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java15
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IPreparedStatementCache.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AbstractPreparedStatementCache.java47
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java214
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DurableLockingManager.java70
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ExternalReferenceManager.java25
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NullPreparedStatementCache.java76
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/SmartPreparedStatementCache.java180
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractFeatureMapTableMapping.java85
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java21
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java47
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMapping.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMappingWithRanges.java119
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java111
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMapping.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMappingWithRanges.java158
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMapping.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java129
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java55
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java81
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java41
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditFeatureMapTableMapping.java76
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java41
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeTable.java21
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractSyncingTest.java16
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java10
30 files changed, 586 insertions, 1117 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
index 696b72625f..b2c7eb698e 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
@@ -15,7 +15,6 @@ package org.eclipse.emf.cdo.server.db;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.DBBrowserPage;
import org.eclipse.emf.cdo.server.internal.db.DBStore;
-import org.eclipse.emf.cdo.server.internal.db.SmartPreparedStatementCache;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.HorizontalAuditMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.HorizontalAuditMappingStrategyWithRanges;
@@ -26,6 +25,7 @@ import org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.HorizontalNonAu
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.IDBConnectionProvider;
+import org.eclipse.net4j.db.IDBTransaction;
import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.container.IManagedContainer;
@@ -199,23 +199,22 @@ public final class CDODBUtil
}
/**
- * Creates a prepared statement cache with the {@link CDODBUtil#DEFAULT_STATEMENT_CACHE_CAPACITY default capacity}.
- *
* @since 2.0
- * @see CDODBUtil#createStatementCache(int)
+ * @deprecated As of 4.2 use {@link IDBTransaction#prepareStatement(String, org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability)}.
*/
+ @Deprecated
public static IPreparedStatementCache createStatementCache()
{
- return createStatementCache(DEFAULT_STATEMENT_CACHE_CAPACITY);
+ throw new UnsupportedOperationException();
}
/**
- * Creates a prepared statement cache with the given capacity.
- *
* @since 2.0
+ * @deprecated As of 4.2 use {@link IDBTransaction#prepareStatement(String, org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability)}.
*/
+ @Deprecated
public static IPreparedStatementCache createStatementCache(int capacity)
{
- return new SmartPreparedStatementCache(capacity);
+ throw new UnsupportedOperationException();
}
}
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 ce92068bfc..4f68b5a92e 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
@@ -12,6 +12,8 @@ package org.eclipse.emf.cdo.server.db;
import org.eclipse.emf.cdo.server.IStoreAccessor;
+import org.eclipse.net4j.db.IDBTransaction;
+
import java.sql.Connection;
/**
@@ -25,10 +27,17 @@ public interface IDBStoreAccessor extends IStoreAccessor.Raw
{
public IDBStore getStore();
+ /**
+ * @since 4.2
+ */
+ public IDBTransaction getDBTransaction();
+
public Connection getConnection();
/**
* @since 2.0
+ * @depreacted As of 4.2 use {@link IDBTransaction#prepareStatement(String, org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability)}.
*/
+ @Deprecated
public IPreparedStatementCache getStatementCache();
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IPreparedStatementCache.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IPreparedStatementCache.java
index 5cd4634393..b6e8648eb4 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IPreparedStatementCache.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IPreparedStatementCache.java
@@ -11,6 +11,8 @@
*/
package org.eclipse.emf.cdo.server.db;
+import org.eclipse.net4j.db.IDBTransaction;
+
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -21,7 +23,9 @@ import java.sql.PreparedStatement;
* @since 2.0
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
+ * @deprecated As of 4.2 use {@link IDBTransaction}.
*/
+@Deprecated
public interface IPreparedStatementCache
{
public void setConnection(Connection connection);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AbstractPreparedStatementCache.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AbstractPreparedStatementCache.java
deleted file mode 100644
index 40ee479ff6..0000000000
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AbstractPreparedStatementCache.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2004 - 2012 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:
- * Stefan Winkler - initial API and implementation
- */
-package org.eclipse.emf.cdo.server.internal.db;
-
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-
-import java.sql.Connection;
-
-/**
- * @author Stefan Winkler
- * @since 2.0
- */
-public abstract class AbstractPreparedStatementCache extends Lifecycle implements IPreparedStatementCache
-{
- private Connection connection;
-
- public AbstractPreparedStatementCache()
- {
- }
-
- public final Connection getConnection()
- {
- return connection;
- }
-
- public final void setConnection(Connection connection)
- {
- checkInactive();
- this.connection = connection;
- }
-
- @Override
- protected void doBeforeActivate()
- {
- checkState(connection, "Must have valid connection to start"); //$NON-NLS-1$
- }
-}
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 c0d2dfc22c..f35190f8f2 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
@@ -39,13 +39,10 @@ import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.IStoreAccessor.DurableLocking2;
import org.eclipse.emf.cdo.server.ITransaction;
-import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
import org.eclipse.emf.cdo.server.db.IMetaDataManager;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IClassMapping;
import org.eclipse.emf.cdo.server.db.mapping.IClassMappingAuditSupport;
import org.eclipse.emf.cdo.server.db.mapping.IClassMappingDeltaSupport;
@@ -69,6 +66,8 @@ import org.eclipse.emf.cdo.spi.server.StoreAccessor;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability;
+import org.eclipse.net4j.db.IDBTransaction;
import org.eclipse.net4j.util.HexUtil;
import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.StringUtil;
@@ -114,12 +113,10 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DBStoreAccessor.class);
- private Connection connection;
+ private IDBTransaction transaction;
private ConnectionKeepAliveTask connectionKeepAliveTask;
- private IPreparedStatementCache statementCache;
-
private Set<CDOID> newObjects = new HashSet<CDOID>();
private CDOID maxID = CDOID.NULL;
@@ -140,9 +137,34 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
return (DBStore)super.getStore();
}
- public IPreparedStatementCache getStatementCache()
+ public IDBTransaction getDBTransaction()
{
- return statementCache;
+ return transaction;
+ }
+
+ @Deprecated
+ public org.eclipse.emf.cdo.server.db.IPreparedStatementCache getStatementCache()
+ {
+ return new org.eclipse.emf.cdo.server.db.IPreparedStatementCache()
+ {
+ public void setConnection(Connection connection)
+ {
+ // Do nothing
+ }
+
+ public PreparedStatement getPreparedStatement(String sql, ReuseProbability reuseProbability)
+ {
+ org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability converted = //
+ org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability.values()[reuseProbability.ordinal()];
+
+ return transaction.prepareStatement(sql, converted);
+ }
+
+ public void releasePreparedStatement(PreparedStatement ps)
+ {
+ DBUtil.close(ps);
+ }
+ };
}
public DBStoreChunkReader createChunkReader(InternalCDORevision revision, EStructuralFeature feature)
@@ -322,13 +344,11 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
public void queryLobs(List<byte[]> ids)
{
- PreparedStatement stmt = null;
+ PreparedStatement stmt = transaction.prepareStatement(CDODBSchema.SQL_QUERY_LOBS, ReuseProbability.MEDIUM);
ResultSet resultSet = null;
try
{
- stmt = statementCache.getPreparedStatement(CDODBSchema.SQL_QUERY_LOBS, ReuseProbability.MEDIUM);
-
for (Iterator<byte[]> it = ids.iterator(); it.hasNext();)
{
byte[] id = it.next();
@@ -354,42 +374,33 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
public void loadLob(byte[] id, OutputStream out) throws IOException
{
- PreparedStatement stmt = null;
+ PreparedStatement stmt = transaction.prepareStatement(CDODBSchema.SQL_LOAD_LOB, ReuseProbability.MEDIUM);
ResultSet resultSet = null;
try
{
- stmt = statementCache.getPreparedStatement(CDODBSchema.SQL_LOAD_LOB, ReuseProbability.MEDIUM);
stmt.setString(1, HexUtil.bytesToHex(id));
+ resultSet = stmt.executeQuery();
+ resultSet.next();
- try
+ long size = resultSet.getLong(1);
+ Blob blob = resultSet.getBlob(2);
+ if (resultSet.wasNull())
{
- resultSet = stmt.executeQuery();
- resultSet.next();
-
- long size = resultSet.getLong(1);
- Blob blob = resultSet.getBlob(2);
- if (resultSet.wasNull())
- {
- Clob clob = resultSet.getClob(3);
- Reader in = clob.getCharacterStream();
- IOUtil.copyCharacter(in, new OutputStreamWriter(out), size);
- }
- else
- {
- InputStream in = blob.getBinaryStream();
- IOUtil.copyBinary(in, out, size);
- }
+ Clob clob = resultSet.getClob(3);
+ Reader in = clob.getCharacterStream();
+ IOUtil.copyCharacter(in, new OutputStreamWriter(out), size);
}
- finally
+ else
{
- DBUtil.close(resultSet);
+ InputStream in = blob.getBinaryStream();
+ IOUtil.copyBinary(in, out, size);
}
}
catch (SQLException ex)
@@ -398,66 +409,58 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(resultSet);
+ DBUtil.close(stmt);
}
}
public void handleLobs(long fromTime, long toTime, CDOLobHandler handler) throws IOException
{
- PreparedStatement stmt = null;
+ PreparedStatement stmt = transaction.prepareStatement(CDODBSchema.SQL_HANDLE_LOBS, ReuseProbability.LOW);
ResultSet resultSet = null;
try
{
- stmt = statementCache.getPreparedStatement(CDODBSchema.SQL_HANDLE_LOBS, ReuseProbability.LOW);
-
- try
+ resultSet = stmt.executeQuery();
+ while (resultSet.next())
{
- resultSet = stmt.executeQuery();
- while (resultSet.next())
+ byte[] id = HexUtil.hexToBytes(resultSet.getString(1));
+ long size = resultSet.getLong(2);
+ Blob blob = resultSet.getBlob(3);
+ if (resultSet.wasNull())
{
- byte[] id = HexUtil.hexToBytes(resultSet.getString(1));
- long size = resultSet.getLong(2);
- Blob blob = resultSet.getBlob(3);
- if (resultSet.wasNull())
+ Clob clob = resultSet.getClob(4);
+ Reader in = clob.getCharacterStream();
+ Writer out = handler.handleClob(id, size);
+ if (out != null)
{
- Clob clob = resultSet.getClob(4);
- Reader in = clob.getCharacterStream();
- Writer out = handler.handleClob(id, size);
- if (out != null)
+ try
+ {
+ IOUtil.copyCharacter(in, out, size);
+ }
+ finally
{
- try
- {
- IOUtil.copyCharacter(in, out, size);
- }
- finally
- {
- IOUtil.close(out);
- }
+ IOUtil.close(out);
}
}
- else
+ }
+ else
+ {
+ InputStream in = blob.getBinaryStream();
+ OutputStream out = handler.handleBlob(id, size);
+ if (out != null)
{
- InputStream in = blob.getBinaryStream();
- OutputStream out = handler.handleBlob(id, size);
- if (out != null)
+ try
{
- try
- {
- IOUtil.copyBinary(in, out, size);
- }
- finally
- {
- IOUtil.close(out);
- }
+ IOUtil.copyBinary(in, out, size);
+ }
+ finally
+ {
+ IOUtil.close(out);
}
}
}
}
- finally
- {
- DBUtil.close(resultSet);
- }
}
catch (SQLException ex)
{
@@ -465,7 +468,8 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(resultSet);
+ DBUtil.close(stmt);
}
}
@@ -497,11 +501,10 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
protected void writeCommitInfo(CDOBranch branch, long timeStamp, long previousTimeStamp, String userID,
String comment, OMMonitor monitor)
{
- PreparedStatement stmt = null;
+ PreparedStatement stmt = transaction.prepareStatement(CDODBSchema.SQL_CREATE_COMMIT_INFO, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(CDODBSchema.SQL_CREATE_COMMIT_INFO, ReuseProbability.HIGH);
stmt.setLong(1, timeStamp);
stmt.setLong(2, previousTimeStamp);
stmt.setInt(3, branch.getID());
@@ -516,7 +519,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -628,7 +631,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
public Connection getConnection()
{
- return connection;
+ return transaction.getConnection();
}
@Override
@@ -640,11 +643,10 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
@Override
protected void writeBlob(byte[] id, long size, InputStream inputStream) throws IOException
{
- PreparedStatement stmt = null;
+ PreparedStatement stmt = transaction.prepareStatement(CDODBSchema.SQL_WRITE_BLOB, ReuseProbability.MEDIUM);
try
{
- stmt = statementCache.getPreparedStatement(CDODBSchema.SQL_WRITE_BLOB, ReuseProbability.MEDIUM);
stmt.setString(1, HexUtil.bytesToHex(id));
stmt.setLong(2, size);
stmt.setBinaryStream(3, inputStream, (int)size);
@@ -657,18 +659,17 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@Override
protected void writeClob(byte[] id, long size, Reader reader) throws IOException
{
- PreparedStatement stmt = null;
+ PreparedStatement stmt = transaction.prepareStatement(CDODBSchema.SQL_WRITE_CLOB, ReuseProbability.MEDIUM);
try
{
- stmt = statementCache.getPreparedStatement(CDODBSchema.SQL_WRITE_CLOB, ReuseProbability.MEDIUM);
stmt.setString(1, HexUtil.bytesToHex(id));
stmt.setLong(2, size);
stmt.setCharacterStream(3, reader, (int)size);
@@ -681,7 +682,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -755,7 +756,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
protected void doActivate() throws Exception
{
DBStore store = getStore();
- connection = store.getConnection();
+ transaction = store.getDatabase().openTransaction();
connectionKeepAliveTask = new ConnectionKeepAliveTask(this);
long keepAlivePeriod = ConnectionKeepAliveTask.EXECUTION_PERIOD;
@@ -770,23 +771,16 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
}
store.getConnectionKeepAliveTimer().schedule(connectionKeepAliveTask, keepAlivePeriod, keepAlivePeriod);
-
- // TODO - make this configurable?
- statementCache = CDODBUtil.createStatementCache();
- statementCache.setConnection(connection);
- LifecycleUtil.activate(statementCache);
}
@Override
protected void doDeactivate() throws Exception
{
- LifecycleUtil.deactivate(statementCache);
-
connectionKeepAliveTask.cancel();
connectionKeepAliveTask = null;
- DBUtil.close(connection);
- connection = null;
+ ObjectUtil.close(transaction);
+ transaction = null;
}
@Override
@@ -794,7 +788,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
{
// this is called when the accessor is put back into the pool
// we want to make sure that no DB lock is held (see Bug 276926)
- connection.rollback();
+ getConnection().rollback();
}
@Override
@@ -846,11 +840,10 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
branchID = getStore().getNextLocalBranchID();
}
- PreparedStatement stmt = null;
+ PreparedStatement stmt = transaction.prepareStatement(CDODBSchema.SQL_CREATE_BRANCH, ReuseProbability.LOW);
try
{
- stmt = statementCache.getPreparedStatement(CDODBSchema.SQL_CREATE_BRANCH, ReuseProbability.LOW);
stmt.setInt(1, branchID);
stmt.setString(2, branchInfo.getName());
stmt.setInt(3, branchInfo.getBaseBranchID());
@@ -866,19 +859,18 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
public BranchInfo loadBranch(int branchID)
{
checkBranchingSupport();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = transaction.prepareStatement(CDODBSchema.SQL_LOAD_BRANCH, ReuseProbability.HIGH);
ResultSet resultSet = null;
try
{
- stmt = statementCache.getPreparedStatement(CDODBSchema.SQL_LOAD_BRANCH, ReuseProbability.HIGH);
stmt.setInt(1, branchID);
resultSet = stmt.executeQuery();
@@ -899,19 +891,18 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
public SubBranchInfo[] loadSubBranches(int baseID)
{
checkBranchingSupport();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = transaction.prepareStatement(CDODBSchema.SQL_LOAD_SUB_BRANCHES, ReuseProbability.HIGH);
ResultSet resultSet = null;
try
{
- stmt = statementCache.getPreparedStatement(CDODBSchema.SQL_LOAD_SUB_BRANCHES, ReuseProbability.HIGH);
stmt.setInt(1, baseID);
resultSet = stmt.executeQuery();
@@ -933,7 +924,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -948,7 +939,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
public int loadBranches(int startID, int endID, CDOBranchHandler handler)
{
int count = 0;
- PreparedStatement stmt = null;
+ PreparedStatement stmt = transaction.prepareStatement(CDODBSchema.SQL_LOAD_BRANCHES, ReuseProbability.HIGH);
ResultSet resultSet = null;
InternalRepository repository = getSession().getManager().getRepository();
@@ -956,7 +947,6 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
try
{
- stmt = statementCache.getPreparedStatement(CDODBSchema.SQL_LOAD_BRANCHES, ReuseProbability.HIGH);
stmt.setInt(1, startID);
stmt.setInt(2, endID > 0 ? endID : Integer.MAX_VALUE);
@@ -982,7 +972,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -1041,7 +1031,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
builder.append(count < 0 || CDOBranchPoint.UNSPECIFIED_DATE <= endTime && endTime <= startTime ? " DESC" : " ASC"); //$NON-NLS-1$
String sql = builder.toString();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = transaction.prepareStatement(sql, ReuseProbability.MEDIUM);
ResultSet resultSet = null;
InternalRepository repository = getStore().getRepository();
@@ -1051,8 +1041,6 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
try
{
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.MEDIUM);
-
resultSet = stmt.executeQuery();
while (resultSet.next())
{
@@ -1084,7 +1072,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -1110,6 +1098,8 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
out.writeCDOID(store.getIDHandler().getLastObjectID()); // See bug 325097
}
+ Connection connection = getConnection();
+
String where = " WHERE " + CDODBSchema.BRANCHES_ID + " BETWEEN " + fromBranchID + " AND " + toBranchID;
DBUtil.serializeTable(out, connection, CDODBSchema.BRANCHES, null, where);
@@ -1145,6 +1135,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
monitor.begin(commitWork + size + commitWork);
Collection<InternalCDOPackageUnit> packageUnits = new HashSet<InternalCDOPackageUnit>();
+ Connection connection = getConnection();
try
{
@@ -1182,6 +1173,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
{
try
{
+ Connection connection = getConnection();
connection.rollback();
}
catch (SQLException ex)
@@ -1202,6 +1194,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
{
DBStore store = getStore();
IMetaDataManager metaDataManager = store.getMetaDataManager();
+ Connection connection = getConnection();
packageUnits.addAll(metaDataManager.rawImport(connection, in, fromCommitTime, toCommitTime, monitor.fork()));
@@ -1306,6 +1299,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor,
try
{
+ Connection connection = getConnection();
connection.commit();
}
catch (SQLException ex)
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DurableLockingManager.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DurableLockingManager.java
index f3b21b49dc..b7c9627340 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DurableLockingManager.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DurableLockingManager.java
@@ -22,8 +22,6 @@ import org.eclipse.emf.cdo.common.lock.IDurableLockingManager.LockGrade;
import org.eclipse.emf.cdo.common.protocol.CDODataInput;
import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.spi.common.branch.InternalCDOBranchManager;
import org.eclipse.emf.cdo.spi.server.InternalLockManager;
@@ -32,6 +30,7 @@ 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.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
@@ -135,12 +134,10 @@ public class DurableLockingManager extends Lifecycle
}
}
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsertLockArea, ReuseProbability.LOW);
try
{
- stmt = statementCache.getPreparedStatement(sqlInsertLockArea, ReuseProbability.LOW);
stmt.setString(1, durableLockingID);
stmt.setString(2, userID);
stmt.setInt(3, branchPoint.getBranch().getID());
@@ -155,7 +152,7 @@ public class DurableLockingManager extends Lifecycle
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
if (!locks.isEmpty())
@@ -175,12 +172,10 @@ public class DurableLockingManager extends Lifecycle
private void insertLocks(DBStoreAccessor accessor, String durableLockingID, Map<CDOID, LockGrade> locks)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsertLock, ReuseProbability.MEDIUM);
try
{
- stmt = statementCache.getPreparedStatement(sqlInsertLock, ReuseProbability.MEDIUM);
stmt.setString(1, durableLockingID);
for (Entry<CDOID, LockGrade> entry : locks.entrySet())
@@ -200,22 +195,20 @@ public class DurableLockingManager extends Lifecycle
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
public LockArea getLockArea(DBStoreAccessor accessor, String durableLockingID) throws LockAreaNotFoundException
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlSelectLockArea, ReuseProbability.MEDIUM);
ResultSet resultSet = null;
try
{
- stmt = statementCache.getPreparedStatement(sqlSelectLockArea, ReuseProbability.MEDIUM);
stmt.setString(1, durableLockingID);
- resultSet = stmt.executeQuery();
+ resultSet = stmt.executeQuery();
if (!resultSet.next())
{
throw new LockAreaNotFoundException(durableLockingID);
@@ -235,13 +228,12 @@ public class DurableLockingManager extends Lifecycle
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
public void getLockAreas(DBStoreAccessor accessor, String userIDPrefix, Handler handler)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement stmt = null;
ResultSet resultSet = null;
@@ -249,11 +241,11 @@ public class DurableLockingManager extends Lifecycle
{
if (userIDPrefix.length() == 0)
{
- stmt = statementCache.getPreparedStatement(sqlSelectAllLockAreas, ReuseProbability.MEDIUM);
+ stmt = accessor.getDBTransaction().prepareStatement(sqlSelectAllLockAreas, ReuseProbability.MEDIUM);
}
else
{
- stmt = statementCache.getPreparedStatement(sqlSelectLockAreas, ReuseProbability.MEDIUM);
+ stmt = accessor.getDBTransaction().prepareStatement(sqlSelectLockAreas, ReuseProbability.MEDIUM);
stmt.setString(1, userIDPrefix + "%");
}
@@ -280,7 +272,7 @@ public class DurableLockingManager extends Lifecycle
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -290,12 +282,10 @@ public class DurableLockingManager extends Lifecycle
{
unlockWithoutCommit(accessor, durableLockingID);
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlDeleteLockArea, ReuseProbability.LOW);
try
{
- stmt = statementCache.getPreparedStatement(sqlDeleteLockArea, ReuseProbability.LOW);
stmt.setString(1, durableLockingID);
DBUtil.update(stmt, true);
@@ -306,7 +296,7 @@ public class DurableLockingManager extends Lifecycle
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
accessor.getConnection().commit();
@@ -360,14 +350,11 @@ public class DurableLockingManager extends Lifecycle
private void unlockWithoutCommit(DBStoreAccessor accessor, String durableLockingID)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlDeleteLocks, ReuseProbability.MEDIUM);
try
{
- stmt = statementCache.getPreparedStatement(sqlDeleteLocks, ReuseProbability.MEDIUM);
stmt.setString(1, durableLockingID);
-
DBUtil.update(stmt, false);
}
catch (SQLException e)
@@ -376,7 +363,7 @@ public class DurableLockingManager extends Lifecycle
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -478,13 +465,11 @@ public class DurableLockingManager extends Lifecycle
private Map<CDOID, LockGrade> getLockMap(DBStoreAccessor accessor, String durableLockingID)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlSelectLocks, ReuseProbability.MEDIUM);
ResultSet resultSet = null;
try
{
- stmt = statementCache.getPreparedStatement(sqlSelectLocks, ReuseProbability.MEDIUM);
stmt.setString(1, durableLockingID);
resultSet = stmt.executeQuery();
@@ -506,7 +491,7 @@ public class DurableLockingManager extends Lifecycle
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -518,22 +503,17 @@ public class DurableLockingManager extends Lifecycle
return;
}
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmtSelect = null;
- PreparedStatement stmtInsertOrDelete = null;
- PreparedStatement stmtUpdate = null;
+ String sql = on ? sqlInsertLock : sqlDeleteLock;
+
+ PreparedStatement stmtSelect = accessor.getDBTransaction().prepareStatement(sqlSelectLock, ReuseProbability.MEDIUM);
+ PreparedStatement stmtInsertOrDelete = accessor.getDBTransaction().prepareStatement(sql, ReuseProbability.MEDIUM);
+ PreparedStatement stmtUpdate = accessor.getDBTransaction().prepareStatement(sqlUpdateLock, ReuseProbability.MEDIUM);
ResultSet resultSet = null;
try
{
- stmtSelect = statementCache.getPreparedStatement(sqlSelectLock, ReuseProbability.MEDIUM);
stmtSelect.setString(1, durableLockingID);
-
- String sql = on ? sqlInsertLock : sqlDeleteLock;
- stmtInsertOrDelete = statementCache.getPreparedStatement(sql, ReuseProbability.MEDIUM);
stmtInsertOrDelete.setString(1, durableLockingID);
-
- stmtUpdate = statementCache.getPreparedStatement(sqlUpdateLock, ReuseProbability.MEDIUM);
stmtUpdate.setString(2, durableLockingID);
InternalLockManager lockManager = accessor.getStore().getRepository().getLockingManager();
@@ -578,9 +558,9 @@ public class DurableLockingManager extends Lifecycle
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmtUpdate);
- statementCache.releasePreparedStatement(stmtInsertOrDelete);
- statementCache.releasePreparedStatement(stmtSelect);
+ DBUtil.close(stmtUpdate);
+ DBUtil.close(stmtInsertOrDelete);
+ DBUtil.close(stmtSelect);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ExternalReferenceManager.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ExternalReferenceManager.java
index 0b006126db..0f9464a73a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ExternalReferenceManager.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ExternalReferenceManager.java
@@ -21,8 +21,6 @@ import org.eclipse.emf.cdo.server.StoreThreadLocal;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.net4j.db.DBException;
@@ -30,6 +28,7 @@ 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.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
@@ -111,16 +110,14 @@ public class ExternalReferenceManager extends Lifecycle
public String unmapURI(IDBStoreAccessor accessor, long mappedId)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlSelectByLongID, ReuseProbability.HIGH);
ResultSet resultSet = null;
try
{
- stmt = statementCache.getPreparedStatement(sqlSelectByLongID, ReuseProbability.HIGH);
stmt.setLong(1, mappedId);
- resultSet = stmt.executeQuery();
+ resultSet = stmt.executeQuery();
if (!resultSet.next())
{
OM.LOG.error("External ID " + mappedId + " not found. Database inconsistent!");
@@ -136,23 +133,20 @@ public class ExternalReferenceManager extends Lifecycle
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
public long lookupByURI(IDBStoreAccessor accessor, String uri)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlSelectByURI, ReuseProbability.HIGH);
ResultSet resultSet = null;
try
{
- stmt = statementCache.getPreparedStatement(sqlSelectByURI, ReuseProbability.HIGH);
stmt.setString(1, uri);
resultSet = stmt.executeQuery();
-
if (resultSet.next())
{
return resultSet.getLong(1);
@@ -168,7 +162,7 @@ public class ExternalReferenceManager extends Lifecycle
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -253,13 +247,10 @@ public class ExternalReferenceManager extends Lifecycle
private long insertNew(IDBStoreAccessor accessor, String uri, long commitTime)
{
long newMappedID = lastMappedID.decrementAndGet();
-
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsert, ReuseProbability.MEDIUM);
try
{
- stmt = statementCache.getPreparedStatement(sqlInsert, ReuseProbability.MEDIUM);
stmt.setLong(1, newMappedID);
stmt.setString(2, uri);
stmt.setLong(3, commitTime);
@@ -273,7 +264,7 @@ public class ExternalReferenceManager extends Lifecycle
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NullPreparedStatementCache.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NullPreparedStatementCache.java
deleted file mode 100644
index 3090240eb4..0000000000
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NullPreparedStatementCache.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2004 - 2012 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
- * Stefan Winkler - 271444: [DB] Multiple refactorings bug 271444
- */
-package org.eclipse.emf.cdo.server.internal.db;
-
-import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
-
-import org.eclipse.net4j.db.DBException;
-import org.eclipse.net4j.db.DBUtil;
-
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.HashSet;
-
-/**
- * @author Stefan Winkler
- * @since 2.0
- */
-public class NullPreparedStatementCache extends AbstractPreparedStatementCache
-{
- private HashSet<PreparedStatement> allocatedStatements = new HashSet<PreparedStatement>();
-
- public NullPreparedStatementCache()
- {
- }
-
- public PreparedStatement getPreparedStatement(String sql, ReuseProbability reuseProbability)
- {
- try
- {
- PreparedStatement result = getConnection().prepareStatement(sql);
- allocatedStatements.add(result);
- return result;
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- }
-
- public void releasePreparedStatement(PreparedStatement ps)
- {
- allocatedStatements.remove(ps);
- DBUtil.close(ps);
- }
-
- public void invalidate()
- {
- checkState(allocatedStatements.isEmpty(), "Cache can only be invalidated if there are no allocated statements");
-
- // Do nothing, since there are no cached statements
- }
-
- @Override
- protected void doBeforeDeactivate() throws Exception
- {
- if (!allocatedStatements.isEmpty())
- {
- OM.LOG.warn("Possible Leak Detected:"); //$NON-NLS-1$
- for (PreparedStatement ps : allocatedStatements)
- {
- OM.LOG.warn("- " + ps.toString()); //$NON-NLS-1$
- }
-
- assert false;
- }
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/SmartPreparedStatementCache.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/SmartPreparedStatementCache.java
deleted file mode 100644
index 9294bf3944..0000000000
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/SmartPreparedStatementCache.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (c) 2004 - 2012 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:
- * Stefan Winkler - initial API and implementation
- */
-package org.eclipse.emf.cdo.server.internal.db;
-
-import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
-
-import org.eclipse.net4j.db.DBException;
-import org.eclipse.net4j.db.DBUtil;
-import org.eclipse.net4j.util.ImplementationError;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * @author Stefan Winkler
- * @since 2.0
- */
-public class SmartPreparedStatementCache extends AbstractPreparedStatementCache
-{
- private final int capacity;
-
- private TreeMap<String, CachedPreparedStatement> cache = new TreeMap<String, CachedPreparedStatement>();
-
- private Map<PreparedStatement, CachedPreparedStatement> checkOuts = new HashMap<PreparedStatement, CachedPreparedStatement>();
-
- private long lastTouch;
-
- public SmartPreparedStatementCache(int capacity)
- {
- this.capacity = capacity;
- }
-
- public final int getCapacity()
- {
- return capacity;
- }
-
- public int size()
- {
- return cache.size();
- }
-
- public PreparedStatement getPreparedStatement(String sql, ReuseProbability probability)
- {
- PreparedStatement preparedStatement;
-
- CachedPreparedStatement cachedStatement = cache.remove(sql);
- if (cachedStatement == null)
- {
- try
- {
- Connection connection = getConnection();
- preparedStatement = connection.prepareStatement(sql);
- cachedStatement = new CachedPreparedStatement(sql, preparedStatement, probability);
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- }
- else
- {
- preparedStatement = cachedStatement.getPreparedStatement();
- }
-
- checkOuts.put(preparedStatement, cachedStatement);
- return preparedStatement;
- }
-
- public void releasePreparedStatement(PreparedStatement preparedStatement)
- {
- if (preparedStatement == null)
- {
- // Bug 276926: Silently accept preparedStatement == null and do nothing.
- return;
- }
-
- CachedPreparedStatement cachedStatement = checkOuts.remove(preparedStatement);
- cachedStatement.setTouch(++lastTouch);
-
- String sql = cachedStatement.getSQL();
- if (cache.put(sql, cachedStatement) != null)
- {
- throw new ImplementationError(sql + " already in cache"); //$NON-NLS-1$
- }
-
- if (cache.size() > capacity)
- {
- CachedPreparedStatement old = cache.remove(cache.firstKey());
- DBUtil.close(old.getPreparedStatement());
- }
- }
-
- public void invalidate()
- {
- checkState(checkOuts.isEmpty(), "Cache can only be invalidated if no prepared statement is checked out");
-
- // Close all statements in the cache, then clear the cache.
- for (CachedPreparedStatement stmt : cache.values())
- {
- DBUtil.close(stmt.getPreparedStatement());
- }
-
- cache.clear();
- }
-
- @Override
- protected void doBeforeDeactivate() throws Exception
- {
- if (!checkOuts.isEmpty())
- {
- OM.LOG.warn("Statement leak detected"); //$NON-NLS-1$
- }
- }
-
- /**
- * @author Stefan Winkler
- */
- private static final class CachedPreparedStatement implements Comparable<CachedPreparedStatement>
- {
- private String sql;
-
- private PreparedStatement preparedStatement;
-
- private ReuseProbability probability;
-
- private long touch;
-
- public CachedPreparedStatement(String sql, PreparedStatement preparedStatement, ReuseProbability probability)
- {
- this.sql = sql;
- this.preparedStatement = preparedStatement;
- this.probability = probability;
- }
-
- public String getSQL()
- {
- return sql;
- }
-
- public PreparedStatement getPreparedStatement()
- {
- return preparedStatement;
- }
-
- public void setTouch(long touch)
- {
- this.touch = touch;
- }
-
- public int compareTo(CachedPreparedStatement o)
- {
- int result = probability.compareTo(o.probability);
- if (result == 0)
- {
- result = (int)(o.touch - touch);
- }
-
- return result;
- }
-
- @Override
- public String toString()
- {
- return "CachedPreparedStatement[sql=" + sql + ", probability=" + probability + ", touch=" + touch + "]";
- }
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
index 85539c0134..be8da39a9d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
@@ -28,7 +28,6 @@ import org.eclipse.emf.cdo.server.StoreThreadLocal;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IMetaDataManager;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
import org.eclipse.emf.cdo.server.db.mapping.IClassMapping;
import org.eclipse.emf.cdo.server.db.mapping.IListMapping;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
@@ -277,8 +276,7 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
private void releaseCurrentStatement()
{
- IPreparedStatementCache statementCache = getAccessor().getStatementCache();
- statementCache.releasePreparedStatement(currentStatement);
+ DBUtil.close(currentStatement);
currentStatement = null;
}
};
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractFeatureMapTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractFeatureMapTableMapping.java
index fec2590376..1249a6870d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractFeatureMapTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractFeatureMapTableMapping.java
@@ -27,8 +27,6 @@ import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
import org.eclipse.emf.cdo.server.db.IIDHandler;
import org.eclipse.emf.cdo.server.db.IMetaDataManager;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
@@ -38,6 +36,7 @@ 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.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
@@ -176,14 +175,14 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
{
String tableName = getTable().getName();
FieldInfo[] fields = getKeyFields();
-
+
// ---------------- SELECT to read chunks ----------------------------
StringBuilder builder = new StringBuilder();
builder.append("SELECT ");
-
+
builder.append(FEATUREMAP_TAG);
builder.append(", ");
-
+
Iterator<String> iter = columnNames.iterator();
while (iter.hasNext())
{
@@ -193,11 +192,11 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
builder.append(", ");
}
}
-
+
builder.append(" FROM ");
builder.append(tableName);
builder.append(" WHERE ");
-
+
for (int i = 0; i < fields.length; i++)
{
builder.append(fields[i].getName());
@@ -212,14 +211,14 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
builder.append("=? ");
}
}
-
+
sqlSelectChunksPrefix = builder.toString();
-
+
sqlOrderByIndex = " ORDER BY " + FEATUREMAP_IDX; //$NON-NLS-1$
-
+
// INSERT with dynamic field name
// TODO: Better: universal INSERT-Statement, because of stmt caching!
-
+
// ----------------- INSERT - prefix -----------------
builder = new StringBuilder("INSERT INTO ");
builder.append(tableName);
@@ -229,13 +228,13 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
builder.append(fields[i].getName());
builder.append(", "); //$NON-NLS-1$
}
-
+
for (int i = 0; i < columnNames.size(); i++)
{
builder.append(columnNames.get(i));
builder.append(", "); //$NON-NLS-1$
}
-
+
builder.append(FEATUREMAP_IDX);
builder.append(", "); //$NON-NLS-1$
builder.append(FEATUREMAP_TAG);
@@ -244,7 +243,7 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
{
builder.append("?, ");
}
-
+
builder.append("?, ?)");
sqlInsert = builder.toString();
}
@@ -317,15 +316,14 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
.getName(), revision.getID(), revision.getVersion());
}
+ String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
+
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sql, ReuseProbability.HIGH);
ResultSet resultSet = null;
try
{
- String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.HIGH);
setKeyFields(stmt, revision);
if (listChunk != CDORevision.UNCHUNKED)
@@ -356,7 +354,7 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
if (TRACER.isEnabled())
@@ -386,24 +384,22 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
getFeature().getName(), chunkReader.getRevision().getID(), chunkReader.getRevision().getVersion());
}
+ StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
+ if (where != null)
+ {
+ builder.append(" AND "); //$NON-NLS-1$
+ builder.append(where);
+ }
+
+ builder.append(sqlOrderByIndex);
+ String sql = builder.toString();
+
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = chunkReader.getAccessor().getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = chunkReader.getAccessor().getDBTransaction().prepareStatement(sql, ReuseProbability.LOW);
ResultSet resultSet = null;
try
{
- StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
- if (where != null)
- {
- builder.append(" AND "); //$NON-NLS-1$
- builder.append(where);
- }
-
- builder.append(sqlOrderByIndex);
-
- String sql = builder.toString();
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.LOW);
setKeyFields(stmt, chunkReader.getRevision());
resultSet = stmt.executeQuery();
@@ -461,7 +457,7 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -478,10 +474,6 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
protected final void writeValue(IDBStoreAccessor accessor, CDORevision revision, int idx, Object value)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER
@@ -489,14 +481,17 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
"Writing value for feature {0}.{1} index {2} of {3} : {4}", getContainingClass().getName(), getFeature(), idx, revision, value); //$NON-NLS-1$
}
+ FeatureMap.Entry entry = (FeatureMap.Entry)value;
+ EStructuralFeature entryFeature = entry.getEStructuralFeature();
+ CDOID tag = getTagByFeature(entryFeature, revision.getTimeStamp());
+ ITypeMapping typeMapping = getTypeMapping(tag);
+ String columnName = getColumnName(tag);
+
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsert, ReuseProbability.HIGH);
+
try
{
- FeatureMap.Entry entry = (FeatureMap.Entry)value;
- EStructuralFeature entryFeature = entry.getEStructuralFeature();
- CDOID tag = getTagByFeature(entryFeature, revision.getTimeStamp());
- String columnName = getColumnName(tag);
-
- stmt = statementCache.getPreparedStatement(sqlInsert, ReuseProbability.HIGH);
setKeyFields(stmt, revision);
int column = getKeyFields().length + 1;
@@ -504,7 +499,7 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
{
if (columnNames.get(i).equals(columnName))
{
- getTypeMapping(tag).setValue(stmt, column++, entry.getValue());
+ typeMapping.setValue(stmt, column++, entry.getValue());
}
else
{
@@ -522,7 +517,7 @@ public abstract class AbstractFeatureMapTableMapping extends AbstractBasicListTa
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java
index 84bfa281e2..8d449b46ae 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java
@@ -28,8 +28,6 @@ import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStoreAccessor.QueryXRefsContext;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IClassMapping;
import org.eclipse.emf.cdo.server.db.mapping.IListMapping;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
@@ -43,6 +41,7 @@ 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.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBSchema;
@@ -562,11 +561,6 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
CDORevisionManager revisionManager = repository.getRevisionManager();
CDOBranchManager branchManager = repository.getBranchManager();
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
- ResultSet resultSet = null;
-
// TODO: test for timeStamp == INVALID_TIME and encode revision.isValid() as WHERE instead of fetching all revisions
// in order to increase performance
@@ -610,9 +604,12 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
}
}
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(builder.toString(), ReuseProbability.LOW);
+ ResultSet resultSet = null;
+
try
{
- stmt = statementCache.getPreparedStatement(builder.toString(), ReuseProbability.LOW);
for (int i = 0; i < timeParameters; i++)
{
stmt.setLong(i + 1, timeStamp);
@@ -643,7 +640,7 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -675,15 +672,13 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
}
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(builder.toString(), ReuseProbability.LOW);
ResultSet resultSet = null;
Set<CDOID> result = new HashSet<CDOID>();
try
{
- stmt = statementCache.getPreparedStatement(builder.toString(), ReuseProbability.LOW);
int column = 1;
for (CDOChangeSetSegment segment : segments)
{
@@ -707,7 +702,7 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping, I
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
index 3903ff4fef..8cf3ada1f6 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
@@ -414,19 +414,17 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
*/
private boolean queryResources(IDBStoreAccessor accessor, IClassMapping classMapping, QueryResourcesContext context)
{
- IIDHandler idHandler = getStore().getIDHandler();
- PreparedStatement stmt = null;
- ResultSet resultSet = null;
-
CDOID folderID = context.getFolderID();
String name = context.getName();
boolean exactMatch = context.exactMatch();
+ IIDHandler idHandler = getStore().getIDHandler();
+ PreparedStatement stmt = classMapping.createResourceQueryStatement(accessor, folderID, name, exactMatch, context);
+ ResultSet resultSet = null;
+
try
{
- stmt = classMapping.createResourceQueryStatement(accessor, folderID, name, exactMatch, context);
resultSet = stmt.executeQuery();
-
while (resultSet.next())
{
CDOID id = idHandler.getCDOID(resultSet, 1);
@@ -451,7 +449,7 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
finally
{
DBUtil.close(resultSet);
- accessor.getStatementCache().releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java
index 767435d030..fa036aa9ec 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java
@@ -22,8 +22,6 @@ import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
@@ -33,6 +31,7 @@ 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.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
@@ -230,14 +229,12 @@ public abstract class AbstractListTableMapping extends AbstractBasicListTableMap
getFeature().getName(), revision.getID(), revision.getVersion());
}
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sql, ReuseProbability.HIGH);
ResultSet resultSet = null;
try
{
- String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.HIGH);
setKeyFields(stmt, revision);
if (TRACER.isEnabled())
@@ -271,7 +268,7 @@ public abstract class AbstractListTableMapping extends AbstractBasicListTableMap
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
if (TRACER.isEnabled())
@@ -289,23 +286,21 @@ public abstract class AbstractListTableMapping extends AbstractBasicListTableMap
getFeature().getName(), chunkReader.getRevision().getID(), chunkReader.getRevision().getVersion());
}
- IPreparedStatementCache statementCache = chunkReader.getAccessor().getStatementCache();
- PreparedStatement stmt = null;
+ StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
+ if (where != null)
+ {
+ builder.append(" AND "); //$NON-NLS-1$
+ builder.append(where);
+ }
+
+ builder.append(sqlOrderByIndex);
+ String sql = builder.toString();
+
+ PreparedStatement stmt = chunkReader.getAccessor().getDBTransaction().prepareStatement(sql, ReuseProbability.LOW);
ResultSet resultSet = null;
try
{
- StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
- if (where != null)
- {
- builder.append(" AND "); //$NON-NLS-1$
- builder.append(where);
- }
-
- builder.append(sqlOrderByIndex);
-
- String sql = builder.toString();
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.LOW);
setKeyFields(stmt, chunkReader.getRevision());
resultSet = stmt.executeQuery();
@@ -362,7 +357,7 @@ public abstract class AbstractListTableMapping extends AbstractBasicListTableMap
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -379,24 +374,20 @@ public abstract class AbstractListTableMapping extends AbstractBasicListTableMap
protected final void writeValue(IDBStoreAccessor accessor, CDORevision revision, int idx, Object value)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER.format("Writing value for feature {0}.{1} index {2} of {3}v{4} : {5}", getContainingClass().getName(),
getFeature().getName(), idx, revision.getID(), revision.getVersion(), value);
}
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsertEntry, ReuseProbability.HIGH);
+
try
{
- stmt = statementCache.getPreparedStatement(sqlInsertEntry, ReuseProbability.HIGH);
-
setKeyFields(stmt, revision);
int column = getKeyFields().length + 1;
stmt.setInt(column++, idx);
typeMapping.setValue(stmt, column++, value);
-
DBUtil.update(stmt, true);
}
catch (SQLException e)
@@ -405,7 +396,7 @@ public abstract class AbstractListTableMapping extends AbstractBasicListTableMap
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMapping.java
index baf32ed022..2e5269cd53 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMapping.java
@@ -17,13 +17,12 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -85,12 +84,10 @@ public class AuditFeatureMapTableMapping extends AbstractFeatureMapTableMapping
public void rawDeleted(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, int version)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlClear, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, version);
DBUtil.update(stmt, false);
@@ -101,7 +98,7 @@ public class AuditFeatureMapTableMapping extends AbstractFeatureMapTableMapping
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMappingWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMappingWithRanges.java
index db0dfbd238..21ffa9ca7b 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMappingWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditFeatureMapTableMappingWithRanges.java
@@ -40,8 +40,6 @@ import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IListMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
@@ -52,6 +50,7 @@ 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.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
@@ -391,7 +390,6 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
public void readValues(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
MoveableList<Object> list = revision.getList(getFeature());
-
if (listChunk == 0 || list.size() == 0)
{
// nothing to read take shortcut
@@ -404,17 +402,14 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
.getName(), revision.getID(), revision.getVersion());
}
+ String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
+
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sql, ReuseProbability.HIGH);
ResultSet resultSet = null;
try
{
- String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
-
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.HIGH);
-
idHandler.setCDOID(stmt, 1, revision.getID());
stmt.setInt(2, revision.getVersion());
stmt.setInt(3, revision.getVersion());
@@ -447,7 +442,7 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
if (TRACER.isEnabled())
@@ -477,24 +472,22 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
getFeature().getName(), chunkReader.getRevision().getID(), chunkReader.getRevision().getVersion());
}
+ StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
+ if (where != null)
+ {
+ builder.append(" AND "); //$NON-NLS-1$
+ builder.append(where);
+ }
+
+ builder.append(sqlOrderByIndex);
+ String sql = builder.toString();
+
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = chunkReader.getAccessor().getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = chunkReader.getAccessor().getDBTransaction().prepareStatement(sql, ReuseProbability.LOW);
ResultSet resultSet = null;
try
{
- StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
- if (where != null)
- {
- builder.append(" AND "); //$NON-NLS-1$
- builder.append(where);
- }
-
- builder.append(sqlOrderByIndex);
-
- String sql = builder.toString();
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.LOW);
idHandler.setCDOID(stmt, 1, chunkReader.getRevision().getID());
stmt.setInt(2, chunkReader.getRevision().getVersion());
stmt.setInt(3, chunkReader.getRevision().getVersion());
@@ -554,7 +547,7 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -654,14 +647,13 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
public void clearList(IDBStoreAccessor accessor, CDOID id, int oldVersion, int newVersion)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmtDeleteTemp = null;
- PreparedStatement stmtClear = null;
+ PreparedStatement stmtDeleteTemp = accessor.getDBTransaction().prepareStatement(sqlDeleteList,
+ ReuseProbability.HIGH);
+ PreparedStatement stmtClear = accessor.getDBTransaction().prepareStatement(sqlClearList, ReuseProbability.HIGH);
try
{
// delete temporary entries
- stmtDeleteTemp = statementCache.getPreparedStatement(sqlDeleteList, ReuseProbability.HIGH);
idHandler.setCDOID(stmtDeleteTemp, 1, id);
stmtDeleteTemp.setInt(2, newVersion);
@@ -672,7 +664,6 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
}
// clear rest of the list
- stmtClear = statementCache.getPreparedStatement(sqlClearList, ReuseProbability.HIGH);
stmtClear.setInt(1, newVersion);
idHandler.setCDOID(stmtClear, 2, id);
@@ -688,8 +679,8 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
}
finally
{
- statementCache.releasePreparedStatement(stmtDeleteTemp);
- statementCache.releasePreparedStatement(stmtClear);
+ DBUtil.close(stmtClear);
+ DBUtil.close(stmtDeleteTemp);
}
}
@@ -900,13 +891,10 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
int endIndex)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlUpdateIndex, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
-
for (int index = startIndex; index <= endIndex; ++index)
{
if (TRACER.isEnabled())
@@ -963,7 +951,7 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -971,12 +959,10 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
int endIndex)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlUpdateIndex, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
for (int index = endIndex; index >= startIndex; --index)
{
if (TRACER.isEnabled())
@@ -1033,32 +1019,30 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
}
private void addEntry(IDBStoreAccessor accessor, CDOID id, int version, int index, Object value, long timestamp)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER.format("Adding value for feature() {0}.{1} index {2} of {3}v{4} : {5}", //$NON-NLS-1$
getContainingClass().getName(), getFeature().getName(), index, id, version, value);
}
- try
- {
- FeatureMap.Entry entry = (FeatureMap.Entry)value;
- EStructuralFeature entryFeature = entry.getEStructuralFeature();
- CDOID tag = getTagByFeature(entryFeature, timestamp);
- String columnName = getColumnName(tag);
+ FeatureMap.Entry entry = (FeatureMap.Entry)value;
+ EStructuralFeature entryFeature = entry.getEStructuralFeature();
+ CDOID tag = getTagByFeature(entryFeature, timestamp);
+ ITypeMapping typeMapping = getTypeMapping(tag);
+ String columnName = getColumnName(tag);
- stmt = statementCache.getPreparedStatement(sqlInsert, ReuseProbability.HIGH);
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsert, ReuseProbability.HIGH);
+ try
+ {
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, version);
@@ -1070,7 +1054,7 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
{
if (columnNames.get(i).equals(columnName))
{
- getTypeMapping(tag).setValue(stmt, column++, entry.getValue());
+ typeMapping.setValue(stmt, column++, entry.getValue());
}
else
{
@@ -1090,27 +1074,24 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
private void removeEntry(IDBStoreAccessor accessor, CDOID id, int oldVersion, int newVersion, int index)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER.format("Removing value for feature() {0}.{1} index {2} of {3}v{4}", //$NON-NLS-1$
getContainingClass().getName(), getFeature().getName(), index, id, newVersion);
}
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlDeleteEntry, ReuseProbability.HIGH);
+
try
{
// try to delete a temporary entry first
- stmt = statementCache.getPreparedStatement(sqlDeleteEntry, ReuseProbability.HIGH);
-
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, index);
@@ -1136,8 +1117,8 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
else
{
// no temporary entry found, so mark the entry as removed
- statementCache.releasePreparedStatement(stmt);
- stmt = statementCache.getPreparedStatement(sqlRemoveEntry, ReuseProbability.HIGH);
+ DBUtil.close(stmt);
+ stmt = accessor.getDBTransaction().prepareStatement(sqlRemoveEntry, ReuseProbability.HIGH);
column = 1;
stmt.setInt(column++, newVersion);
@@ -1168,21 +1149,17 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
private FeatureMap.Entry getValue(IDBStoreAccessor accessor, CDOID id, int index)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
- FeatureMap.Entry result = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlGetValue, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlGetValue, ReuseProbability.HIGH);
-
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, index);
@@ -1195,12 +1172,14 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
CDOID tag = idHandler.getCDOID(resultSet, 1);
Object value = getTypeMapping(tag).readValue(resultSet);
- result = CDORevisionUtil.createFeatureMapEntry(getFeatureByTag(tag), value);
+ FeatureMap.Entry result = CDORevisionUtil.createFeatureMapEntry(getFeatureByTag(tag), value);
if (TRACER.isEnabled())
{
TRACER.format("Read value (index {0}) from result set: {1}", index, result); //$NON-NLS-1$
}
+
+ return result;
}
catch (SQLException e)
{
@@ -1208,10 +1187,8 @@ public class AuditFeatureMapTableMappingWithRanges extends AbstractBasicListTabl
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
-
- return result;
}
public final boolean queryXRefs(IDBStoreAccessor accessor, String mainTableName, String mainTableWhere,
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java
index d57dae7eca..121664a824 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java
@@ -16,13 +16,12 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.emf.ecore.EClass;
@@ -87,12 +86,10 @@ public class AuditListTableMapping extends AbstractListTableMapping
public void rawDeleted(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, int version)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlClear, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, version);
DBUtil.update(stmt, false);
@@ -103,7 +100,7 @@ public class AuditListTableMapping extends AbstractListTableMapping
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java
index b2eb2cd7cd..dac4007f6a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMappingWithRanges.java
@@ -36,8 +36,6 @@ import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IListMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
@@ -48,6 +46,7 @@ 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.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
@@ -303,15 +302,14 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
getFeature().getName(), revision.getID(), revision.getVersion());
}
+ String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
+
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sql, ReuseProbability.HIGH);
ResultSet resultSet = null;
try
{
- String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, revision.getID());
stmt.setInt(2, revision.getVersion());
stmt.setInt(3, revision.getVersion());
@@ -334,6 +332,14 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
list.set(currentIndex++, value);
}
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.format(
+ "Reading {4} list values done for feature {0}.{1} of {2}v{3}", //$NON-NLS-1$
+ getContainingClass().getName(), getFeature().getName(), revision.getID(), revision.getVersion(),
+ list.size());
+ }
}
catch (SQLException ex)
{
@@ -342,13 +348,7 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.format("Reading {4} list values done for feature {0}.{1} of {2}v{3}", //$NON-NLS-1$
- getContainingClass().getName(), getFeature().getName(), revision.getID(), revision.getVersion(), list.size());
+ DBUtil.close(stmt);
}
}
@@ -360,24 +360,22 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
getFeature().getName(), chunkReader.getRevision().getID(), chunkReader.getRevision().getVersion());
}
+ StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
+ if (where != null)
+ {
+ builder.append(" AND "); //$NON-NLS-1$
+ builder.append(where);
+ }
+
+ builder.append(sqlOrderByIndex);
+ String sql = builder.toString();
+
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = chunkReader.getAccessor().getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = chunkReader.getAccessor().getDBTransaction().prepareStatement(sql, ReuseProbability.LOW);
ResultSet resultSet = null;
try
{
- StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
- if (where != null)
- {
- builder.append(" AND "); //$NON-NLS-1$
- builder.append(where);
- }
-
- builder.append(sqlOrderByIndex);
-
- String sql = builder.toString();
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.LOW);
idHandler.setCDOID(stmt, 1, chunkReader.getRevision().getID());
stmt.setInt(2, chunkReader.getRevision().getVersion());
stmt.setInt(3, chunkReader.getRevision().getVersion());
@@ -437,7 +435,7 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -482,14 +480,13 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
public void clearList(IDBStoreAccessor accessor, CDOID id, int oldVersion, int newVersion)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmtDeleteTemp = null;
- PreparedStatement stmtClear = null;
+ PreparedStatement stmtDeleteTemp = accessor.getDBTransaction().prepareStatement(sqlDeleteList,
+ ReuseProbability.HIGH);
+ PreparedStatement stmtClear = accessor.getDBTransaction().prepareStatement(sqlClearList, ReuseProbability.HIGH);
try
{
// delete temporary entries
- stmtDeleteTemp = statementCache.getPreparedStatement(sqlDeleteList, ReuseProbability.HIGH);
idHandler.setCDOID(stmtDeleteTemp, 1, id);
stmtDeleteTemp.setInt(2, newVersion);
@@ -500,7 +497,6 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
}
// clear rest of the list
- stmtClear = statementCache.getPreparedStatement(sqlClearList, ReuseProbability.HIGH);
stmtClear.setInt(1, newVersion);
idHandler.setCDOID(stmtClear, 2, id);
@@ -516,8 +512,8 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmtDeleteTemp);
- statementCache.releasePreparedStatement(stmtClear);
+ DBUtil.close(stmtClear);
+ DBUtil.close(stmtDeleteTemp);
}
}
@@ -766,13 +762,10 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
int endIndex)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlUpdateIndex, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
-
for (int index = startIndex; index <= endIndex; ++index)
{
if (TRACER.isEnabled())
@@ -829,7 +822,7 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -837,13 +830,10 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
int endIndex)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlUpdateIndex, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
-
for (int index = endIndex; index >= startIndex; --index)
{
if (TRACER.isEnabled())
@@ -900,27 +890,24 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
}
private void addEntry(IDBStoreAccessor accessor, CDOID id, int version, int index, Object value)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER.format("Adding value for feature() {0}.{1} index {2} of {3}v{4} : {5}", //$NON-NLS-1$
getContainingClass().getName(), getFeature().getName(), index, id, version, value);
}
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsertEntry, ReuseProbability.HIGH);
+
try
{
- stmt = statementCache.getPreparedStatement(sqlInsertEntry, ReuseProbability.HIGH);
-
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, version);
@@ -939,27 +926,24 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
private void removeEntry(IDBStoreAccessor accessor, CDOID id, int oldVersion, int newVersion, int index)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER.format("Removing value for feature() {0}.{1} index {2} of {3}v{4}", //$NON-NLS-1$
getContainingClass().getName(), getFeature().getName(), index, id, newVersion);
}
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlDeleteEntry, ReuseProbability.HIGH);
+
try
{
// try to delete a temporary entry first
- stmt = statementCache.getPreparedStatement(sqlDeleteEntry, ReuseProbability.HIGH);
-
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, index);
@@ -985,8 +969,8 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
else
{
// no temporary entry found, so mark the entry as removed
- statementCache.releasePreparedStatement(stmt);
- stmt = statementCache.getPreparedStatement(sqlRemoveEntry, ReuseProbability.HIGH);
+ DBUtil.close(stmt);
+ stmt = accessor.getDBTransaction().prepareStatement(sqlRemoveEntry, ReuseProbability.HIGH);
column = 1;
stmt.setInt(column++, newVersion);
@@ -1018,21 +1002,18 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
private Object getValue(IDBStoreAccessor accessor, CDOID id, int index)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlGetValue, ReuseProbability.HIGH);
Object result = null;
try
{
- stmt = statementCache.getPreparedStatement(sqlGetValue, ReuseProbability.HIGH);
-
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, index);
@@ -1055,7 +1036,7 @@ public class AuditListTableMappingWithRanges extends AbstractBasicListTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
return result;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMapping.java
index ead2cea41c..a36531dd31 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMapping.java
@@ -17,13 +17,12 @@ import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -88,12 +87,10 @@ public class BranchingFeatureMapTableMapping extends AbstractFeatureMapTableMapp
@Override
public void rawDeleted(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, int version)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlClear, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
stmt.setInt(2, branch.getID());
stmt.setInt(3, version);
@@ -105,7 +102,7 @@ public class BranchingFeatureMapTableMapping extends AbstractFeatureMapTableMapp
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMappingWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMappingWithRanges.java
index d2a522aca6..f4d6bee411 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMappingWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingFeatureMapTableMappingWithRanges.java
@@ -36,8 +36,6 @@ import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IListMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
@@ -50,6 +48,7 @@ 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.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
@@ -416,21 +415,19 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
.getName(), revision);
}
+ String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
+
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sql, ReuseProbability.HIGH);
ResultSet resultSet = null;
IStoreChunkReader baseReader = null;
try
{
- String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
-
CDOID id = revision.getID();
int branchID = revision.getBranch().getID();
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, branchID);
stmt.setInt(3, revision.getVersion());
@@ -490,7 +487,7 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
if (baseReader != null)
@@ -528,26 +525,23 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
getFeature().getName(), revision);
}
+ StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
+ if (where != null)
+ {
+ builder.append(" AND "); //$NON-NLS-1$
+ builder.append(where);
+ }
+
+ builder.append(sqlOrderByIndex);
+ String sql = builder.toString();
+
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = chunkReader.getAccessor().getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = chunkReader.getAccessor().getDBTransaction().prepareStatement(sql, ReuseProbability.LOW);
ResultSet resultSet = null;
-
IStoreChunkReader baseReader = null;
try
{
- StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
- if (where != null)
- {
- builder.append(" AND "); //$NON-NLS-1$
- builder.append(where);
- }
-
- builder.append(sqlOrderByIndex);
-
- String sql = builder.toString();
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.LOW);
idHandler.setCDOID(stmt, 1, revision.getID());
stmt.setInt(2, revision.getBranch().getID());
stmt.setInt(3, revision.getVersion());
@@ -646,7 +640,7 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
// now read missing values from base revision.
@@ -796,31 +790,28 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
public void clearList(IDBStoreAccessor accessor, CDOID id, int branchId, int oldVersion, int newVersion,
int lastIndex, long timestamp)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmtDeleteTemp = null;
- PreparedStatement stmtClear = null;
-
- try
+ // check for each index if the value exists in the current branch
+ for (int i = 0; i <= lastIndex; i++)
{
- // check for each index if the value exists in the current branch
- for (int i = 0; i <= lastIndex; i++)
+ if (getValue(accessor, id, branchId, i, false) == null)
{
- if (getValue(accessor, id, branchId, i, false) == null)
- {
- // if not, add a historic entry for missing ones.
- addHistoricEntry(accessor, id, branchId, 0, newVersion, i, getValueFromBase(accessor, id, branchId, i),
- timestamp);
- }
+ // if not, add a historic entry for missing ones.
+ addHistoricEntry(accessor, id, branchId, 0, newVersion, i, getValueFromBase(accessor, id, branchId, i),
+ timestamp);
}
+ }
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlClearList, ReuseProbability.HIGH);
+
+ try
+ {
// clear rest of the list
- stmtClear = statementCache.getPreparedStatement(sqlClearList, ReuseProbability.HIGH);
- stmtClear.setInt(1, newVersion);
- idHandler.setCDOID(stmtClear, 2, id);
- stmtClear.setInt(3, branchId);
+ stmt.setInt(1, newVersion);
+ idHandler.setCDOID(stmt, 2, id);
+ stmt.setInt(3, branchId);
- int result = DBUtil.update(stmtClear, false);
+ int result = DBUtil.update(stmt, false);
if (TRACER.isEnabled())
{
TRACER.format("ClearList result: {0}", result); //$NON-NLS-1$
@@ -832,8 +823,7 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
}
finally
{
- statementCache.releasePreparedStatement(stmtDeleteTemp);
- statementCache.releasePreparedStatement(stmtClear);
+ DBUtil.close(stmt);
}
}
@@ -1062,13 +1052,10 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
int startIndex, int endIndex)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlUpdateIndex, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
-
for (int index = startIndex; index <= endIndex; ++index)
{
if (TRACER.isEnabled())
@@ -1140,7 +1127,7 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -1148,12 +1135,10 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
int startIndex, int endIndex)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlUpdateIndex, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
for (int index = endIndex; index >= startIndex; --index)
{
if (TRACER.isEnabled())
@@ -1219,7 +1204,7 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
}
@@ -1227,25 +1212,22 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
private void addEntry(IDBStoreAccessor accessor, CDOID id, int branchId, int version, int index, Object value,
long timestamp)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER.format("Adding value for feature() {0}.{1} index {2} of {3}v{4} : {5}", //$NON-NLS-1$
getContainingClass().getName(), getFeature().getName(), index, id, version, value);
}
- try
- {
- FeatureMap.Entry entry = (FeatureMap.Entry)value;
- EStructuralFeature entryFeature = entry.getEStructuralFeature();
- CDOID tag = getTagByFeature(entryFeature, timestamp);
- String columnName = getColumnName(tag);
+ FeatureMap.Entry entry = (FeatureMap.Entry)value;
+ EStructuralFeature entryFeature = entry.getEStructuralFeature();
+ CDOID tag = getTagByFeature(entryFeature, timestamp);
+ String columnName = getColumnName(tag);
- stmt = statementCache.getPreparedStatement(sqlInsert, ReuseProbability.HIGH);
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsert, ReuseProbability.HIGH);
+ try
+ {
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, branchId);
@@ -1278,17 +1260,13 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
private void addHistoricEntry(IDBStoreAccessor accessor, CDOID id, int branchId, int versionAdded,
int versionRemoved, int index, Object value, long timestamp)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER.format(
@@ -1297,15 +1275,17 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
value);
}
- try
- {
- FeatureMap.Entry entry = (FeatureMap.Entry)value;
- EStructuralFeature entryFeature = entry.getEStructuralFeature();
- CDOID tag = getTagByFeature(entryFeature, timestamp);
- String columnName = getColumnName(tag);
+ FeatureMap.Entry entry = (FeatureMap.Entry)value;
+ EStructuralFeature entryFeature = entry.getEStructuralFeature();
+ CDOID tag = getTagByFeature(entryFeature, timestamp);
+ ITypeMapping typeMapping = getTypeMapping(tag);
+ String columnName = getColumnName(tag);
- stmt = statementCache.getPreparedStatement(sqlInsert, ReuseProbability.HIGH);
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsert, ReuseProbability.HIGH);
+ try
+ {
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, branchId);
@@ -1318,7 +1298,7 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
{
if (columnNames.get(i).equals(columnName))
{
- getTypeMapping(tag).setValue(stmt, column++, entry.getValue());
+ typeMapping.setValue(stmt, column++, entry.getValue());
}
else
{
@@ -1338,28 +1318,25 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
private void removeEntry(IDBStoreAccessor accessor, CDOID id, int branchId, int oldVersion, int newVersion,
int index, long timestamp)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER.format("Removing value for feature() {0}.{1} index {2} of {3}v{4}", //$NON-NLS-1$
getContainingClass().getName(), getFeature().getName(), index, id, newVersion);
}
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlDeleteEntry, ReuseProbability.HIGH);
+
try
{
// try to delete a temporary entry first
- stmt = statementCache.getPreparedStatement(sqlDeleteEntry, ReuseProbability.HIGH);
-
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, branchId);
@@ -1386,8 +1363,8 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
else
{
// no temporary entry found, so mark the entry as removed
- statementCache.releasePreparedStatement(stmt);
- stmt = statementCache.getPreparedStatement(sqlRemoveEntry, ReuseProbability.HIGH);
+ DBUtil.close(stmt);
+ stmt = accessor.getDBTransaction().prepareStatement(sqlRemoveEntry, ReuseProbability.HIGH);
column = 1;
stmt.setInt(column++, newVersion);
@@ -1428,21 +1405,18 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
private FeatureMap.Entry getValue(IDBStoreAccessor accessor, CDOID id, int branchId, int index, boolean getFromBase)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlGetValue, ReuseProbability.HIGH);
FeatureMap.Entry result = null;
try
{
- stmt = statementCache.getPreparedStatement(sqlGetValue, ReuseProbability.HIGH);
-
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, branchId);
@@ -1475,7 +1449,7 @@ public class BranchingFeatureMapTableMappingWithRanges extends AbstractBasicList
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
return result;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMapping.java
index 18fd444567..c51a1719db 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMapping.java
@@ -17,13 +17,12 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.emf.ecore.EClass;
@@ -93,12 +92,10 @@ public class BranchingListTableMapping extends AbstractListTableMapping
public void rawDeleted(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, int version)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlClear, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, branch.getID());
stmt.setInt(3, version);
@@ -110,7 +107,7 @@ public class BranchingListTableMapping extends AbstractListTableMapping
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java
index a029ae0ebe..79c0103604 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/BranchingListTableMappingWithRanges.java
@@ -37,8 +37,6 @@ import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IListMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
@@ -51,6 +49,7 @@ 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.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
@@ -322,17 +321,15 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
getFeature().getName(), revision);
}
+ String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
+
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sql, ReuseProbability.HIGH);
ResultSet resultSet = null;
+ ArrayList<Pair<Integer, Integer>> toReadFromBase = null; // list of chunks to be read from base revision
- // list of chunks to be read from base revision
- ArrayList<Pair<Integer, Integer>> toReadFromBase = null;
try
{
- String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, branchID);
stmt.setInt(3, revision.getVersion());
@@ -389,7 +386,7 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
// read missing values from base revision ...
@@ -434,36 +431,33 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
public final void readChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks, String where)
{
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Reading list chunk values for feature {0}.{1} of {2}", getContainingClass().getName(), //$NON-NLS-1$
+ getFeature().getName(), chunkReader.getRevision());
+ }
+
CDORevision revision = chunkReader.getRevision();
CDOID id = revision.getID();
int branchID = revision.getBranch().getID();
- if (TRACER.isEnabled())
+ StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
+ if (where != null)
{
- TRACER.format("Reading list chunk values for feature {0}.{1} of {2}", getContainingClass().getName(), //$NON-NLS-1$
- getFeature().getName(), revision);
+ builder.append(" AND "); //$NON-NLS-1$
+ builder.append(where);
}
+ builder.append(sqlOrderByIndex);
+ String sql = builder.toString();
+
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = chunkReader.getAccessor().getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = chunkReader.getAccessor().getDBTransaction().prepareStatement(sql, ReuseProbability.LOW);
ResultSet resultSet = null;
-
IStoreChunkReader baseReader = null;
try
{
- StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
- if (where != null)
- {
- builder.append(" AND "); //$NON-NLS-1$
- builder.append(where);
- }
-
- builder.append(sqlOrderByIndex);
-
- String sql = builder.toString();
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.LOW);
idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, branchID);
stmt.setInt(3, revision.getVersion());
@@ -572,7 +566,7 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
// now read missing values from base revision.
@@ -656,23 +650,21 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
*/
public void clearList(IDBStoreAccessor accessor, CDOID id, int branchId, int oldVersion, int newVersion, int lastIndex)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
- try
+ // check for each index if the value exists in the current branch
+ for (int i = 0; i <= lastIndex; i++)
{
- // check for each index if the value exists in the current branch
- for (int i = 0; i <= lastIndex; i++)
+ if (getValue(accessor, id, branchId, i, false) == null)
{
- if (getValue(accessor, id, branchId, i, false) == null)
- {
- // if not, add a historic entry for missing ones.
- addHistoricEntry(accessor, id, branchId, 0, newVersion, i, getValueFromBase(accessor, id, branchId, i));
- }
+ // if not, add a historic entry for missing ones.
+ addHistoricEntry(accessor, id, branchId, 0, newVersion, i, getValueFromBase(accessor, id, branchId, i));
}
+ }
+
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlClearList, ReuseProbability.HIGH);
+ try
+ {
// clear rest of the list
- stmt = statementCache.getPreparedStatement(sqlClearList, ReuseProbability.HIGH);
stmt.setInt(1, newVersion);
getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 2, id);
stmt.setInt(3, branchId);
@@ -689,7 +681,7 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -956,13 +948,10 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
int startIndex, int endIndex)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlUpdateIndex, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
-
for (int index = startIndex; index <= endIndex; ++index)
{
if (TRACER.isEnabled())
@@ -1035,7 +1024,7 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -1043,13 +1032,10 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
int startIndex, int endIndex)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlUpdateIndex, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
-
for (int index = endIndex; index >= startIndex; --index)
{
if (TRACER.isEnabled())
@@ -1122,27 +1108,24 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
}
private void addEntry(IDBStoreAccessor accessor, CDOID id, int branchId, int version, int index, Object value)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER.format("Adding value for feature {0}.{1} index {2} of {3}:{4}v{5} : {6}", //$NON-NLS-1$
getContainingClass().getName(), getFeature().getName(), index, id, branchId, version, value);
}
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsertEntry, ReuseProbability.HIGH);
+
try
{
- stmt = statementCache.getPreparedStatement(sqlInsertEntry, ReuseProbability.HIGH);
-
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, branchId);
@@ -1163,17 +1146,13 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
private void addHistoricEntry(IDBStoreAccessor accessor, CDOID id, int branchId, int versionAdded,
int versionRemoved, int index, Object value)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER.format(
@@ -1182,10 +1161,11 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
value);
}
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsertEntry, ReuseProbability.HIGH);
+
try
{
- stmt = statementCache.getPreparedStatement(sqlInsertEntry, ReuseProbability.HIGH);
-
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, branchId);
@@ -1206,27 +1186,24 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
private void removeEntry(IDBStoreAccessor accessor, CDOID id, int branchId, int oldVersion, int newVersion, int index)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
if (TRACER.isEnabled())
{
TRACER.format("Removing value for feature {0}.{1} index {2} of {3}:{4}v{5}", //$NON-NLS-1$
getContainingClass().getName(), getFeature().getName(), index, id, branchId, newVersion);
}
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlDeleteEntry, ReuseProbability.HIGH);
+
try
{
// Try to delete a temporary entry first
- stmt = statementCache.getPreparedStatement(sqlDeleteEntry, ReuseProbability.HIGH);
-
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, branchId);
@@ -1253,8 +1230,8 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
else
{
// no temporary entry found, so mark the entry as removed
- statementCache.releasePreparedStatement(stmt);
- stmt = statementCache.getPreparedStatement(sqlRemoveEntry, ReuseProbability.HIGH);
+ DBUtil.close(stmt);
+ stmt = accessor.getDBTransaction().prepareStatement(sqlRemoveEntry, ReuseProbability.HIGH);
column = 1;
stmt.setInt(column++, newVersion);
@@ -1296,7 +1273,7 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -1319,13 +1296,11 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
private Object getValue(IDBStoreAccessor accessor, CDOID id, int branchId, int index, boolean getFromBase)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlGetValue, ReuseProbability.HIGH);
Object result = null;
try
{
- stmt = statementCache.getPreparedStatement(sqlGetValue, ReuseProbability.HIGH);
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, branchId);
@@ -1356,7 +1331,7 @@ public class BranchingListTableMappingWithRanges extends AbstractBasicListTableM
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
return result;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
index 763582bd94..62c7fe829d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
@@ -33,8 +33,6 @@ import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.server.IStoreAccessor.QueryXRefsContext;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IClassMappingAuditSupport;
import org.eclipse.emf.cdo.server.db.mapping.IClassMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IListMappingDeltaSupport;
@@ -45,6 +43,7 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
@@ -204,7 +203,6 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement stmt = null;
try
@@ -212,14 +210,14 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
long timeStamp = revision.getTimeStamp();
if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE)
{
- stmt = statementCache.getPreparedStatement(sqlSelectAttributesByTime, ReuseProbability.MEDIUM);
+ stmt = accessor.getDBTransaction().prepareStatement(sqlSelectAttributesByTime, ReuseProbability.MEDIUM);
idHandler.setCDOID(stmt, 1, revision.getID());
stmt.setLong(2, timeStamp);
stmt.setLong(3, timeStamp);
}
else
{
- stmt = statementCache.getPreparedStatement(sqlSelectCurrentAttributes, ReuseProbability.HIGH);
+ stmt = accessor.getDBTransaction().prepareStatement(sqlSelectCurrentAttributes, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, revision.getID());
}
@@ -240,19 +238,18 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
public boolean readRevisionByVersion(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlSelectAttributesByVersion,
+ ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlSelectAttributesByVersion, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, revision.getID());
stmt.setInt(2, revision.getVersion());
@@ -273,7 +270,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -327,14 +324,11 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(builder.toString(), ReuseProbability.MEDIUM);
try
{
int column = 1;
-
- stmt = statementCache.getPreparedStatement(builder.toString(), ReuseProbability.MEDIUM);
idHandler.setCDOID(stmt, column++, folderId);
if (name != null)
@@ -358,7 +352,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
catch (SQLException ex)
{
- statementCache.releasePreparedStatement(stmt); // only release on error
+ DBUtil.close(stmt); // only release on error
throw new DBException(ex);
}
}
@@ -370,21 +364,18 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
TRACER.format("Created ObjectID Statement : {0}", sqlSelectAllObjectIDs); //$NON-NLS-1$
}
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- return statementCache.getPreparedStatement(sqlSelectAllObjectIDs, ReuseProbability.HIGH);
+ return accessor.getDBTransaction().prepareStatement(sqlSelectAllObjectIDs, ReuseProbability.HIGH);
}
@Override
protected final void writeValues(IDBStoreAccessor accessor, InternalCDORevision revision)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsertAttributes, ReuseProbability.HIGH);
try
{
int column = 1;
- stmt = statementCache.getPreparedStatement(sqlInsertAttributes, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, column++, revision.getID());
stmt.setInt(column++, revision.getVersion());
stmt.setLong(column++, revision.getTimeStamp());
@@ -437,7 +428,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -446,15 +437,11 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
OMMonitor mon)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsertAttributes, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlInsertAttributes, ReuseProbability.HIGH);
-
int column = 1;
-
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, -version); // cdo_version
stmt.setLong(column++, timeStamp); // cdo_created
@@ -496,19 +483,18 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@Override
protected void rawDeleteAttributes(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, int version, OMMonitor fork)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction()
+ .prepareStatement(sqlRawDeleteAttributes, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlRawDeleteAttributes, ReuseProbability.HIGH);
getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
stmt.setInt(2, version);
DBUtil.update(stmt, false);
@@ -519,7 +505,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -527,13 +513,10 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
protected void reviseOldRevision(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, long revised)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlReviseAttributes, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlReviseAttributes, ReuseProbability.HIGH);
-
stmt.setLong(1, revised);
idHandler.setCDOID(stmt, 2, id);
@@ -545,7 +528,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java
index 858509363c..218d75ed6e 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalBranchingClassMapping.java
@@ -37,8 +37,6 @@ import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStoreAccessor.QueryXRefsContext;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IClassMappingAuditSupport;
import org.eclipse.emf.cdo.server.db.mapping.IClassMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IListMapping;
@@ -54,6 +52,7 @@ 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.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
@@ -346,19 +345,17 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
- boolean success;
-
long timeStamp = revision.getTimeStamp();
int branchID = revision.getBranch().getID();
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = null;
+
try
{
if (timeStamp != CDOBranchPoint.UNSPECIFIED_DATE)
{
- stmt = statementCache.getPreparedStatement(sqlSelectAttributesByTime, ReuseProbability.MEDIUM);
+ stmt = accessor.getDBTransaction().prepareStatement(sqlSelectAttributesByTime, ReuseProbability.MEDIUM);
idHandler.setCDOID(stmt, 1, revision.getID());
stmt.setInt(2, branchID);
stmt.setLong(3, timeStamp);
@@ -366,7 +363,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
else
{
- stmt = statementCache.getPreparedStatement(sqlSelectCurrentAttributes, ReuseProbability.HIGH);
+ stmt = accessor.getDBTransaction().prepareStatement(sqlSelectCurrentAttributes, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, revision.getID());
stmt.setInt(2, branchID);
}
@@ -377,11 +374,11 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
// Read singleval-attribute table always (even without modeled attributes!)
- success = readValuesFromStatement(stmt, revision, accessor);
+ boolean success = readValuesFromStatement(stmt, revision, accessor);
// Read multival tables only if revision exists
if (success && revision.getVersion() >= CDOBranchVersion.FIRST_VERSION)
@@ -395,13 +392,12 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
public boolean readRevisionByVersion(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlSelectAttributesByVersion,
+ ReuseProbability.HIGH);
boolean success;
try
{
- stmt = statementCache.getPreparedStatement(sqlSelectAttributesByVersion, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, revision.getID());
stmt.setInt(2, revision.getBranch().getID());
stmt.setInt(3, revision.getVersion());
@@ -415,7 +411,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
// Read multival tables only if revision exists
@@ -481,14 +477,11 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(builder.toString(), ReuseProbability.MEDIUM);
try
{
int column = 1;
-
- stmt = statementCache.getPreparedStatement(builder.toString(), ReuseProbability.MEDIUM);
stmt.setInt(column++, branchID);
idHandler.setCDOID(stmt, column++, folderId);
@@ -513,7 +506,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
catch (SQLException ex)
{
- statementCache.releasePreparedStatement(stmt); // only release on error
+ DBUtil.close(stmt); // only release on error
throw new DBException(ex);
}
}
@@ -525,21 +518,18 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
TRACER.format("Created ObjectID Statement : {0}", sqlSelectAllObjectIDs); //$NON-NLS-1$
}
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- return statementCache.getPreparedStatement(sqlSelectAllObjectIDs, ReuseProbability.HIGH);
+ return accessor.getDBTransaction().prepareStatement(sqlSelectAllObjectIDs, ReuseProbability.HIGH);
}
@Override
protected final void writeValues(IDBStoreAccessor accessor, InternalCDORevision revision)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsertAttributes, ReuseProbability.HIGH);
try
{
int column = 1;
- stmt = statementCache.getPreparedStatement(sqlInsertAttributes, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, column++, revision.getID());
stmt.setInt(column++, revision.getVersion());
stmt.setInt(column++, revision.getBranch().getID());
@@ -592,7 +582,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -601,13 +591,10 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
OMMonitor mon)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsertAttributes, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlInsertAttributes, ReuseProbability.HIGH);
-
int column = 1;
idHandler.setCDOID(stmt, column++, id);
stmt.setInt(column++, -version); // cdo_version
@@ -651,20 +638,20 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@Override
protected void rawDeleteAttributes(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, int version, OMMonitor fork)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction()
+ .prepareStatement(sqlRawDeleteAttributes, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlRawDeleteAttributes, ReuseProbability.HIGH);
- getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
+ idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, branch.getID());
stmt.setInt(3, version);
DBUtil.update(stmt, false);
@@ -675,7 +662,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -683,17 +670,13 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
protected void reviseOldRevision(IDBStoreAccessor accessor, CDOID id, CDOBranch branch, long revised)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlReviseAttributes, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlReviseAttributes, ReuseProbability.HIGH);
-
stmt.setLong(1, revised);
idHandler.setCDOID(stmt, 2, id);
stmt.setInt(3, branch.getID());
-
DBUtil.update(stmt, false); // No row affected if old revision from other branch!
}
catch (SQLException e)
@@ -702,7 +685,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -855,14 +838,11 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
CDOBranchManager branchManager = repository.getBranchManager();
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(builder.toString(), ReuseProbability.LOW);
ResultSet resultSet = null;
try
{
- stmt = statementCache.getPreparedStatement(builder.toString(), ReuseProbability.LOW);
-
int column = 1;
if (branch != null)
{
@@ -907,7 +887,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -943,15 +923,12 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
}
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(builder.toString(), ReuseProbability.LOW);
ResultSet resultSet = null;
-
Set<CDOID> result = new HashSet<CDOID>();
try
{
- stmt = statementCache.getPreparedStatement(builder.toString(), ReuseProbability.LOW);
int column = 1;
for (CDOChangeSetSegment segment : segments)
{
@@ -976,7 +953,7 @@ public class HorizontalBranchingClassMapping extends AbstractHorizontalClassMapp
finally
{
DBUtil.close(resultSet);
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
index c6548b4d6b..912c554389 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
@@ -32,8 +32,6 @@ import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.server.IStoreAccessor.QueryXRefsContext;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IClassMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IListMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
@@ -43,6 +41,7 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.net4j.util.collection.Pair;
@@ -193,13 +192,11 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
protected void writeValues(IDBStoreAccessor accessor, InternalCDORevision revision)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsertAttributes, ReuseProbability.HIGH);
try
{
int column = 1;
- stmt = statementCache.getPreparedStatement(sqlInsertAttributes, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, column++, revision.getID());
stmt.setInt(column++, revision.getVersion());
stmt.setLong(column++, revision.getTimeStamp());
@@ -251,7 +248,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -262,8 +259,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
TRACER.format("Created ObjectID Statement : {0}", sqlSelectAllObjectIDs); //$NON-NLS-1$
}
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- return statementCache.getPreparedStatement(sqlSelectAllObjectIDs, ReuseProbability.HIGH);
+ return accessor.getDBTransaction().prepareStatement(sqlSelectAllObjectIDs, ReuseProbability.HIGH);
}
public PreparedStatement createResourceQueryStatement(IDBStoreAccessor accessor, CDOID folderId, String name,
@@ -304,14 +300,11 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(builder.toString(), ReuseProbability.MEDIUM);
try
{
int column = 1;
-
- stmt = statementCache.getPreparedStatement(builder.toString(), ReuseProbability.MEDIUM);
idHandler.setCDOID(stmt, column++, folderId);
if (name != null)
@@ -329,7 +322,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
catch (SQLException ex)
{
- statementCache.releasePreparedStatement(stmt); // only release on error
+ DBUtil.close(stmt); // only release on error
throw new DBException(ex);
}
}
@@ -343,12 +336,11 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlSelectCurrentAttributes,
+ ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlSelectCurrentAttributes, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, revision.getID());
// Read singleval-attribute table always (even without modeled attributes!)
@@ -368,7 +360,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -387,14 +379,11 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
OMMonitor monitor)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlDelete, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlDelete, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, id);
-
DBUtil.update(stmt, true);
}
catch (SQLException e)
@@ -403,7 +392,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -575,14 +564,12 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
private void updateAttributes()
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(buildUpdateStatement(),
+ ReuseProbability.MEDIUM);
try
{
int column = 1;
-
- stmt = statementCache.getPreparedStatement(buildUpdateStatement(), ReuseProbability.MEDIUM);
stmt.setInt(column++, newVersion);
stmt.setLong(column++, created);
if (updateContainer)
@@ -605,7 +592,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditFeatureMapTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditFeatureMapTableMapping.java
index d64c2cc547..3c8d537503 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditFeatureMapTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditFeatureMapTableMapping.java
@@ -28,14 +28,13 @@ import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IListMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.emf.ecore.EClass;
@@ -215,13 +214,12 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
*/
public void clearList(IDBStoreAccessor accessor, CDOID id)
{
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlClear, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
- getMappingStrategy().getStore().getIDHandler().setCDOID(stmt, 1, id);
+ idHandler.setCDOID(stmt, 1, id);
DBUtil.update(stmt, false);
}
catch (SQLException e)
@@ -230,7 +228,7 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -260,21 +258,17 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
private void insertValue(IDBStoreAccessor accessor, CDOID id, int index, Object value, long timestamp)
{
+ FeatureMap.Entry entry = (FeatureMap.Entry)value;
+ EStructuralFeature entryFeature = entry.getEStructuralFeature();
+ CDOID tag = getTagByFeature(entryFeature, timestamp);
+ ITypeMapping typeMapping = getTypeMapping(tag);
+ String columnName = getColumnName(tag);
+
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsert, ReuseProbability.HIGH);
try
{
- FeatureMap.Entry entry = (FeatureMap.Entry)value;
- EStructuralFeature entryFeature = entry.getEStructuralFeature();
- CDOID tag = getTagByFeature(entryFeature, timestamp);
- String columnName = getColumnName(tag);
-
- String sql = sqlInsert;
-
- stmt = statementCache.getPreparedStatement(sql, ReuseProbability.HIGH);
-
idHandler.setCDOID(stmt, 1, id);
int column = getKeyFields().length + 1;
@@ -282,7 +276,7 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
{
if (getColumnNames().get(i).equals(columnName))
{
- getTypeMapping(tag).setValue(stmt, column++, entry.getValue());
+ typeMapping.setValue(stmt, column++, entry.getValue());
}
else
{
@@ -292,7 +286,6 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
stmt.setInt(column++, index);
idHandler.setCDOID(stmt, column++, tag);
-
DBUtil.update(stmt, true);
}
catch (SQLException e)
@@ -301,7 +294,7 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -346,12 +339,10 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
private void updateOneIndex(IDBStoreAccessor accessor, CDOID id, int oldIndex, int newIndex)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlUpdateIndex, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
stmt.setInt(1, newIndex);
idHandler.setCDOID(stmt, 2, id);
stmt.setInt(3, oldIndex);
@@ -363,7 +354,7 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -390,14 +381,11 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
private void move1down(IDBStoreAccessor accessor, CDOID id, int index, int upperIndex)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(
+ upperIndex == UNBOUNDED_MOVE ? sqlMoveDown : sqlMoveDownWithLimit, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(upperIndex == UNBOUNDED_MOVE ? sqlMoveDown : sqlMoveDownWithLimit,
- ReuseProbability.HIGH);
-
idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, index);
if (upperIndex != UNBOUNDED_MOVE)
@@ -413,7 +401,7 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -424,13 +412,11 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
private void move1up(IDBStoreAccessor accessor, CDOID id, int index, int upperIndex)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(
+ upperIndex == UNBOUNDED_MOVE ? sqlMoveUp : sqlMoveUpWithLimit, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(upperIndex == UNBOUNDED_MOVE ? sqlMoveUp : sqlMoveUpWithLimit,
- ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, index);
if (upperIndex != UNBOUNDED_MOVE)
@@ -446,19 +432,17 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
private void deleteItem(IDBStoreAccessor accessor, CDOID id, int index)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlDeleteItem, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlDeleteItem, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, id);
stmt.setInt(2, index);
DBUtil.update(stmt, true);
@@ -469,7 +453,7 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -487,19 +471,17 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
*/
public void setListItem(IDBStoreAccessor accessor, CDOID id, int index, Object value, long timestamp)
{
- IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
-
FeatureMap.Entry entry = (FeatureMap.Entry)value;
EStructuralFeature entryFeature = entry.getEStructuralFeature();
CDOID tag = getTagByFeature(entryFeature, timestamp);
- String columnName = getColumnName(tag);
ITypeMapping mapping = getTypeMapping(tag);
+ String columnName = getColumnName(tag);
+
+ IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlUpdateValue, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlUpdateValue, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, tag);
int column = 2;
@@ -525,7 +507,7 @@ public class NonAuditFeatureMapTableMapping extends AbstractFeatureMapTableMappi
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java
index 34416d7e58..5f85862c16 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java
@@ -28,8 +28,6 @@ import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta;
import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IListMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
@@ -37,6 +35,7 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBPreparedStatement.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.om.trace.ContextTracer;
@@ -225,12 +224,10 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
public void clearList(IDBStoreAccessor accessor, CDOID id)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlClear, ReuseProbability.HIGH);
try
{
- stmt = statementCache.getPreparedStatement(sqlClear, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, id);
DBUtil.update(stmt, false);
}
@@ -240,7 +237,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -253,13 +250,12 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
public int getCurrentIndexOffset(IDBStoreAccessor accessor, CDOID id)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlReadCurrentIndexOffset,
+ ReuseProbability.HIGH);
ResultSet rset = null;
try
{
- stmt = statementCache.getPreparedStatement(sqlReadCurrentIndexOffset, ReuseProbability.HIGH);
idHandler.setCDOID(stmt, 1, id);
rset = stmt.executeQuery();
if (!rset.next())
@@ -278,7 +274,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
finally
{
DBUtil.close(rset);
- releaseStatement(accessor, stmt);
+ close(stmt);
}
}
@@ -316,7 +312,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
visitor.writeResultToDatabase(accessor, id);
}
- private void releaseStatement(IDBStoreAccessor accessor, PreparedStatement... stmts)
+ private void close(PreparedStatement... stmts)
{
Throwable t = null;
@@ -336,7 +332,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- accessor.getStatementCache().releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
}
@@ -702,7 +698,6 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
private void writeResultToDatabase(IDBStoreAccessor accessor, CDOID id)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement deleteStmt = null;
PreparedStatement moveStmt = null;
PreparedStatement setValueStmt = null;
@@ -740,7 +735,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
if (deleteStmt == null)
{
- deleteStmt = statementCache.getPreparedStatement(sqlDeleteItem, ReuseProbability.HIGH);
+ deleteStmt = accessor.getDBTransaction().prepareStatement(sqlDeleteItem, ReuseProbability.HIGH);
idHandler.setCDOID(deleteStmt, 1, id);
}
@@ -762,7 +757,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
if (moveStmt == null)
{
- moveStmt = statementCache.getPreparedStatement(sqlUpdateIndex, ReuseProbability.HIGH);
+ moveStmt = accessor.getDBTransaction().prepareStatement(sqlUpdateIndex, ReuseProbability.HIGH);
idHandler.setCDOID(moveStmt, 2, id);
}
@@ -830,7 +825,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
if (setValueStmt == null)
{
- setValueStmt = statementCache.getPreparedStatement(sqlUpdateValue, ReuseProbability.HIGH);
+ setValueStmt = accessor.getDBTransaction().prepareStatement(sqlUpdateValue, ReuseProbability.HIGH);
idHandler.setCDOID(setValueStmt, 2, id);
}
@@ -852,7 +847,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
if (insertStmt == null)
{
- insertStmt = statementCache.getPreparedStatement(sqlInsertValue, ReuseProbability.HIGH);
+ insertStmt = accessor.getDBTransaction().prepareStatement(sqlInsertValue, ReuseProbability.HIGH);
idHandler.setCDOID(insertStmt, 1, id);
}
@@ -904,7 +899,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- releaseStatement(accessor, deleteStmt, moveStmt, insertStmt, setValueStmt);
+ close(deleteStmt, moveStmt, insertStmt, setValueStmt);
}
}
@@ -998,13 +993,11 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
*/
ListIterator<ShiftOperation> operationIt = shiftOperations.listIterator();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
PreparedStatement shiftDownStmt = null;
int operationCounter = 0;
try
{
-
while (operationIt.hasNext())
{
ShiftOperation operation = operationIt.next();
@@ -1012,7 +1005,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
{
if (shiftDownStmt == null)
{
- shiftDownStmt = statementCache.getPreparedStatement(sqlShiftDownIndex, ReuseProbability.HIGH);
+ shiftDownStmt = accessor.getDBTransaction().prepareStatement(sqlShiftDownIndex, ReuseProbability.HIGH);
idHandler.setCDOID(shiftDownStmt, 2, id);
}
@@ -1038,7 +1031,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- releaseStatement(accessor, shiftDownStmt);
+ close(shiftDownStmt);
}
PreparedStatement shiftUpStmt = null;
@@ -1052,7 +1045,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
ShiftOperation operation = operationIt.previous();
if (shiftUpStmt == null)
{
- shiftUpStmt = statementCache.getPreparedStatement(sqlShiftUpIndex, ReuseProbability.HIGH);
+ shiftUpStmt = accessor.getDBTransaction().prepareStatement(sqlShiftUpIndex, ReuseProbability.HIGH);
idHandler.setCDOID(shiftUpStmt, 2, id);
}
@@ -1075,7 +1068,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- releaseStatement(accessor, shiftUpStmt);
+ close(shiftUpStmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeTable.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeTable.java
index 4d09e4f466..6b75d7cf5c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeTable.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeTable.java
@@ -20,8 +20,6 @@ import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
-import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.ReuseProbability;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.net4j.db.DBException;
@@ -29,6 +27,7 @@ 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.ReuseProbability;
import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
@@ -64,12 +63,10 @@ public class ObjectTypeTable extends AbstractObjectTypeMapper implements IMappin
public final CDOClassifierRef getObjectType(IDBStoreAccessor accessor, CDOID id)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlSelect, ReuseProbability.MAX);
try
{
- stmt = statementCache.getPreparedStatement(sqlSelect, ReuseProbability.MAX);
idHandler.setCDOID(stmt, 1, id);
if (DBUtil.isTracerEnabled())
@@ -99,7 +96,7 @@ public class ObjectTypeTable extends AbstractObjectTypeMapper implements IMappin
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
@@ -107,12 +104,10 @@ public class ObjectTypeTable extends AbstractObjectTypeMapper implements IMappin
{
IDBStore store = getMappingStrategy().getStore();
IIDHandler idHandler = store.getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlInsert, ReuseProbability.MAX);
try
{
- stmt = statementCache.getPreparedStatement(sqlInsert, ReuseProbability.MAX);
idHandler.setCDOID(stmt, 1, id);
idHandler.setCDOID(stmt, 2, getMetaDataManager().getMetaID(type, timeStamp));
stmt.setLong(3, timeStamp);
@@ -139,19 +134,17 @@ public class ObjectTypeTable extends AbstractObjectTypeMapper implements IMappin
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
public final void removeObjectType(IDBStoreAccessor accessor, CDOID id)
{
IIDHandler idHandler = getMappingStrategy().getStore().getIDHandler();
- IPreparedStatementCache statementCache = accessor.getStatementCache();
- PreparedStatement stmt = null;
+ PreparedStatement stmt = accessor.getDBTransaction().prepareStatement(sqlDelete, ReuseProbability.MAX);
try
{
- stmt = statementCache.getPreparedStatement(sqlDelete, ReuseProbability.MAX);
idHandler.setCDOID(stmt, 1, id);
if (DBUtil.isTracerEnabled())
@@ -171,7 +164,7 @@ public class ObjectTypeTable extends AbstractObjectTypeMapper implements IMappin
}
finally
{
- statementCache.releasePreparedStatement(stmt);
+ DBUtil.close(stmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractSyncingTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractSyncingTest.java
index 84c4272353..59975255d4 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractSyncingTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractSyncingTest.java
@@ -149,24 +149,28 @@ public abstract class AbstractSyncingTest extends AbstractCDOTest
protected static void checkRevision(EObject object, InternalRepository repository, String location)
{
+ CDORevision revision = CDOUtil.getCDOObject(object).cdoRevision();
+ CDOBranch branch = repository.getBranchManager().getBranch(revision.getBranch().getID());
+
// Check if revision arrived in cache
- checkRevision(object, repository.getRevisionManager().getCache().getAllRevisions(), location + " cache");
+ checkRevision(revision, branch, repository.getRevisionManager().getCache().getAllRevisions(), location + " cache");
// Check if revision arrived in store
InternalStore store = repository.getStore();
if (store instanceof IMEMStore)
{
- checkRevision(object, ((IMEMStore)store).getAllRevisions(), location + " store");
+ checkRevision(revision, branch, ((IMEMStore)store).getAllRevisions(), location + " store");
}
}
- protected static void checkRevision(EObject object, Map<CDOBranch, List<CDORevision>> allRevisions, String location)
+ protected static void checkRevision(CDORevision revision, CDOBranch branch,
+ Map<CDOBranch, List<CDORevision>> allRevisions, String location)
{
- CDORevision revision = CDOUtil.getCDOObject(object).cdoRevision();
- List<CDORevision> revisions = allRevisions.get(revision.getBranch());
+ List<CDORevision> revisions = allRevisions.get(branch);
for (CDORevision rev : revisions)
{
- if (revision.equals(rev))
+ if (rev.getID() == revision.getID() && rev.getBranch().getID() == revision.getBranch().getID()
+ && rev.getVersion() == revision.getVersion())
{
return;
}
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java
index 09f7973580..0d15706d0d 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBDatabase.java
@@ -80,8 +80,6 @@ public final class DBDatabase extends SetContainer<IDBTransaction> implements ID
public DBSchemaTransaction openSchemaTransaction()
{
- beginSchemaAccess(true);
-
DBSchemaTransaction schemaTransaction = new DBSchemaTransaction(this);
this.schemaTransaction = schemaTransaction;
return schemaTransaction;
@@ -91,6 +89,8 @@ public final class DBDatabase extends SetContainer<IDBTransaction> implements ID
{
try
{
+ beginSchemaAccess(true);
+
for (IDBTransaction transaction : getTransactions())
{
((DBTransaction)transaction).invalidateStatementCache();
@@ -194,6 +194,10 @@ public final class DBDatabase extends SetContainer<IDBTransaction> implements ID
ReadSchemaAccess readSchemaAccess = (ReadSchemaAccess)schemaAccess;
readSchemaAccess.incrementReaders();
}
+ else
+ {
+ schemaAccess = null;
+ }
}
if (schemaAccess == null)
@@ -256,7 +260,7 @@ public final class DBDatabase extends SetContainer<IDBTransaction> implements ID
*/
private final class ReadSchemaAccess implements SchemaAccess
{
- private int readers;
+ private int readers = 1;
public void incrementReaders()
{

Back to the top