use of org.apache.derby.iapi.sql.Statement in project derby by apache.
the class SPSDescriptor method compileStatement.
/**
* Compiles this SPS.
* <p>
* <em>Note:</em> This SPS may still be marked as invalid after this method
* has completed, because an invalidation request may have been received
* while compiling.
*
* @param lcc connection
* @param triggerTable subject table (may be {@code null})
* @param tc transaction controller to use (may be {@code null})
* @throws StandardException if something fails
*/
// @GuardedBy("this")
private void compileStatement(LanguageConnectionContext lcc, TableDescriptor triggerTable, TransactionController tc) throws StandardException {
ContextManager cm = lcc.getContextManager();
LanguageConnectionFactory lcf = lcc.getLanguageConnectionFactory();
DataDictionary dd = getDataDictionary();
/*
** If we are a trigger, then we have to go ahead
** and locate the trigger's table descriptor and
** push it on the lcc. This is expensive, but
** pretty atypical since trigger actions aren't
** likely to be invalidated too often. Also, when
** possible, we already have the triggerTable.
*/
if (type == SPS_TYPE_TRIGGER && triggerTable == null) {
// 49 because name consists of (see CreateTriggerConstantAction):
// TRIGGER<ACTN|WHEN>_<UUID:36>_<UUID:36>
String uuidStr = name.substring(49);
triggerTable = dd.getTableDescriptor(recreateUUID(uuidStr));
if (SanityManager.DEBUG) {
if (triggerTable == null) {
SanityManager.THROWASSERT("couldn't find trigger table for trigger sps " + name);
}
}
}
if (triggerTable != null) {
lcc.pushTriggerTable(triggerTable);
}
// stored statements always stored as unicode.
Statement stmt = lcf.getStatement(dd.getSchemaDescriptor(compSchemaId, null), text, true);
try {
preparedStatement = (ExecPreparedStatement) stmt.prepareStorable(lcc, preparedStatement, getParameterDefaults(), getSchemaDescriptor(), type == SPS_TYPE_TRIGGER);
} finally {
if (triggerTable != null) {
lcc.popTriggerTable(triggerTable);
}
}
// when the query is getting compiled.
if (preparedStatement.referencesSessionSchema())
throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES);
setCompileTime();
setParams(preparedStatement.getParameterTypes());
if (!dd.isReadOnlyUpgrade()) {
/*
** Indicate that we are going to write the data
** dictionary. We have probably already done this
** but it is ok to call startWriting more than once.
*/
dd.startWriting(lcc);
DependencyManager dm = dd.getDependencyManager();
/*
** Clear out all the dependencies that exist
** before we recreate them so we don't grow
** SYS.SYSDEPENDS forever.
*/
dm.clearDependencies(lcc, this, tc);
/*
** Copy over all the dependencies to me
*/
// from
dm.copyDependencies(// from
preparedStatement, // to
this, // persistent only
false, cm, tc);
// between this sps and the trigger table DERBY-5120
if (triggerTable != null)
dm.addDependency(this, triggerTable, lcc.getContextManager());
}
// mark it as valid
valid = true;
}
Aggregations