use of org.apache.derby.iapi.sql.depend.Dependency in project derby by apache.
the class BasicDependencyManager method addInMemoryDependency.
/**
* Adds the dependency as an in-memory dependency.
*
* @param d the dependent
* @param p the provider
* @param cm context manager
* @throws StandardException if adding the dependency fails
* @see #addStoredDependency
*/
private synchronized void addInMemoryDependency(Dependent d, Provider p, ContextManager cm) throws StandardException {
Dependency dy = new BasicDependency(d, p);
// Duplicate dependencies are not added to the lists.
// If we find that the dependency we are trying to add in
// one list is a duplicate, then it should be a duplicate in the
// other list.
boolean addedToProvs = false;
boolean addedToDeps = addDependencyToTable(dependents, d.getObjectID(), dy);
if (addedToDeps) {
addedToProvs = addDependencyToTable(providers, p.getObjectID(), dy);
} else if (SanityManager.DEBUG) {
addedToProvs = addDependencyToTable(providers, p.getObjectID(), dy);
}
// Dependency should have been added to both or neither.
if (SanityManager.DEBUG) {
if (addedToDeps != addedToProvs) {
SanityManager.THROWASSERT("addedToDeps (" + addedToDeps + ") and addedToProvs (" + addedToProvs + ") are expected to agree");
}
}
// Add the dependency to the StatementContext, so that
// it can be cleared on a pre-execution error.
StatementContext sc = (StatementContext) cm.getContext(org.apache.derby.shared.common.reference.ContextId.LANG_STATEMENT);
sc.addDependency(dy);
}
use of org.apache.derby.iapi.sql.depend.Dependency in project derby by apache.
the class BasicDependencyManager method addDependencyToTable.
//
// class implementation
//
/**
* Add a new dependency to the specified table if it does not
* already exist in that table.
*
* @return boolean Whether or not the dependency get added.
*/
private boolean addDependencyToTable(Map<UUID, List<Dependency>> table, UUID key, Dependency dy) {
List<Dependency> deps = table.get(key);
if (deps == null) {
deps = new ArrayList<Dependency>();
deps.add(dy);
table.put(key, deps);
} else {
/* Make sure that we're not adding a duplicate dependency */
UUID provKey = dy.getProvider().getObjectID();
UUID depKey = dy.getDependent().getObjectID();
for (ListIterator<Dependency> depsIT = deps.listIterator(); depsIT.hasNext(); ) {
Dependency curDY = depsIT.next();
//
if (curDY.getProvider().getObjectID() == null) {
continue;
}
if (curDY.getProvider().getObjectID().equals(provKey) && curDY.getDependent().getObjectID().equals(depKey)) {
return false;
}
}
deps.add(dy);
}
if (SanityManager.DEBUG) {
if (SanityManager.DEBUG_ON("memoryLeakTrace")) {
if (table.size() > 100)
System.out.println("memoryLeakTrace:BasicDependencyManager:table " + table.size());
if (deps.size() > 50)
System.out.println("memoryLeakTrace:BasicDependencyManager:deps " + deps.size());
}
}
return true;
}
use of org.apache.derby.iapi.sql.depend.Dependency in project derby by apache.
the class BasicDependencyManager method clearDependencies.
/**
* @inheritDoc
*/
public void clearDependencies(LanguageConnectionContext lcc, Dependent d, TransactionController tc) throws StandardException {
UUID id = d.getObjectID();
// Remove all the stored dependencies.
if (d.isPersistent()) {
boolean wait = (tc == null);
dd.dropDependentsStoredDependencies(id, ((wait) ? lcc.getTransactionExecute() : tc), wait);
}
// Now remove the in-memory dependencies, if any.
synchronized (this) {
List deps = (List) dependents.get(id);
if (deps != null) {
Iterator depsIter = deps.iterator();
// the dependency from their lists
while (depsIter.hasNext()) {
Dependency dy = (Dependency) depsIter.next();
clearProviderDependency(dy.getProviderKey(), dy);
}
dependents.remove(id);
}
}
}
use of org.apache.derby.iapi.sql.depend.Dependency in project derby by apache.
the class GenericStatementContext method cleanupOnError.
//
// Context interface
//
/**
* Close down the top ResultSet, if relevant, and rollback to the
* internal savepoint, if one was set.
*
* @exception StandardException thrown on error. REVISIT: don't want
* cleanupOnError's to throw exceptions.
*/
public void cleanupOnError(Throwable error) throws StandardException {
if (SanityManager.DEBUG) {
if (SanityManager.DEBUG_ON("traceSavepoints")) {
SanityManager.DEBUG_PRINT("GenericStatementContext.cleanupOnError()", String.valueOf(hashCode()));
}
}
try {
/*
** If it isn't a StandardException, then assume
** session severity. It is probably an unexpected
** java error somewhere in the language.
** Store layer treats JVM error as session severity,
** hence to be consistent and to avoid getting rawstore
** protocol violation errors, we treat java errors here
** to be of session severity.
*/
int severity = ExceptionSeverity.SESSION_SEVERITY;
if (error instanceof StandardException) {
StandardException se = (StandardException) error;
// Update the severity.
severity = se.getSeverity();
// (for correctness, not optimization).
if (SQLState.LANG_STATEMENT_NEEDS_RECOMPILE.equals(se.getMessageId())) {
statementWasInvalidated = true;
}
}
/**
* Don't clean up this statement context if it's not in use.
* This can happen if you get an error while calling one of
* the JDBC getxxxx() methods on a ResultSet, since no statement
* context is pushed when those calls occur.
*/
if (!inUse) {
return;
}
/* Clean up the ResultSet, if one exists */
if (topResultSet != null) {
topResultSet.cleanUp();
}
/* Close down any open subqueries */
if (subqueryTrackingArray != null) {
for (int index = 0; index < subqueryTrackingArray.length; index++) {
/* Remember, the array is sparse, so only check
* non-null entries.
*/
if (subqueryTrackingArray[index] != null) {
subqueryTrackingArray[index].cleanUp();
}
}
}
/* Clean up any dependencies */
if (dependencies != null) {
DependencyManager dmgr = lcc.getDataDictionary().getDependencyManager();
for (Iterator<Dependency> iterator = dependencies.iterator(); iterator.hasNext(); ) {
Dependency dy = iterator.next();
dmgr.clearInMemoryDependency(dy);
}
dependencies = null;
}
if (severity <= ExceptionSeverity.STATEMENT_SEVERITY && setSavePoint) {
if (SanityManager.DEBUG) {
if (SanityManager.DEBUG_ON("traceSavepoints")) {
SanityManager.DEBUG_PRINT("GenericStatementContext.cleanupOnError", "rolling back to: " + internalSavePointName);
}
}
lcc.internalRollbackToSavepoint(internalSavePointName, false, null);
clearSavePoint();
}
if (severity >= ExceptionSeverity.TRANSACTION_SEVERITY) {
// transaction severity errors roll back the transaction.
/*
** We call clearSavePoint() above only for statement errors.
** We don't call clearSavePoint() for transaction errors because
** the savepoint will be rolled back anyway. So in this case,
** we need to indicate that the savepoint is not set.
*/
setSavePoint = false;
}
/* Pop the context */
lcc.popStatementContext(this, error);
} catch (Exception ex) {
// DERBY-6722(GenericStatementContext.cleanupOnError()
// needs protection from later errors during statement
// cleanup
ex.initCause(error);
throw StandardException.unexpectedUserException(ex);
}
}
use of org.apache.derby.iapi.sql.depend.Dependency in project derby by apache.
the class BasicDependencyManager method coreInvalidateFor.
/**
* A version of invalidateFor that does not provide synchronization among
* invalidators.
*
* @param p the provider
* @param action the action causing the invalidation
* @param lcc language connection context
*
* @throws StandardException if something goes wrong
*/
private void coreInvalidateFor(Provider p, int action, LanguageConnectionContext lcc) throws StandardException {
List<Dependency> list = getDependents(p);
if (list.isEmpty()) {
return;
}
// affectedCols is passed in from table descriptor provider to indicate
// which columns it cares; subsetCols is affectedCols' intersection
// with column bit map found in the provider of SYSDEPENDS line to
// find out which columns really matter. If SYSDEPENDS line's
// dependent is view (or maybe others), provider is table, yet it
// doesn't have column bit map because the view was created in a
// previous version of server which doesn't support column dependency,
// and we really want it to have (such as in drop column), in any case
// if we passed in table descriptor to this function with a bit map,
// we really need this, we generate the bitmaps on the fly and update
// SYSDEPENDS
//
// Note: Since the "previous version of server" mentioned above must
// be a version that predates Derby, and we don't support upgrade from
// those versions, we no longer have code to generate the column
// dependency list on the fly. Instead, an assert has been added to
// verify that we always have a column bitmap in SYSDEPENDS if the
// affectedCols bitmap is non-null.
FormatableBitSet affectedCols = null, subsetCols = null;
if (p instanceof TableDescriptor) {
affectedCols = ((TableDescriptor) p).getReferencedColumnMap();
if (affectedCols != null)
subsetCols = new FormatableBitSet(affectedCols.getLength());
}
{
StandardException noInvalidate = null;
// entries from this list.
for (int ei = list.size() - 1; ei >= 0; ei--) {
if (ei >= list.size())
continue;
Dependency dependency = list.get(ei);
Dependent dep = dependency.getDependent();
if (affectedCols != null) {
TableDescriptor td = (TableDescriptor) dependency.getProvider();
FormatableBitSet providingCols = td.getReferencedColumnMap();
if (providingCols == null) {
if (dep instanceof ViewDescriptor) {
// this code was removed as part of DERBY-6169.
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("Expected view to " + "have referenced column bitmap");
}
} else
// if dep instanceof ViewDescriptor
((TableDescriptor) p).setReferencedColumnMap(null);
} else // if providingCols == null
{
subsetCols.copyFrom(affectedCols);
subsetCols.and(providingCols);
if (subsetCols.anySetBit() == -1)
continue;
((TableDescriptor) p).setReferencedColumnMap(subsetCols);
}
}
// generate a list of invalidations that fail.
try {
dep.prepareToInvalidate(p, action, lcc);
} catch (StandardException sqle) {
if (noInvalidate == null) {
noInvalidate = sqle;
} else {
try {
sqle.initCause(noInvalidate);
noInvalidate = sqle;
} catch (IllegalStateException ise) {
// We weren't able to chain the exceptions. That's
// OK, since we always have the first exception we
// caught. Just skip the current exception.
}
}
}
if (noInvalidate == null) {
if (affectedCols != null)
((TableDescriptor) p).setReferencedColumnMap(affectedCols);
// REVISIT: future impl will want to mark the individual
// dependency as invalid as well as the dependent...
dep.makeInvalid(action, lcc);
}
}
if (noInvalidate != null)
throw noInvalidate;
}
}
Aggregations