use of org.apache.derby.impl.sql.GenericPreparedStatement in project derby by apache.
the class GenericLanguageConnectionContext method lookupStatement.
/**
* See if a given statement has already been compiled for this user, and
* if so use its prepared statement. Returns null if not found.
*
* @exception StandardException thrown if lookup goes wrong.
* @return the prepared statement for the given string, null
* if none was found.
*/
public PreparedStatement lookupStatement(GenericStatement statement) throws StandardException {
CacheManager statementCache = getLanguageConnectionFactory().getStatementCache();
if (statementCache == null)
return null;
// statement caching disable when in DDL mode
if (dataDictionaryInWriteMode()) {
return null;
}
Cacheable cachedItem = statementCache.find(statement);
CachedStatement cs = (CachedStatement) cachedItem;
GenericPreparedStatement ps = cs.getPreparedStatement();
synchronized (ps) {
if (ps.upToDate()) {
GeneratedClass ac = ps.getActivationClass();
// Check to see if the statement was prepared before some change
// in the class loading set. If this is the case then force it to be invalid
int currentClasses = getLanguageConnectionFactory().getClassFactory().getClassLoaderVersion();
if (ac.getClassLoaderVersion() != currentClasses) {
ps.makeInvalid(DependencyManager.INTERNAL_RECOMPILE_REQUEST, this);
}
// note that the PreparedStatement is not kept in the cache. This is because
// having items kept in the cache that ultimately are held onto by
// user code is impossible to manage. E.g. an open ResultSet would hold onto
// a PreparedStatement (through its activation) and the user can allow
// this object to be garbage collected. Pushing a context stack is impossible
// in garbage collection as it may deadlock with the open connection and
// the context manager assumes a singel current thread per context stack
}
}
statementCache.release(cachedItem);
return ps;
}
use of org.apache.derby.impl.sql.GenericPreparedStatement in project derby by apache.
the class ConstraintCharacteristicsTest method testAlterConstraintInvalidation.
/**
* Check that altering constraint characteristics invalidates prepared
* statements.
* @throws SQLException
*/
public void testAlterConstraintInvalidation() throws SQLException {
if (usingDerbyNetClient()) {
// Skip, since we need to see inside an embedded connection here
return;
}
final Connection c = getConnection();
final Statement s = createStatement();
s.executeUpdate("create table t(i int, constraint c primary key(i))");
final PreparedStatement ps = c.prepareStatement("insert into t values 3");
ps.execute();
s.executeUpdate("alter table t alter constraint c enforced ");
final LanguageConnectionContext lcc = getLCC(c);
final GenericPreparedStatement derbyPs = (GenericPreparedStatement) lcc.getLastActivation().getPreparedStatement();
assertFalse(derbyPs.isValid());
rollback();
}
use of org.apache.derby.impl.sql.GenericPreparedStatement in project derby by apache.
the class CachedStatement method setIdentity.
/**
*/
public Cacheable setIdentity(Object key) {
identity = key;
ps = new GenericPreparedStatement((GenericStatement) key);
ps.setCacheHolder(this);
return this;
}
Aggregations