* @exception StandardException thrown if lookup goes wrong.
*/
public void removeStatement(GenericStatement statement)
throws StandardException {
CacheManager statementCache =
getLanguageConnectionFactory().getStatementCache();
if (statementCache == null)
return;
Cacheable cachedItem = statementCache.findCached(statement);
// No need to do anything if the statement is already removed
if (cachedItem != null) {
CachedStatement cs = (CachedStatement) cachedItem;
if (statement.getPreparedStatement() != cs.getPreparedStatement()) {
// DERBY-3786: Someone else has removed the statement from
// the cache, probably because of the same error that brought
// us here. In addition, someone else has recreated the
// statement. Since the recreated statement is not the same
// object as the one we are working on, we don't have the
// proper guarding (through the synchronized flag
// GenericStatement.preparedStmt.compilingStatement) to ensure
// that we're the only ones calling CacheManager.remove() on
// this statement. Therefore, just release the statement here
// so that we don't get in the way for the other thread that
// is trying to compile the same query.
statementCache.release(cachedItem);
} else {
// The statement object that we were trying to compile is still
// in the cache. Since the compilation failed, remove it.
statementCache.remove(cachedItem);
}
}
}