Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-09-05 06:19:37 +0000
committerEike Stepper2013-09-05 06:19:37 +0000
commit68733d9f8c744fcaddba0a1ae917c75a209fe108 (patch)
treecfae4d5a8511b92be6208f55bf748df3d18926f4
parent1c2ba406f5c8150a50efe39da2aa4db5b75fa1d8 (diff)
downloadcdo-68733d9f8c744fcaddba0a1ae917c75a209fe108.tar.gz
cdo-68733d9f8c744fcaddba0a1ae917c75a209fe108.tar.xz
cdo-68733d9f8c744fcaddba0a1ae917c75a209fe108.zip
[416587] [DB] NPE in PreparedStatementCache
https://bugs.eclipse.org/bugs/show_bug.cgi?id=416587
-rw-r--r--plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java2
-rw-r--r--plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBConnection.java71
2 files changed, 42 insertions, 31 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java
index 292e0783e0..8e318fd82b 100644
--- a/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java
+++ b/plugins/org.eclipse.emf.cdo.server.ocl/src/org/eclipse/emf/cdo/server/ocl/CDOExtentCreator.java
@@ -355,7 +355,7 @@ public class CDOExtentCreator implements OCLExtentCreator
try
{
- mutex.wait();
+ mutex.wait(500L);
}
catch (InterruptedException ex)
{
diff --git a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBConnection.java b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBConnection.java
index a1ebc040cb..4128f3f852 100644
--- a/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBConnection.java
+++ b/plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBConnection.java
@@ -122,21 +122,26 @@ public final class DBConnection extends DelegatingConnection implements IDBConne
{
database.beginSchemaAccess(false);
- DBPreparedStatement preparedStatement = cache.remove(sql);
- if (preparedStatement == null)
+ DBPreparedStatement preparedStatement;
+ synchronized (this)
{
- try
- {
- PreparedStatement delegate = getDelegate().prepareStatement(sql, resultSetType, resultSetConcurrency);
- preparedStatement = new DBPreparedStatement(this, sql, reuseProbability, delegate);
- }
- catch (SQLException ex)
+ preparedStatement = cache.remove(sql);
+ if (preparedStatement == null)
{
- throw new DBException(ex);
+ try
+ {
+ PreparedStatement delegate = getDelegate().prepareStatement(sql, resultSetType, resultSetConcurrency);
+ preparedStatement = new DBPreparedStatement(this, sql, reuseProbability, delegate);
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
}
+
+ checkOuts.add(preparedStatement);
}
- checkOuts.add(preparedStatement);
return preparedStatement;
}
@@ -163,19 +168,22 @@ public final class DBConnection extends DelegatingConnection implements IDBConne
return;
}
- checkOuts.remove(preparedStatement);
- preparedStatement.setTouch(++lastTouch);
-
- String sql = preparedStatement.getSQL();
- if (cache.put(sql, preparedStatement) != null)
- {
- throw new IllegalStateException(sql + " already in cache"); //$NON-NLS-1$
- }
-
- if (cache.size() > database.getStatementCacheCapacity())
+ synchronized (this)
{
- DBPreparedStatement old = cache.remove(cache.firstKey());
- DBUtil.close(old.getDelegate());
+ checkOuts.remove(preparedStatement);
+ preparedStatement.setTouch(++lastTouch);
+
+ String sql = preparedStatement.getSQL();
+ if (cache.put(sql, preparedStatement) != null)
+ {
+ throw new IllegalStateException(sql + " already in cache"); //$NON-NLS-1$
+ }
+
+ if (cache.size() > database.getStatementCacheCapacity())
+ {
+ DBPreparedStatement old = cache.remove(cache.firstKey());
+ DBUtil.close(old.getDelegate());
+ }
}
}
finally
@@ -186,15 +194,18 @@ public final class DBConnection extends DelegatingConnection implements IDBConne
public void invalidateStatementCache()
{
- CheckUtil.checkState(checkOuts.isEmpty(), "Statements are checked out: " + checkOuts);
-
- // Close all statements in the cache, then clear the cache.
- for (DBPreparedStatement preparedStatement : cache.values())
+ synchronized (this)
{
- PreparedStatement delegate = preparedStatement.getDelegate();
- DBUtil.close(delegate);
- }
+ CheckUtil.checkState(checkOuts.isEmpty(), "Statements are checked out: " + checkOuts);
- cache.clear();
+ // Close all statements in the cache, then clear the cache.
+ for (DBPreparedStatement preparedStatement : cache.values())
+ {
+ PreparedStatement delegate = preparedStatement.getDelegate();
+ DBUtil.close(delegate);
+ }
+
+ cache.clear();
+ }
}
}

Back to the top