use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class DataDictionaryImpl method addTableDescriptorToOtherCache.
/**
* Add a table descriptor to the "other" cache. The other cache is
* determined by the type of the object c.
*
* @param td TableDescriptor to add to the other cache.
* @param c Cacheable Object which lets us figure out the other cache.
*
* @exception StandardException
*/
public void addTableDescriptorToOtherCache(TableDescriptor td, Cacheable c) throws StandardException {
// get the other cache. if the entry we are setting in the cache is of
// type oidtdcacheable then use the nametdcache
CacheManager otherCache = (c instanceof OIDTDCacheable) ? nameTdCache : OIDTdCache;
Object key;
TDCacheable otherCacheEntry = null;
if (otherCache == nameTdCache)
key = new TableKey(td.getSchemaDescriptor().getUUID(), td.getName());
else
key = td.getUUID();
try {
// insert the entry into the the other cache.
otherCacheEntry = (TDCacheable) otherCache.create(key, td);
} catch (StandardException se) {
// otherwise throw the error.
if (!(se.getMessageId().equals(SQLState.OBJECT_EXISTS_IN_CACHE)))
throw se;
} finally {
if (otherCacheEntry != null)
otherCache.release(otherCacheEntry);
}
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class DataDictionaryImpl method getDescriptorViaIndexMinion.
private <T extends TupleDescriptor> T getDescriptorViaIndexMinion(int indexId, ExecIndexRow keyRow, ScanQualifier[][] scanQualifiers, TabInfoImpl ti, TupleDescriptor parentTupleDescriptor, List<? super T> list, Class<T> returnType, boolean forUpdate, int isolationLevel, TransactionController tc) throws StandardException {
CatalogRowFactory rf = ti.getCatalogRowFactory();
ConglomerateController heapCC;
ExecIndexRow indexRow1;
ExecRow outRow;
RowLocation baseRowLocation;
ScanController scanController;
T td = null;
if (SanityManager.DEBUG) {
SanityManager.ASSERT(isolationLevel == TransactionController.ISOLATION_REPEATABLE_READ || isolationLevel == TransactionController.ISOLATION_READ_UNCOMMITTED);
}
outRow = rf.makeEmptyRow();
heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, isolationLevel);
/* Scan the index and go to the data pages for qualifying rows to
* build the column descriptor.
*/
scanController = tc.openScan(// conglomerate to open
ti.getIndexConglomerate(indexId), // don't hold open across commit
false, (forUpdate) ? TransactionController.OPENMODE_FORUPDATE : 0, TransactionController.MODE_RECORD, isolationLevel, // all fields as objects
(FormatableBitSet) null, // start position - first row
keyRow.getRowArray(), // startSearchOperation
ScanController.GE, // scanQualifier,
scanQualifiers, // stop position - through last row
keyRow.getRowArray(), // stopSearchOperation
ScanController.GT);
while (true) {
// create an index row template
indexRow1 = getIndexRowFromHeapRow(ti.getIndexRowGenerator(indexId), heapCC.newRowLocationTemplate(), outRow);
// from the table.
if (!scanController.fetchNext(indexRow1.getRowArray())) {
break;
}
baseRowLocation = (RowLocation) indexRow1.getColumn(indexRow1.nColumns());
// RESOLVE paulat - remove the try catch block when track 3677 is fixed
// just leave the contents of the try block
// adding to get more info on track 3677
boolean base_row_exists = false;
try {
base_row_exists = heapCC.fetch(baseRowLocation, outRow.getRowArray(), (FormatableBitSet) null);
} catch (RuntimeException re) {
if (SanityManager.DEBUG) {
if (re instanceof AssertFailure) {
StringBuffer strbuf = new StringBuffer("Error retrieving base row in table " + ti.getTableName());
strbuf.append(": An ASSERT was thrown when trying to locate a row matching index row " + indexRow1 + " from index " + ti.getIndexName(indexId) + ", conglom number " + ti.getIndexConglomerate(indexId));
debugGenerateInfo(strbuf, tc, heapCC, ti, indexId);
}
}
throw re;
} catch (StandardException se) {
if (SanityManager.DEBUG) {
// do not want to catch lock timeout errors here
if (se.getSQLState().equals("XSRS9")) {
StringBuffer strbuf = new StringBuffer("Error retrieving base row in table " + ti.getTableName());
strbuf.append(": A StandardException was thrown when trying to locate a row matching index row " + indexRow1 + " from index " + ti.getIndexName(indexId) + ", conglom number " + ti.getIndexConglomerate(indexId));
debugGenerateInfo(strbuf, tc, heapCC, ti, indexId);
}
}
throw se;
}
if (SanityManager.DEBUG) {
// holding scan cursor on index at ISOLATION_REPEATABLE_READ.
if (!base_row_exists && (isolationLevel == TransactionController.ISOLATION_REPEATABLE_READ)) {
StringBuffer strbuf = new StringBuffer("Error retrieving base row in table " + ti.getTableName());
strbuf.append(": could not locate a row matching index row " + indexRow1 + " from index " + ti.getIndexName(indexId) + ", conglom number " + ti.getIndexConglomerate(indexId));
debugGenerateInfo(strbuf, tc, heapCC, ti, indexId);
// RESOLVE: for now, we are going to kill the VM
// to help debug this problem.
System.exit(1);
// RESOLVE: not currently reached
// SanityManager.THROWASSERT(strbuf.toString());
}
}
if (!base_row_exists && (isolationLevel == TransactionController.ISOLATION_READ_UNCOMMITTED)) {
// If isolationLevel == ISOLATION_READ_UNCOMMITTED we may
// possibly see that the base row does not exist even if the
// index row did. This mode is currently only used by
// TableNameInfo's call to hashAllTableDescriptorsByTableId,
// cf. DERBY-3678, and by getStatisticsDescriptors,
// cf. DERBY-4881.
//
// For the former call, a table's schema descriptor is attempted
// read, and if the base row for the schema has gone between
// reading the index and the base table, the table that needs
// this information has gone, too. So, the table should not
// be needed for printing lock timeout or deadlock
// information, so we can safely just return an empty (schema)
// descriptor. Furthermore, neither Timeout or DeadLock
// diagnostics access the schema of a table descriptor, so it
// seems safe to just return an empty schema descriptor for
// the table.
//
// There is a theoretical chance another row may have taken
// the first one's place, but only if a compress of the base
// table managed to run between the time we read the index and
// the base row, which seems unlikely so we ignore that.
//
// Even the index row may be gone in the above use case, of
// course, and that case also returns an empty descriptor
// since no match is found.
td = null;
} else {
// normal case
td = returnType.cast(rf.buildDescriptor(outRow, parentTupleDescriptor, this));
}
/* If list is null, then caller only wants a single descriptor - we're done
* else just add the current descriptor to the list.
*/
if (list == null) {
break;
} else if (td != null) {
list.add(td);
}
}
scanController.close();
heapCC.close();
return td;
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class DataDictionaryImpl method getSPSDescriptor.
/**
* Get a SPSDescriptor given its UUID.
*
* @param uuid The UUID
*
* @return The SPSDescriptor for the constraint.
*
* @exception StandardException Thrown on failure
*/
public SPSDescriptor getSPSDescriptor(UUID uuid) throws StandardException {
SPSDescriptor sps;
/* Make sure that non-core info is initialized */
getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM);
/* Only use the cache if we're in compile-only mode */
if ((spsNameCache != null) && (getCacheMode() == DataDictionary.COMPILE_ONLY_MODE)) {
sps = spsIdHash.get(uuid);
if (sps != null) {
return sps;
}
sps = getSPSDescriptorIndex2Scan(uuid.toString());
TableKey stmtKey = new TableKey(sps.getSchemaDescriptor().getUUID(), sps.getName());
try {
SPSNameCacheable cacheEntry = (SPSNameCacheable) spsNameCache.create(stmtKey, sps);
spsNameCache.release(cacheEntry);
} catch (StandardException se) {
/*
** If the error is that the item is already
** in the cache, then that is ok.
*/
if (SQLState.OBJECT_EXISTS_IN_CACHE.equals(se.getMessageId())) {
return sps;
} else {
throw se;
}
}
} else {
sps = getSPSDescriptorIndex2Scan(uuid.toString());
}
return sps;
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class DataDictionaryImpl method startReading.
/*
** Methods related to ModuleControl
*/
/**
* @see org.apache.derby.iapi.sql.dictionary.DataDictionary#startReading
*
* @exception StandardException Thrown on error
*/
public int startReading(LanguageConnectionContext lcc) throws StandardException {
int bindCount = lcc.incrementBindCount();
int localCacheMode;
boolean needRetry = false;
do {
if (needRetry) {
try {
lockFactory.zeroDurationlockObject(lcc.getTransactionExecute().getLockSpace(), cacheCoordinator, ShExQual.SH, C_LockFactory.WAIT_FOREVER);
} catch (StandardException e) {
// DEADLOCK, timeout will not happen with WAIT_FOREVER
lcc.decrementBindCount();
throw e;
}
needRetry = false;
}
synchronized (this) {
localCacheMode = getCacheMode();
/*
** Keep track of how deeply nested this bind() operation is.
** It's possible for nested binding to happen if the user
** prepares SQL statements from within a static initializer
** of a class, and calls a method on that class (or uses a
** field in the class).
**
** If nested binding is happening, we only want to lock the
** DataDictionary on the outermost nesting level.
*/
if (bindCount == 1) {
if (localCacheMode == DataDictionary.COMPILE_ONLY_MODE) {
if (SanityManager.DEBUG) {
SanityManager.ASSERT(ddlUsers == 0, "Cache mode is COMPILE_ONLY and there are DDL users.");
}
/*
** If we deadlock while waiting for a lock,
** then be sure to restore things as they
** were.
*/
boolean lockGranted = false;
try {
// When the C_LockFactory.NO_WAIT is used this
// routine will not throw timeout or deadlock
// exceptions. The boolean returned will indicate
// if the lock was granted or not. If it would
// have had to wait, it just returns immediately
// and returns false.
//
// See if we can get this lock granted without
// waiting (while holding the dataDictionary
// synchronization).
CompatibilitySpace space = lcc.getTransactionExecute().getLockSpace();
lockGranted = lockFactory.lockObject(space, space.getOwner(), cacheCoordinator, ShExQual.SH, C_LockFactory.NO_WAIT);
} catch (StandardException e) {
// neither TIMEOUT or DEADLOCK can happen with
// NO_WAIT flag. This must be some other exception.
lcc.decrementBindCount();
throw e;
}
if (!lockGranted)
needRetry = true;
} else {
readersInDDLMode++;
}
}
}
// end of sync block
} while (needRetry);
return localCacheMode;
}
use of org.apache.derby.shared.common.error.StandardException in project derby by apache.
the class GenericParameter method throwInvalidOutParamMap.
private StandardException throwInvalidOutParamMap(int sqlType) {
// TypeId typeId = TypeId.getBuiltInTypeId(sqlType);
// String sqlTypeName = typeId == null ? "OTHER" : typeId.getSQLTypeName();
String jdbcTypesName = org.apache.derby.impl.jdbc.Util.typeName(sqlType);
TypeId typeId = TypeId.getBuiltInTypeId(jdbcTypeId);
String thisTypeName = typeId == null ? declaredClassName : typeId.getSQLTypeName();
StandardException e = StandardException.newException(SQLState.LANG_INVALID_OUT_PARAM_MAP, getJDBCParameterNumberStr(), jdbcTypesName, thisTypeName);
return e;
}
Aggregations