diff options
author | Eike Stepper | 2013-09-05 06:19:37 +0000 |
---|---|---|
committer | Eike Stepper | 2013-09-05 06:19:37 +0000 |
commit | 68733d9f8c744fcaddba0a1ae917c75a209fe108 (patch) | |
tree | cfae4d5a8511b92be6208f55bf748df3d18926f4 /plugins/org.eclipse.net4j.db | |
parent | 1c2ba406f5c8150a50efe39da2aa4db5b75fa1d8 (diff) | |
download | cdo-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
Diffstat (limited to 'plugins/org.eclipse.net4j.db')
-rw-r--r-- | plugins/org.eclipse.net4j.db/src/org/eclipse/net4j/internal/db/DBConnection.java | 71 |
1 files changed, 41 insertions, 30 deletions
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(); + } } } |