summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2009-04-22 08:36:17 (EDT)
committerStefan Winkler2009-04-22 08:36:17 (EDT)
commit3d096f78a916fef8b9bd28450693a199826fb4cb (patch)
tree95f1960f434c3e3463a8322d6ec10088a0b85a1c
parent0f1a10584c8fd62f98331d479113568f97467d35 (diff)
downloadcdo-3d096f78a916fef8b9bd28450693a199826fb4cb.zip
cdo-3d096f78a916fef8b9bd28450693a199826fb4cb.tar.gz
cdo-3d096f78a916fef8b9bd28450693a199826fb4cb.tar.bz2
Statement caching implemented.
All features required for the merge are now implemented.
-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.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IPreparedStatementCache.java49
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AbstractPreparedStatementCache.java29
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java68
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NullPreparedStatementCache.java50
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/SmartPreparedStatementCache.java256
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java17
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java51
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java43
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java33
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeCache.java16
14 files changed, 545 insertions, 103 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 5957710..376ada9 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
@@ -4,10 +4,10 @@
* 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
+ * Stefan Winkler - 271444: [DB] Multiple refactorings
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*
*/
@@ -17,6 +17,7 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
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.HorizontalNonAuditMappingStrategy;
@@ -263,4 +264,14 @@ public final class CDODBUtil
}
}
+ /**
+ * TODO make this configurable
+ *
+ * @since 2.0
+ */
+ public static IPreparedStatementCache createStatementCache()
+ {
+ return new SmartPreparedStatementCache(200);
+ }
+
}
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 0a024cc..a9a067d 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
@@ -4,7 +4,7 @@
* 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
*/
@@ -23,4 +23,9 @@ public interface IDBStoreAccessor extends IStoreAccessor
public IDBStore getStore();
public Connection getConnection();
+
+ /**
+ * @since 2.0
+ */
+ 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
new file mode 100644
index 0000000..978ac2b
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IPreparedStatementCache.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright (c) 2004 - 2009 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 https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
+ */
+package org.eclipse.emf.cdo.server.db;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+
+/**
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @author Stefan Winkler
+ * @since 2.0
+ */
+public interface IPreparedStatementCache
+{
+ public void setConnection(Connection connection);
+
+ public PreparedStatement getPreparedStatement(String sql, PSReuseProbability reuseProbability);
+
+ public void releasePreparedStatement(PreparedStatement ps);
+
+ /**
+ * An enum for the degree of probability to which a prepared statement is reused later on. This is used for managing
+ * the cache of prepared statements so that statements which are more likely reused are kept in the cache longer. Rule
+ * of thumb:
+ * <ul>
+ * <li>For global statements which are used regularly (such as lookup object in cdo_objects) use {@value #MAX}.
+ * <li>For constant object-specific statements which are used regularly use {@value #HIGH}.
+ * <li>For object-specific statements which are assembled from constants which are used regularly use {@value #MEDIUM}.
+ * <li>For all other dynamic statements, like queries, use {@value #LOW}
+ * </ul>
+ *
+ * @author Stefan Winkler
+ * @since 2.0
+ */
+ public static enum PSReuseProbability
+ {
+ MAX, HIGH, MEDIUM, LOW;
+ }
+}
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
new file mode 100644
index 0000000..a17ed96
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AbstractPreparedStatementCache.java
@@ -0,0 +1,29 @@
+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;
+
+public abstract class AbstractPreparedStatementCache extends Lifecycle implements IPreparedStatementCache
+{
+ private Connection connection = null;
+
+ public final Connection getConnection()
+ {
+ return connection;
+ }
+
+ public final void setConnection(Connection connection)
+ {
+ checkInactive();
+ this.connection = connection;
+ }
+
+ @Override
+ protected void doBeforeActivate()
+ {
+ checkNull(connection, "Must have valid connection to start.");
+ }
+}
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 9d34133..43ece40 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
@@ -22,9 +22,11 @@ import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.ITransaction;
+import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
-import org.eclipse.emf.cdo.server.db.mapping.IClassMappingAuditSupport;
+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.IClassMappingAuditSupport;
import org.eclipse.emf.cdo.server.db.mapping.IClassMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
@@ -37,6 +39,7 @@ import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
import org.eclipse.net4j.util.collection.CloseableIterator;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
import org.eclipse.net4j.util.om.monitor.ProgressDistributable;
import org.eclipse.net4j.util.om.monitor.ProgressDistributor;
@@ -49,7 +52,10 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import java.sql.Connection;
import java.sql.SQLException;
+import java.sql.Statement;
import java.util.Collection;
+import java.util.Timer;
+import java.util.TimerTask;
/**
* @author Eike Stepper
@@ -60,6 +66,10 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
private Connection connection = null;
+ private IPreparedStatementCache statementCache = null;
+
+ private Timer connectionKeepAliveTimer = null;
+
@ExcludeFromDump
@SuppressWarnings("unchecked")
private final ProgressDistributable<CommitContext>[] ops = ProgressDistributor.array( //
@@ -95,6 +105,11 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return (DBStore)super.getStore();
}
+ public IPreparedStatementCache getStatementCache()
+ {
+ return statementCache;
+ }
+
public DBStoreChunkReader createChunkReader(InternalCDORevision revision, EStructuralFeature feature)
{
return new DBStoreChunkReader(this, revision, feature);
@@ -297,7 +312,8 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
protected void writeRevisionDelta(InternalCDORevisionDelta delta, long created, OMMonitor monitor)
{
EClass eClass = getObjectType(delta.getID());
- IClassMappingDeltaSupport mapping = (IClassMappingDeltaSupport)getStore().getMappingStrategy().getClassMapping(eClass);
+ IClassMappingDeltaSupport mapping = (IClassMappingDeltaSupport)getStore().getMappingStrategy().getClassMapping(
+ eClass);
mapping.writeRevisionDelta(this, delta, created, monitor);
}
@@ -380,9 +396,6 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
try
{
getConnection().commit();
-
- // CDODBUtil.sqlDump(getStore().getDBConnectionProvider(), "select * from CDOResourceFolder");
- // CDODBUtil.sqlDump(getStore().getDBConnectionProvider(), "select * from CDOResource");
}
catch (SQLException ex)
{
@@ -417,11 +430,26 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
protected void doActivate() throws Exception
{
connection = getStore().getDBConnectionProvider().getConnection();
+
+ connectionKeepAliveTimer = new Timer("Connection-Keep-Alive-" + toString());
+ connectionKeepAliveTimer.schedule(new ConnectionKeepAliveTask(), ConnectionKeepAliveTask.EXECUTION_PERIOD,
+ ConnectionKeepAliveTask.EXECUTION_PERIOD);
+
+ // TODO - make this configurable?
+ statementCache = CDODBUtil.createStatementCache();
+ statementCache.setConnection(connection);
+
+ LifecycleUtil.activate(statementCache);
}
@Override
protected void doDeactivate() throws Exception
{
+ LifecycleUtil.deactivate(statementCache);
+
+ connectionKeepAliveTimer.cancel();
+ connectionKeepAliveTimer = null;
+
DBUtil.close(connection);
connection = null;
}
@@ -435,7 +463,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
@Override
protected void doUnpassivate() throws Exception
{
- // TODO Check if connection is still valid.
+ // do nothing
}
public EPackage[] loadPackageUnit(InternalCDOPackageUnit packageUnit)
@@ -461,4 +489,32 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
monitor.done();
}
}
+
+ private class ConnectionKeepAliveTask extends TimerTask
+ {
+ public static final long EXECUTION_PERIOD = 1000 * 60 * 60 * 4; // 4 hours
+
+ @Override
+ public void run()
+ {
+ Statement stmt = null;
+ try
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("DB connection keep-alive task activated.");
+ }
+ stmt = connection.createStatement();
+ stmt.executeQuery("SELECT 1 FROM " + CDODBSchema.REPOSITORY);
+ }
+ catch (SQLException e)
+ {
+ OM.LOG.error("DB connection keep-alive failed.", e);
+ }
+ finally
+ {
+ 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
new file mode 100644
index 0000000..ff0c0d8
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NullPreparedStatementCache.java
@@ -0,0 +1,50 @@
+package org.eclipse.emf.cdo.server.internal.db;
+
+import org.eclipse.emf.cdo.server.db.IPreparedStatementCache;
+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;
+
+public class NullPreparedStatementCache extends AbstractPreparedStatementCache implements IPreparedStatementCache
+{
+ HashSet<PreparedStatement> allocatedStatements = new HashSet<PreparedStatement>();
+
+ public PreparedStatement getPreparedStatement(String sql, PSReuseProbability 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);
+ }
+
+ @Override
+ protected void doBeforeDeactivate() throws Exception
+ {
+ if (!allocatedStatements.isEmpty())
+ {
+ OM.LOG.warn("Possible Leak Detected:");
+ for (PreparedStatement ps : allocatedStatements)
+ {
+ OM.LOG.warn("- " + ps.toString());
+ }
+ 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
new file mode 100644
index 0000000..7ad6a7c
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/SmartPreparedStatementCache.java
@@ -0,0 +1,256 @@
+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.util.ImplementationError;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.HashMap;
+
+public class SmartPreparedStatementCache extends AbstractPreparedStatementCache
+{
+ private Cache cache;
+
+ private HashMap<PreparedStatement, CachedPreparedStatement> checkedOut = new HashMap<PreparedStatement, CachedPreparedStatement>();
+
+ public SmartPreparedStatementCache(int capacity)
+ {
+ cache = new Cache(capacity);
+ }
+
+ public PreparedStatement getPreparedStatement(String sql, PSReuseProbability reuseProbability)
+ {
+ CachedPreparedStatement cachedStatement = cache.remove(sql);
+
+ if (cachedStatement == null)
+ {
+ cachedStatement = createCachedPreparedStatement(sql, reuseProbability);
+ }
+
+ PreparedStatement result = cachedStatement.getPreparedStatement();
+ checkedOut.put(result, cachedStatement);
+
+ return result;
+ }
+
+ private CachedPreparedStatement createCachedPreparedStatement(String sql, PSReuseProbability reuseProbability)
+ {
+ PreparedStatement stmt;
+ try
+ {
+ stmt = getConnection().prepareStatement(sql);
+ CachedPreparedStatement result = new CachedPreparedStatement(sql, reuseProbability, stmt);
+ return result;
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ }
+
+ public void releasePreparedStatement(PreparedStatement ps)
+ {
+ CachedPreparedStatement cachedStatement = checkedOut.remove(ps);
+ cache.put(cachedStatement);
+ }
+
+ @Override
+ protected void doBeforeDeactivate() throws Exception
+ {
+ if (!checkedOut.isEmpty())
+ {
+ OM.LOG.warn("Statement leak detected.");
+ }
+ }
+
+ private class Cache
+ {
+ private CacheList lists[];
+
+ private HashMap<String, CachedPreparedStatement> lookup;
+
+ private int capacity;
+
+ public Cache(int capacity)
+ {
+ this.capacity = capacity;
+
+ lookup = new HashMap<String, CachedPreparedStatement>(capacity);
+
+ lists = new CacheList[PSReuseProbability.values().length];
+ for (PSReuseProbability prob : PSReuseProbability.values())
+ {
+ lists[prob.ordinal()] = new CacheList();
+ }
+ }
+
+ public void put(CachedPreparedStatement cachedStatement)
+ {
+ // refresh age
+ cachedStatement.touch();
+
+ // put into appripriate list
+ lists[cachedStatement.getProbability().ordinal()].add(cachedStatement);
+
+ // put into lookup table
+ if (lookup.put(cachedStatement.getSql(), cachedStatement) != null)
+ {
+ throw new ImplementationError(cachedStatement.getSql() + " already in cache.");
+ }
+
+ // handle capacity overflow
+ if (lookup.size() > capacity)
+ {
+ evictOne();
+ }
+ }
+
+ private void evictOne()
+ {
+ long maxAge = -1;
+ int ordinal = -1;
+
+ for (PSReuseProbability prob : PSReuseProbability.values())
+ {
+ if (!lists[prob.ordinal()].isEmpty())
+ {
+ long age = lists[prob.ordinal()].tail().getAge();
+ if (maxAge < age)
+ {
+ maxAge = age;
+ ordinal = prob.ordinal();
+ }
+ }
+ }
+
+ remove(lists[ordinal].tail().getSql());
+ }
+
+ public CachedPreparedStatement remove(String sql)
+ {
+ CachedPreparedStatement result = lookup.remove(sql);
+ if (result == null)
+ {
+ return null;
+ }
+ else
+ {
+ lists[result.getProbability().ordinal()].remove(result);
+ return result;
+ }
+ }
+
+ private class CacheList
+ {
+ private CachedPreparedStatement first = null;
+
+ private CachedPreparedStatement last = null;
+
+ public CacheList()
+ {
+ };
+
+ public void add(CachedPreparedStatement s)
+ {
+ if (first == null)
+ {
+ first = s;
+ last = s;
+ s.previous = null;
+ s.next = null;
+ }
+ else
+ {
+ first.previous = s;
+ s.next = first;
+ first = s;
+ }
+ }
+
+ public void remove(CachedPreparedStatement s)
+ {
+ if (s == first)
+ {
+ first = s.next;
+ }
+ if (s.next != null)
+ {
+ s.next.previous = s.previous;
+ }
+ if (s == last)
+ {
+ last = s.previous;
+ }
+ if (s.previous != null)
+ {
+ s.previous.next = s.next;
+ }
+
+ s.previous = null;
+ s.next = null;
+ }
+
+ public CachedPreparedStatement tail()
+ {
+ return last;
+ }
+
+ public boolean isEmpty()
+ {
+ return first == null;
+ }
+ }
+ };
+
+ private class CachedPreparedStatement
+ {
+ private long timeStamp;
+
+ private String sql;
+
+ private PSReuseProbability probability;
+
+ private PreparedStatement statement;
+
+ // DL fields
+ CachedPreparedStatement previous = null;
+
+ CachedPreparedStatement next = null;
+
+ public CachedPreparedStatement(String sql, PSReuseProbability prob, PreparedStatement stmt)
+ {
+ this.sql = sql;
+ probability = prob;
+ statement = stmt;
+ timeStamp = System.currentTimeMillis();
+ }
+
+ public PreparedStatement getPreparedStatement()
+ {
+ return statement;
+ }
+
+ public long getAge()
+ {
+ long currentTime = System.currentTimeMillis();
+ return (currentTime - timeStamp) * probability.ordinal();
+ }
+
+ public void touch()
+ {
+ timeStamp = System.currentTimeMillis();
+ }
+
+ public String getSql()
+ {
+ return sql;
+ }
+
+ public PSReuseProbability getProbability()
+ {
+ return probability;
+ }
+ }
+}
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 903f61a..18b7cce 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
@@ -4,11 +4,11 @@
* 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 - major refactoring
- * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db.mapping;
@@ -188,7 +188,7 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
catch (SQLException ex)
{
DBUtil.close(rset); // only on error
- DBUtil.close(currentStatement); // only on error
+ getAccessor().getStatementCache().releasePreparedStatement(currentStatement);
throw new DBException(ex);
}
}
@@ -199,7 +199,7 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
protected void closeCurrentResultSet()
{
super.closeCurrentResultSet();
- DBUtil.close(currentStatement);
+ getAccessor().getStatementCache().releasePreparedStatement(currentStatement);
currentStatement = null;
}
};
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 1097c65..26bd301 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
@@ -4,10 +4,10 @@
* 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 https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
@@ -184,7 +184,7 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
finally
{
DBUtil.close(rset);
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(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 5bce265..8736f9b 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
@@ -17,6 +17,7 @@ import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
+import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.PSReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IListMapping;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.db.mapping.ITypeMapping;
@@ -253,7 +254,7 @@ public abstract class AbstractListTableMapping implements IListMapping
{
String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
- pstmt = accessor.getConnection().prepareStatement(sql);
+ pstmt = accessor.getStatementCache().getPreparedStatement(sql, PSReuseProbability.HIGH);
setKeyFields(pstmt, revision);
@@ -290,7 +291,7 @@ public abstract class AbstractListTableMapping implements IListMapping
finally
{
DBUtil.close(resultSet);
- DBUtil.close(pstmt);
+ accessor.getStatementCache().releasePreparedStatement(pstmt);
}
if (TRACER.isEnabled())
@@ -316,7 +317,7 @@ public abstract class AbstractListTableMapping implements IListMapping
try
{
- pstmt = accessor.getConnection().prepareStatement(sqlGetListLastIndex);
+ pstmt = accessor.getStatementCache().getPreparedStatement(sqlGetListLastIndex, PSReuseProbability.HIGH);
setKeyFields(pstmt, revision);
@@ -352,7 +353,7 @@ public abstract class AbstractListTableMapping implements IListMapping
finally
{
DBUtil.close(resultSet);
- DBUtil.close(pstmt);
+ accessor.getStatementCache().releasePreparedStatement(pstmt);
}
}
@@ -378,7 +379,7 @@ public abstract class AbstractListTableMapping implements IListMapping
String sql = builder.toString();
- pstmt = chunkReader.getAccessor().getConnection().prepareStatement(sql);
+ pstmt = chunkReader.getAccessor().getStatementCache().getPreparedStatement(sql, PSReuseProbability.LOW);
setKeyFields(pstmt, chunkReader.getRevision());
@@ -441,7 +442,7 @@ public abstract class AbstractListTableMapping implements IListMapping
finally
{
DBUtil.close(resultSet);
- DBUtil.close(pstmt);
+ chunkReader.getAccessor().getStatementCache().releasePreparedStatement(pstmt);
}
}
@@ -468,7 +469,7 @@ public abstract class AbstractListTableMapping implements IListMapping
try
{
- stmt = accessor.getConnection().prepareStatement(sqlInsertEntry);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlInsertEntry, PSReuseProbability.HIGH);
setKeyFields(stmt, revision);
int stmtIndex = getKeyFields().length + 1;
@@ -483,7 +484,7 @@ public abstract class AbstractListTableMapping implements IListMapping
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
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 fb0eba0..cb9e9f7 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
@@ -4,7 +4,7 @@
* 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 - major refactoring
@@ -17,15 +17,15 @@ import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
-import org.eclipse.emf.cdo.server.db.mapping.IClassMappingAuditSupport;
+import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.PSReuseProbability;
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.ITypeMapping;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
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.util.ImplementationError;
import org.eclipse.net4j.util.om.trace.ContextTracer;
@@ -42,7 +42,8 @@ import java.sql.SQLException;
* @author Stefan Winkler
* @since 2.0
*/
-public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping implements IClassMapping, IClassMappingAuditSupport
+public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping implements IClassMapping,
+ IClassMappingAuditSupport
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, HorizontalAuditClassMapping.class);
@@ -162,8 +163,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
PreparedStatement pstmt = null;
try
{
- // TODO add caching
- pstmt = accessor.getConnection().prepareStatement(sqlSelectAttributesByTime);
+ pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectAttributesByTime, PSReuseProbability.MEDIUM);
pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
pstmt.setLong(2, timeStamp);
pstmt.setLong(3, timeStamp);
@@ -185,7 +185,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
finally
{
- DBUtil.close(pstmt);
+ accessor.getStatementCache().releasePreparedStatement(pstmt);
}
}
@@ -195,8 +195,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
PreparedStatement pstmt = null;
try
{
- // TODO add caching
- pstmt = accessor.getConnection().prepareStatement(sqlSelectAttributesByVersion);
+ pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectAttributesByVersion, PSReuseProbability.HIGH);
pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
pstmt.setInt(2, version);
@@ -217,7 +216,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
finally
{
- DBUtil.close(pstmt);
+ accessor.getStatementCache().releasePreparedStatement(pstmt);
}
}
@@ -272,7 +271,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
{
int idx = 1;
- pstmt = accessor.getConnection().prepareStatement(builder.toString());
+ pstmt = accessor.getStatementCache().getPreparedStatement(builder.toString(), PSReuseProbability.MEDIUM);
pstmt.setLong(idx++, CDOIDUtil.getLong(folderId));
if (name != null)
@@ -296,26 +295,19 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
catch (SQLException ex)
{
- DBUtil.close(pstmt); // only close on error
+ accessor.getStatementCache().releasePreparedStatement(pstmt); // only release on error
throw new DBException(ex);
}
}
public PreparedStatement createObjectIdStatement(IDBStoreAccessor accessor)
{
- try
+ if (TRACER.isEnabled())
{
- if (TRACER.isEnabled())
- {
- TRACER.format("Created ObjectID Statement : {0}", sqlSelectAllObjectIds);
- }
-
- return accessor.getConnection().prepareStatement(sqlSelectAllObjectIds);
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
+ TRACER.format("Created ObjectID Statement : {0}", sqlSelectAllObjectIds);
}
+
+ return accessor.getStatementCache().getPreparedStatement(sqlSelectAllObjectIds, PSReuseProbability.HIGH);
}
public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
@@ -323,8 +315,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
PreparedStatement pstmt = null;
try
{
- // TODO add caching
- pstmt = accessor.getConnection().prepareStatement(sqlSelectCurrentAttributes);
+ pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectCurrentAttributes, PSReuseProbability.HIGH);
pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
// Read singleval-attribute table always (even without modeled attributes!)
@@ -344,7 +335,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
finally
{
- DBUtil.close(pstmt);
+ accessor.getStatementCache().releasePreparedStatement(pstmt);
}
}
@@ -355,7 +346,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
try
{
- stmt = accessor.getConnection().prepareStatement(sqlInsertAttributes);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlInsertAttributes, PSReuseProbability.HIGH);
int col = 1;
@@ -381,7 +372,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
@@ -392,7 +383,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
try
{
- stmt = accessor.getConnection().prepareStatement(sqlReviseAttributes);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlReviseAttributes, PSReuseProbability.HIGH);
stmt.setLong(1, revised);
stmt.setLong(2, CDOIDUtil.getLong(id));
@@ -405,7 +396,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(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 764bc06..8bd8898 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
@@ -27,6 +27,7 @@ import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta;
import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
+import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.PSReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IClassMapping;
import org.eclipse.emf.cdo.server.db.mapping.IClassMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IListMappingDeltaSupport;
@@ -37,7 +38,6 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
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.util.ImplementationError;
import org.eclipse.net4j.util.collection.Pair;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
@@ -183,7 +183,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
try
{
- stmt = accessor.getConnection().prepareStatement(sqlInsertAttributes);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlInsertAttributes, PSReuseProbability.HIGH);
int col = 1;
@@ -209,25 +209,18 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
public PreparedStatement createObjectIdStatement(IDBStoreAccessor accessor)
{
- try
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Created ObjectID Statement : {0}", sqlSelectAllObjectIds);
- }
-
- return accessor.getConnection().prepareStatement(sqlSelectAllObjectIds);
- }
- catch (SQLException ex)
+ if (TRACER.isEnabled())
{
- throw new DBException(ex);
+ TRACER.format("Created ObjectID Statement : {0}", sqlSelectAllObjectIds);
}
+
+ return accessor.getStatementCache().getPreparedStatement(sqlSelectAllObjectIds, PSReuseProbability.HIGH);
}
public PreparedStatement createResourceQueryStatement(IDBStoreAccessor accessor, CDOID folderId, String name,
@@ -269,7 +262,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
{
int idx = 1;
- pstmt = accessor.getConnection().prepareStatement(builder.toString());
+ pstmt = accessor.getStatementCache().getPreparedStatement(builder.toString(), PSReuseProbability.MEDIUM);
pstmt.setLong(idx++, CDOIDUtil.getLong(folderId));
if (name != null)
@@ -287,7 +280,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
catch (SQLException ex)
{
- DBUtil.close(pstmt); // only close on error
+ accessor.getStatementCache().releasePreparedStatement(pstmt); // only release on error
throw new DBException(ex);
}
}
@@ -298,7 +291,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
try
{
// TODO add caching
- pstmt = accessor.getConnection().prepareStatement(sqlSelectCurrentAttributes);
+ pstmt = accessor.getStatementCache().getPreparedStatement(sqlSelectCurrentAttributes, PSReuseProbability.HIGH);
pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
// Read singleval-attribute table always (even without modeled attributes!)
@@ -318,7 +311,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
finally
{
- DBUtil.close(pstmt);
+ accessor.getStatementCache().releasePreparedStatement(pstmt);
}
}
@@ -329,7 +322,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
try
{
- stmt = accessor.getConnection().prepareStatement(sqlDelete);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlDelete, PSReuseProbability.HIGH);
stmt.setLong(1, CDOIDUtil.getLong(id));
CDODBUtil.sqlUpdate(stmt, true);
}
@@ -339,7 +332,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
@@ -485,7 +478,8 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
try
{
- stmt = accessor.getConnection().prepareStatement(buildUpdateStatement(attributeChanges, true));
+ stmt = accessor.getStatementCache().getPreparedStatement(buildUpdateStatement(attributeChanges, true),
+ PSReuseProbability.MEDIUM);
int col = 1;
@@ -510,7 +504,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
@@ -522,7 +516,8 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
try
{
- stmt = accessor.getConnection().prepareStatement(buildUpdateStatement(attributeChanges, false));
+ stmt = accessor.getStatementCache().getPreparedStatement(buildUpdateStatement(attributeChanges, false),
+ PSReuseProbability.MEDIUM);
int col = 1;
@@ -544,7 +539,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(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 73714b1..75edc46 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
@@ -26,6 +26,7 @@ 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.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
+import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.PSReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IListMapping;
import org.eclipse.emf.cdo.server.db.mapping.IListMappingDeltaSupport;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
@@ -33,7 +34,6 @@ import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
-import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.emf.ecore.EClass;
@@ -210,7 +210,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
try
{
- stmt = accessor.getConnection().prepareStatement(sqlClear);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlClear, PSReuseProbability.HIGH);
stmt.setLong(1, CDOIDUtil.getLong(id));
CDODBUtil.sqlUpdate(stmt, false);
}
@@ -220,7 +220,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
@@ -248,7 +248,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
try
{
- stmt = accessor.getConnection().prepareStatement(sqlInsertValue);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlInsertValue, PSReuseProbability.HIGH);
stmt.setLong(1, CDOIDUtil.getLong(id));
stmt.setInt(2, index);
getTypeMapping().setValue(stmt, 3, value);
@@ -261,7 +261,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
@@ -309,7 +309,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
try
{
- stmt = accessor.getConnection().prepareStatement(sqlUpdateIndex);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlUpdateIndex, PSReuseProbability.HIGH);
stmt.setInt(1, newIndex);
stmt.setLong(2, CDOIDUtil.getLong(id));
stmt.setInt(3, oldIndex);
@@ -321,7 +321,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
@@ -351,8 +351,8 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
try
{
- stmt = accessor.getConnection().prepareStatement(
- upperIndex == UNBOUNDED_MOVE ? sqlMoveDown : sqlMoveDownWithLimit);
+ stmt = accessor.getStatementCache().getPreparedStatement(
+ upperIndex == UNBOUNDED_MOVE ? sqlMoveDown : sqlMoveDownWithLimit, PSReuseProbability.HIGH);
stmt.setLong(1, CDOIDUtil.getLong(id));
stmt.setInt(2, index);
@@ -369,7 +369,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
@@ -383,7 +383,8 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
try
{
- stmt = accessor.getConnection().prepareStatement(upperIndex == UNBOUNDED_MOVE ? sqlMoveUp : sqlMoveUpWithLimit);
+ stmt = accessor.getStatementCache().getPreparedStatement(
+ upperIndex == UNBOUNDED_MOVE ? sqlMoveUp : sqlMoveUpWithLimit, PSReuseProbability.HIGH);
stmt.setLong(1, CDOIDUtil.getLong(id));
stmt.setInt(2, index);
if (upperIndex != UNBOUNDED_MOVE)
@@ -399,7 +400,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
@@ -409,7 +410,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
try
{
- stmt = accessor.getConnection().prepareStatement(sqlDeleteItem);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlDeleteItem, PSReuseProbability.HIGH);
stmt.setLong(1, CDOIDUtil.getLong(id));
stmt.setInt(2, index);
CDODBUtil.sqlUpdate(stmt, true);
@@ -420,7 +421,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
@@ -442,7 +443,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
try
{
- stmt = accessor.getConnection().prepareStatement(sqlUpdateValue);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlUpdateValue, PSReuseProbability.HIGH);
getTypeMapping().setValue(stmt, 1, value);
stmt.setLong(2, CDOIDUtil.getLong(id));
stmt.setInt(3, index);
@@ -454,7 +455,7 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
}
finally
{
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeCache.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeCache.java
index 4f58bd7..8910c07 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeCache.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/ObjectTypeCache.java
@@ -18,6 +18,7 @@ import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IMetaDataManager;
import org.eclipse.emf.cdo.server.db.IObjectTypeCache;
+import org.eclipse.emf.cdo.server.db.IPreparedStatementCache.PSReuseProbability;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
@@ -86,7 +87,7 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
try
{
- stmt = connection.prepareStatement(sqlSelect);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlSelect, PSReuseProbability.MAX);
stmt.setLong(1, CDOIDUtil.getLong(id));
DBUtil.trace(stmt.toString());
ResultSet resultSet = stmt.executeQuery();
@@ -107,8 +108,7 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
}
finally
{
- // TODO - statement caching
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
@@ -121,7 +121,7 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
try
{
- stmt = connection.prepareStatement(sqlInsert);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlInsert, PSReuseProbability.MAX);
stmt.setLong(1, CDOIDUtil.getLong(id));
stmt.setLong(2, metaDataManager.getMetaID(type));
DBUtil.trace(stmt.toString());
@@ -138,8 +138,7 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
}
finally
{
- // TODO - statement caching
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}
@@ -152,7 +151,7 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
try
{
- stmt = connection.prepareStatement(sqlDelete);
+ stmt = accessor.getStatementCache().getPreparedStatement(sqlDelete, PSReuseProbability.MAX);
stmt.setLong(1, CDOIDUtil.getLong(id));
DBUtil.trace(stmt.toString());
int result = stmt.executeUpdate();
@@ -168,8 +167,7 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
}
finally
{
- // TODO - statement caching
- DBUtil.close(stmt);
+ accessor.getStatementCache().releasePreparedStatement(stmt);
}
}