use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class AliasDescriptor method makeInvalid.
/**
* Mark the dependent as invalid (due to at least one of
* its dependencies being invalid). Always an error
* for an alias -- 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 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 void prepareToInvalidate(Provider p, int action, LanguageConnectionContext lcc) throws StandardException {
switch(action) {
/*
* We don't care about creating or dropping indexes or
* alter table on an underlying table.
*/
case DependencyManager.CREATE_INDEX:
case DependencyManager.DROP_INDEX:
case DependencyManager.DROP_COLUMN:
case DependencyManager.CREATE_CONSTRAINT:
case DependencyManager.ALTER_TABLE:
case DependencyManager.CREATE_TRIGGER:
case DependencyManager.DROP_TRIGGER:
case DependencyManager.BULK_INSERT:
case DependencyManager.COMPRESS_TABLE:
case DependencyManager.RENAME_INDEX:
case DependencyManager.UPDATE_STATISTICS:
case DependencyManager.DROP_STATISTICS:
case DependencyManager.TRUNCATE_TABLE:
/*
** Set constriants is a bit odd in that it
** will send a SET_CONSTRAINTS on the table
** when it enables a constraint, rather than
** on the constraint. So since we depend on
** the table, we have to deal with this action.
*/
case DependencyManager.SET_CONSTRAINTS_ENABLE:
case DependencyManager.SET_TRIGGERS_ENABLE:
// the ViewDescriptor drop itself.
case DependencyManager.REVOKE_PRIVILEGE:
// ViewDescriptor drop itself.
case DependencyManager.REVOKE_ROLE:
// Only used by Activations
case DependencyManager.RECHECK_PRIVILEGES:
break;
// to handle this event.
case DependencyManager.INTERNAL_RECOMPILE_REQUEST:
break;
// object (table, column, privilege, etc.)
default:
DependencyManager dm;
dm = getDataDictionary().getDependencyManager();
throw StandardException.newException(SQLState.LANG_PROVIDER_HAS_DEPENDENT_VIEW, dm.getActionString(action), p.getObjectName(), viewName);
}
// end switch
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class CreateTriggerNode method bindStatement.
// accessors
// We inherit the generate() method from DDLStatementNode.
/**
* Bind this CreateTriggerNode. This means doing any static error
* checking that can be done before actually creating the table.
*
* @exception StandardException Thrown on error
*/
@Override
public void bindStatement() throws StandardException {
CompilerContext compilerContext = getCompilerContext();
DataDictionary dd = getDataDictionary();
/*
** Grab the current schema. We will use that for
** sps compilation
*/
LanguageConnectionContext lcc = getLanguageConnectionContext();
compSchemaDescriptor = lcc.getDefaultSchema();
/*
** Get and check the schema descriptor for this
** trigger. This check will throw the proper exception
** if someone tries to create a trigger in the SYS
** schema.
*/
triggerSchemaDescriptor = getSchemaDescriptor();
/*
** Get the trigger table.
*/
triggerTableDescriptor = getTableDescriptor(tableName);
// throw an exception if user is attempting to create a trigger on a temporary table
if (isSessionSchema(triggerTableDescriptor.getSchemaDescriptor())) {
throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES);
}
if (isPrivilegeCollectionRequired()) {
compilerContext.pushCurrentPrivType(Authorizer.TRIGGER_PRIV);
compilerContext.addRequiredTablePriv(triggerTableDescriptor);
compilerContext.popCurrentPrivType();
}
/*
** Regenerates the actionText and actionNode if necessary.
*/
boolean needInternalSQL = bindReferencesClause(dd);
// Get all the names of SQL objects referenced by the triggered
// SQL statement and the WHEN clause. Since some of the TableName
// nodes may be eliminated from the node tree during the bind phase,
// we collect the nodes before the nodes have been bound. The
// names will be used later when we normalize the trigger text
// that will be stored in the system tables.
SortedSet<TableName> actionNames = actionNode.getOffsetOrderedNodes(TableName.class);
SortedSet<TableName> whenNames = (whenClause != null) ? whenClause.getOffsetOrderedNodes(TableName.class) : null;
ProviderList prevAPL = compilerContext.getCurrentAuxiliaryProviderList();
ProviderList apl = new ProviderList();
lcc.pushTriggerTable(triggerTableDescriptor);
try {
compilerContext.setCurrentAuxiliaryProviderList(apl);
/*
** Bind the trigger action and the trigger
** when clause to make sure that they are
** ok. Note that we have already substituted
** in various replacements for OLD/NEW transition
** tables/variables and reparsed if necessary.
*/
if (needInternalSQL)
compilerContext.setReliability(CompilerContext.INTERNAL_SQL_LEGAL);
// bind of the call statement node.
if (isBefore)
compilerContext.setReliability(CompilerContext.MODIFIES_SQL_DATA_PROCEDURE_ILLEGAL);
actionNode.bindStatement();
if (whenClause != null) {
ContextManager cm = getContextManager();
whenClause = whenClause.bindExpression(new FromList(cm), new SubqueryList(cm), new ArrayList<AggregateNode>(0));
// The WHEN clause must be a BOOLEAN expression.
whenClause.checkIsBoolean();
}
} finally {
lcc.popTriggerTable(triggerTableDescriptor);
compilerContext.setCurrentAuxiliaryProviderList(prevAPL);
}
// Qualify identifiers before storing them (DERBY-5901/DERBY-6370).
qualifyNames(actionNames, whenNames);
/*
** Statement is dependent on the TableDescriptor
*/
compilerContext.createDependency(triggerTableDescriptor);
/*
** If there is a list of columns, then no duplicate columns,
** and all columns must be found.
*/
if (triggerCols != null && triggerCols.size() != 0) {
HashSet<String> columnNames = new HashSet<String>();
for (ResultColumn rc : triggerCols) {
if (!columnNames.add(rc.getName())) {
throw StandardException.newException(SQLState.LANG_DUPLICATE_COLUMN_IN_TRIGGER_UPDATE, rc.getName(), triggerName);
}
ColumnDescriptor cd = triggerTableDescriptor.getColumnDescriptor(rc.getName());
if (cd == null) {
throw StandardException.newException(SQLState.LANG_COLUMN_NOT_FOUND_IN_TABLE, rc.getName(), tableName);
}
}
}
// statement references a table in the SESSION schema.
if (referencesSessionSchema()) {
throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES);
}
DependencyManager dm = dd.getDependencyManager();
providerInfo = dm.getPersistentProviderInfos(apl);
dm.clearColumnInfoInProviders(apl);
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class GenericLanguageConnectionContext method dropAllDeclaredGlobalTempTables.
/**
* Drop all the declared global temporary tables associated with this
* connection. This gets called when a getConnection() is done on a
* PooledConnection. This will ensure all the temporary tables declared on
* earlier connection handle associated with this physical database
* connection are dropped before a new connection handle is issued on that
* same physical database connection.
*/
private void dropAllDeclaredGlobalTempTables() throws StandardException {
if (allDeclaredGlobalTempTables == null)
return;
DependencyManager dm = getDataDictionary().getDependencyManager();
StandardException topLevelStandardException = null;
// temporary tables and throw them as one chained exception at the end.
for (int i = 0; i < allDeclaredGlobalTempTables.size(); i++) {
try {
TempTableInfo tempTableInfo = allDeclaredGlobalTempTables.get(i);
TableDescriptor td = tempTableInfo.getTableDescriptor();
// the following 2 lines of code has been copied from
// DropTableConstantAction. If there are any changes made there
// in future, we should check if they need to be made here too.
dm.invalidateFor(td, DependencyManager.DROP_TABLE, this);
tran.dropConglomerate(td.getHeapConglomerateId());
} catch (StandardException e) {
if (topLevelStandardException == null) {
// always keep the first exception unchanged
topLevelStandardException = e;
} else {
try {
// Try to create a chain of exceptions. If successful,
// the current exception is the top-level exception,
// and the previous exception the cause of it.
e.initCause(topLevelStandardException);
topLevelStandardException = e;
} catch (IllegalStateException ise) {
// initCause() has already been called on e. We don't
// expect this to happen, but if it happens, just skip
// the current exception from the chain. This is safe
// since we always keep the first exception.
}
}
}
}
allDeclaredGlobalTempTables = null;
try {
internalCommit(true);
} catch (StandardException e) {
// do the same chaining as above
if (topLevelStandardException == null) {
topLevelStandardException = e;
} else {
try {
e.initCause(topLevelStandardException);
topLevelStandardException = e;
} catch (IllegalStateException ise) {
/* ignore */
}
}
}
if (topLevelStandardException != null)
throw topLevelStandardException;
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class TableElementList method genConstraintActions.
/**
* Fill in the ConstraintConstantAction[] for this create/alter table.
*
* @param forCreateTable ConstraintConstantAction is for a create table.
* @param conActions The ConstraintConstantAction[] to be filled in.
* @param tableName The name of the Table being created.
* @param tableSd The schema for that table.
* @param dd The DataDictionary
*
* @exception StandardException Thrown on failure
*/
void genConstraintActions(boolean forCreateTable, ConstraintConstantAction[] conActions, String tableName, SchemaDescriptor tableSd, DataDictionary dd) throws StandardException {
int conActionIndex = 0;
for (TableElementNode ten : this) {
String[] columnNames = null;
IndexConstantAction indexAction = null;
if (!ten.hasConstraint() || ten instanceof ColumnDefinitionNode) {
continue;
}
ConstraintDefinitionNode constraintDN = (ConstraintDefinitionNode) ten;
if (constraintDN.getColumnList() != null) {
columnNames = new String[constraintDN.getColumnList().size()];
constraintDN.getColumnList().exportNames(columnNames);
}
int constraintType = constraintDN.getConstraintType();
boolean[] cChars = constraintDN.getCharacteristics();
String constraintText = constraintDN.getConstraintText();
/*
** If the constraint is not named (e.g.
** create table x (x int primary key)), then
** the constraintSd is the same as the table.
*/
String constraintName = constraintDN.getConstraintMoniker();
/* At execution time, we will generate a unique name for the backing
* index (for CREATE CONSTRAINT) and we will look up the conglomerate
* name (for DROP CONSTRAINT).
*/
if (constraintDN.requiresBackingIndex()) {
if (constraintDN.constraintType == DataDictionary.UNIQUE_CONSTRAINT && (dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_4, null))) {
boolean contains_nullable_columns = areColumnsNullable(constraintDN, td);
// if all the columns are non nullable, continue to use
// a unique backing index.
boolean unique = !contains_nullable_columns;
// Only use a "unique with duplicate nulls" backing index
// for constraints with nullable columns.
boolean uniqueWithDuplicateNulls = contains_nullable_columns;
indexAction = genIndexAction(forCreateTable, unique, uniqueWithDuplicateNulls, // deferrable?
cChars[0], // initiallyDeferred?
cChars[1], null, constraintDN, columnNames, true, tableSd, tableName, constraintType, dd);
} else {
// PRIMARY KEY, FOREIGN KEY
// For foreign key constraint we do no mark the
// index as deferrable; since checking isn't done on
// duplicate keys there.
indexAction = genIndexAction(forCreateTable, constraintDN.requiresUniqueIndex(), false, cChars[0], cChars[1], null, constraintDN, columnNames, true, tableSd, tableName, constraintType, dd);
}
}
if (constraintType == DataDictionary.DROP_CONSTRAINT) {
if (SanityManager.DEBUG) {
// Can't drop constraints on a create table.
SanityManager.ASSERT(!forCreateTable);
}
conActions[conActionIndex] = getGenericConstantActionFactory().getDropConstraintConstantAction(constraintName, // / FiX
constraintDN.getDropSchemaName(), tableName, td.getUUID(), tableSd.getSchemaName(), indexAction, constraintDN.getDropBehavior(), constraintDN.getVerifyType());
} else if (constraintType == DataDictionary.MODIFY_CONSTRAINT) {
conActions[conActionIndex] = getGenericConstantActionFactory().getAlterConstraintConstantAction(constraintName, constraintDN.getDropSchemaName(), cChars, tableName, td.getUUID(), tableSd.getSchemaName(), indexAction);
} else {
ProviderList apl = constraintDN.getAuxiliaryProviderList();
ConstraintInfo refInfo = null;
ProviderInfo[] providerInfos;
if (constraintDN instanceof FKConstraintDefinitionNode) {
refInfo = ((FKConstraintDefinitionNode) constraintDN).getReferencedConstraintInfo();
}
/* Create the ProviderInfos, if the constraint is dependent on any Providers */
if (apl != null && apl.size() > 0) {
/* Get all the dependencies for the current statement and transfer
* them to this view.
*/
DependencyManager dm = dd.getDependencyManager();
providerInfos = dm.getPersistentProviderInfos(apl);
} else {
providerInfos = new ProviderInfo[0];
// System.out.println("TABLE ELEMENT LIST EMPTY");
}
conActions[conActionIndex++] = getGenericConstantActionFactory().getCreateConstraintConstantAction(constraintName, constraintType, cChars, forCreateTable, tableName, ((td != null) ? td.getUUID() : (UUID) null), tableSd.getSchemaName(), columnNames, indexAction, constraintText, refInfo, providerInfos);
}
}
}
Aggregations