use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class TableDescriptor method makeInvalid.
/**
* Mark the dependent as invalid (due to at least one of
* its dependencies being invalid). Always an error
* for a table -- should never have gotten here.
*
* @param action The action causing the invalidation
*
* @exception StandardException thrown if called in sanity mode
*/
public void makeInvalid(int action, LanguageConnectionContext lcc) throws StandardException {
/*
** We should never get here, we should have barfed on
** prepareToInvalidate().
*/
if (SanityManager.DEBUG) {
DependencyManager dm;
dm = getDataDictionary().getDependencyManager();
SanityManager.THROWASSERT("makeInvalid(" + dm.getActionString(action) + ") not expected to get called");
}
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class ViewDescriptor method drop.
/**
* Drop this descriptor, if not already done, due to action.
* If action is not {@code DependencyManager.DROP_VIEW}, the descriptor is
* dropped due to dropping some other object, e.g. a table column.
*
* @param lcc current language connection context
* @param sd schema descriptor
* @param td table descriptor for this view
* @param action action
* @throws StandardException standard error policy
*/
private void drop(LanguageConnectionContext lcc, SchemaDescriptor sd, TableDescriptor td, int action) throws StandardException {
DataDictionary dd = getDataDictionary();
DependencyManager dm = dd.getDependencyManager();
TransactionController tc = lcc.getTransactionExecute();
/* Drop the columns */
dd.dropAllColumnDescriptors(td.getUUID(), tc);
/* Prepare all dependents to invalidate. (This is there chance
* to say that they can't be invalidated. For example, an open
* cursor referencing a table/view that the user is attempting to
* drop.) If no one objects, then invalidate any dependent objects.
*/
dm.invalidateFor(td, action, lcc);
/* Clear the dependencies for the view */
dm.clearDependencies(lcc, this);
/* Drop the view */
dd.dropViewDescriptor(this, tc);
/* Drop all table and column permission descriptors */
dd.dropAllTableAndColPermDescriptors(td.getUUID(), tc);
/* Drop the table */
dd.dropTableDescriptor(td, sd, tc);
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class GenericPreparedStatement method makeInvalid.
/**
* Mark the dependent as invalid (due to at least one of
* its dependencies being invalid).
*
* @param action The action causing the invalidation
*
* @exception StandardException Standard Derby error policy.
*/
public void makeInvalid(int action, LanguageConnectionContext lcc) throws StandardException {
boolean alreadyInvalid;
switch(action) {
case DependencyManager.RECHECK_PRIVILEGES:
return;
}
synchronized (this) {
if (compilingStatement) {
// Since the statement is in the process of being compiled,
// and at the end of the compilation it will set isValid to
// true and overwrite whatever we set it to here, set another
// flag to indicate that an invalidation was requested. A
// re-compilation will be triggered if this flag is set, but
// not until the current compilation is done.
invalidatedWhileCompiling = true;
return;
}
alreadyInvalid = !isValid;
// make ourseleves invalid
isValid = false;
// block compiles while we are invalidating
beginCompiling();
}
try {
DependencyManager dm = lcc.getDataDictionary().getDependencyManager();
/* Clear out the old dependencies on this statement as we
* will build the new set during the reprepare in makeValid().
*/
dm.clearDependencies(lcc, this);
/*
** If we are invalidating an EXECUTE STATEMENT because of a stale
** plan, we also need to invalidate the stored prepared statement.
*/
if (execStmtName != null) {
switch(action) {
case DependencyManager.INTERNAL_RECOMPILE_REQUEST:
case DependencyManager.CHANGED_CURSOR:
{
/*
** Get the DataDictionary, so we can get the descriptor for
** the SPP to invalidate it.
*/
DataDictionary dd = lcc.getDataDictionary();
SchemaDescriptor sd = dd.getSchemaDescriptor(execSchemaName, lcc.getTransactionCompile(), true);
SPSDescriptor spsd = dd.getSPSDescriptor(execStmtName, sd);
spsd.makeInvalid(action, lcc);
break;
}
}
}
} finally {
endCompiling();
}
}
use of org.apache.derby.iapi.sql.depend.DependencyManager 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;
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class SPSDescriptor method prepareToInvalidate.
/**
* Prepare to mark the dependent as invalid (due to at least one of
* its dependencies being invalid).
*
* @param action The action causing the invalidation
* @param p the provider
*
* @exception StandardException thrown if unable to make it invalid
*/
public final void prepareToInvalidate(Provider p, int action, LanguageConnectionContext lcc) throws StandardException {
switch(action) {
/*
** Things that don't affect us
*/
case DependencyManager.CREATE_VIEW:
/*
** Things that force a recompile, but are
** allowed.
*/
case DependencyManager.CREATE_INDEX:
case DependencyManager.CREATE_CONSTRAINT:
case DependencyManager.DROP_CONSTRAINT:
case DependencyManager.DROP_INDEX:
case DependencyManager.DROP_TABLE:
case DependencyManager.DROP_VIEW:
case DependencyManager.DROP_METHOD_ALIAS:
case DependencyManager.DROP_SYNONYM:
case DependencyManager.ALTER_TABLE:
case DependencyManager.RENAME:
case DependencyManager.RENAME_INDEX:
case DependencyManager.PREPARED_STATEMENT_RELEASE:
case DependencyManager.USER_RECOMPILE_REQUEST:
case DependencyManager.CHANGED_CURSOR:
case DependencyManager.BULK_INSERT:
case DependencyManager.COMPRESS_TABLE:
case DependencyManager.SET_CONSTRAINTS_ENABLE:
case DependencyManager.SET_CONSTRAINTS_DISABLE:
case DependencyManager.SET_TRIGGERS_ENABLE:
case DependencyManager.SET_TRIGGERS_DISABLE:
case DependencyManager.ROLLBACK:
case DependencyManager.INTERNAL_RECOMPILE_REQUEST:
case DependencyManager.CREATE_TRIGGER:
case DependencyManager.DROP_TRIGGER:
case DependencyManager.DROP_COLUMN:
case DependencyManager.DROP_COLUMN_RESTRICT:
case DependencyManager.UPDATE_STATISTICS:
case DependencyManager.DROP_STATISTICS:
case DependencyManager.TRUNCATE_TABLE:
break;
/*
** The rest are errors
*/
default:
DependencyManager dm;
dm = getDataDictionary().getDependencyManager();
throw StandardException.newException(SQLState.LANG_PROVIDER_HAS_DEPENDENT_S_P_S, dm.getActionString(action), p.getObjectName(), name);
}
}
Aggregations