use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class SchemaDescriptor method drop.
/**
* Drop this schema.
* Drops the schema if it is empty. If the schema was
* the current default then the current default will be
* reset through the language connection context.
* @throws StandardException Schema could not be dropped.
*/
public void drop(LanguageConnectionContext lcc, Activation activation) throws StandardException {
DataDictionary dd = getDataDictionary();
DependencyManager dm = dd.getDependencyManager();
TransactionController tc = lcc.getTransactionExecute();
// no physical SESSION schema and hence getSchemaDescriptor has returned an in-memory SESSION schema
if (getSchemaName().equals(SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME) && (getUUID() == null))
throw StandardException.newException(SQLState.LANG_SCHEMA_DOES_NOT_EXIST, getSchemaName());
/*
** Make sure the schema is empty.
** In the future we want to drop everything
** in the schema if it is CASCADE.
*/
if (!dd.isSchemaEmpty(this)) {
throw StandardException.newException(SQLState.LANG_SCHEMA_NOT_EMPTY, getSchemaName());
}
/* 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(this, DependencyManager.DROP_SCHEMA, lcc);
dd.dropSchemaDescriptor(getSchemaName(), tc);
/*
** If we have dropped the current default schema,
** then we will set the default to null. The
** LCC is free to set the new default schema to
** some system defined default.
*/
lcc.resetSchemaUsages(activation, getSchemaName());
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class AliasDescriptor method drop.
/**
* Drop the routine or synonym.
* For a routine its permission descriptors will be dropped as well.
* For a synonym its TableDescriptor will be dropped as well.
* @param lcc
* @throws StandardException
*/
public void drop(LanguageConnectionContext lcc) throws StandardException {
DataDictionary dd = getDataDictionary();
TransactionController tc = lcc.getTransactionExecute();
DependencyManager dm = dd.getDependencyManager();
/* Prepare all dependents to invalidate. (This is their 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.
* We check for invalidation before we drop the descriptor
* since the descriptor may be looked up as part of
* decoding tuples in SYSDEPENDS.
*/
int invalidationType = 0;
switch(getAliasType()) {
case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
invalidationType = DependencyManager.DROP_METHOD_ALIAS;
break;
case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
invalidationType = DependencyManager.DROP_SYNONYM;
break;
case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR:
invalidationType = DependencyManager.DROP_UDT;
break;
case AliasInfo.ALIAS_TYPE_AGGREGATE_AS_CHAR:
invalidationType = DependencyManager.DROP_AGGREGATE;
break;
}
dm.invalidateFor(this, invalidationType, lcc);
if (getAliasType() == AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR) {
SchemaDescriptor sd = dd.getSchemaDescriptor(schemaID, tc);
// Drop the entry from SYSTABLES as well.
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
TableDescriptor td = ddg.newTableDescriptor(aliasName, sd, TableDescriptor.SYNONYM_TYPE, TableDescriptor.DEFAULT_LOCK_GRANULARITY);
dd.dropTableDescriptor(td, sd, tc);
} else
dd.dropAllRoutinePermDescriptors(getUUID(), tc);
/* Drop the alias */
dd.dropAliasDescriptor(this, tc);
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class ConglomerateDescriptor method drop.
/**
* Drop this ConglomerateDescriptor when it represents
* an index. If this is the last desciptor for
* a physical index then the physical index (conglomerate)
* and its descriptor will be dropped.
*
* @param lcc Connection context to use for dropping
* @param td TableDescriptor for the table to which this
* conglomerate belongs
* @return If the conglomerate described by this descriptor
* is an index conglomerate that is shared by multiple
* constraints/indexes, then we may have to create a new
* conglomerate to satisfy the constraints/indexes which
* remain after we drop the existing conglomerate. If that's
* needed then we'll return a conglomerate descriptor which
* describes what the new conglomerate must look like. It
* is then up to the caller of this method to create a new
* corresponding conglomerate. We don't create the index
* here because depending on who called us, it might not
* make sense to create it--esp. if we get here because of
* a DROP TABLE.
* @throws StandardException
*/
public ConglomerateDescriptor drop(LanguageConnectionContext lcc, TableDescriptor td) throws StandardException {
DataDictionary dd = getDataDictionary();
DependencyManager dm = dd.getDependencyManager();
TransactionController tc = lcc.getTransactionExecute();
// invalidate any prepared statements that
// depended on the index (including this one)
dm.invalidateFor(this, DependencyManager.DROP_INDEX, lcc);
// only drop the conglomerate if no similar index but with different
// name. Get from dd in case we drop other dup indexes with a cascade operation
ConglomerateDescriptor[] congDescs = dd.getConglomerateDescriptors(getConglomerateNumber());
boolean dropConglom = false;
ConglomerateDescriptor physicalCD = null;
if (congDescs.length == 1)
dropConglom = true;
else {
/* There are multiple conglomerate descriptors which share
* the same physical conglomerate. That said, if we are
* dropping the *ONLY* conglomerate descriptor that fully
* matches the physical conglomerate, then we have to do
* a little extra work. Namely, if the physical conglomerate
* is unique and this descriptor is unique, but none of the
* other descriptors which share with this one are unique,
* then we have to "update" the physical conglomerate to
* be non-unique. This ensures correct behavior for the
* remaining descriptors. (DERBY-3299)
*
* Note that "update the physical conglomerate" above is
* currently implemented as "drop the old conglomerate"
* (now) and "create a new (replacement) one" (later--let
* the caller do it). Possible improvements to that logic
* may be desirable in the future...
*/
boolean needNewConglomerate;
/* Find a conglomerate descriptor that fully describes what
* a physical conglomerate would have to look like in order
* to fulfill the requirements (esp. uniqueness) of _all_
* conglomerate descriptors which share a physical conglomerate
* with this one. "true" in the next line means that when we
* search for such a conglomerate, we should ignore "this"
* descriptor--because we're going to drop this one and we
* want to see what the physical conglomerate must look like
* when "this" descriptor does not exist. Note that this
* call should never return null because we only get here
* if more than one descriptor shares a conglom with this
* one--so at the very least we'll have two descriptors,
* which means the following call should return the "other"
* one.
*/
physicalCD = describeSharedConglomerate(congDescs, true);
IndexRowGenerator othersIRG = physicalCD.getIndexDescriptor();
/* Let OTHERS denote the set of "other" descriptors which
* share a physical conglomerate with this one. Recall
* that (for now) 1) sharing descriptors must always have
* the same columns referenced in the same order, and
* 2) if a unique descriptor shares a conglomerate with
* a non-unique descriptor, the physical conglomerate
* must itself be unique. So given that, we have four
* possible cases:
*
* 1. "this" is unique, none of OTHERS are unique
* 2. "this" is unique, 1 or more of OTHERS is unique
* 3. "this" is not unique, none of OTHERS are unique
* 4. "this" is not unique, 1 or more of OTHERS is unique
*
* In case 1 "this" conglomerate descriptor must be the
* _only_ one which fully matches the physical conglom.
* In case 4, "this" descriptor does _not_ fully match
* the physical conglomerate. In cases 2 and 3, "this"
* descriptor fully matches the physical conglom, but it
* is NOT the only one to do so--which means we don't need
* to update the physical conglomerate when we drop "this"
* (because OTHERS need the exact same physical conglom).
* The only case that actually requires an "updated"
* conglomerate, then, is case 1, since the physical
* conglomerate for the remaining descriptors no longer
* has a uniqueness requirement.
*/
needNewConglomerate = (indexRowGenerator.isUnique() && !othersIRG.isUnique()) || (indexRowGenerator.isUniqueWithDuplicateNulls() && !othersIRG.isUniqueWithDuplicateNulls());
if (needNewConglomerate) {
/* We have to create a new backing conglomerate
* to correctly represent the remaing (sharing)
* descriptors, so drop the physical conglomerate
* now. The caller of the method can then create
* new conglomerate as/if needed.
*/
dropConglom = true;
} else
physicalCD = null;
}
/* DERBY-5681 Drop statistics */
dd.dropStatisticsDescriptors(td.getUUID(), getUUID(), tc);
if (dropConglom) {
/* Drop the physical conglomerate */
tc.dropConglomerate(getConglomerateNumber());
}
/* Drop the conglomerate descriptor */
dd.dropConglomerateDescriptor(this, tc);
/*
** Remove the conglomerate descriptor from the list hanging off of the
** table descriptor
*/
td.removeConglomerateDescriptor(this);
return physicalCD;
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class DefaultDescriptor method makeInvalid.
/**
* Mark the dependent as invalid (due to at least one of
* its dependencies being invalid). Always an error
* for a constraint -- 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 IndexStatisticsDaemonImpl method invalidateStatements.
/**
* Performs an invalidation action for the given table (the event being
* statistics update).
*
* @param lcc connection context to use to perform the work
* @param td the table to invalidate for
* @param asBackgroundTask whether the update is done automatically as
* part of a background task or if explicitly invoked by the user
* @throws StandardException if the invalidation request fails
*/
private void invalidateStatements(LanguageConnectionContext lcc, TableDescriptor td, boolean asBackgroundTask) throws StandardException {
// Invalidate compiled statements accessing the table.
DataDictionary dd = lcc.getDataDictionary();
DependencyManager dm = dd.getDependencyManager();
int retries = 0;
while (true) {
try {
if (!lcc.dataDictionaryInWriteMode()) {
dd.startWriting(lcc);
}
dm.invalidateFor(td, DependencyManager.UPDATE_STATISTICS, lcc);
trace(1, "invalidation completed");
break;
} catch (StandardException se) {
if (se.isLockTimeout() && asBackgroundTask && retries < 3) {
retries++;
// locks, back down by releasing our own locks.
if (retries > 1) {
trace(2, "releasing locks");
lcc.internalRollback();
}
trace(2, "lock timeout when invalidating");
// adaptive sleeping...
sleep(100 * (1 + retries));
} else {
// Throw exception because of one of:
// o it isn't a lock timeout
// - or -
// o we gave up retrying
// - or -
// o we are running in explicit mode
trace(1, "invalidation failed");
throw se;
}
}
}
}
Aggregations