use of org.apache.derby.catalog.UUID in project derby by apache.
the class JarUtil method drop.
/**
* Drop a jar file from the current connection's database.
*
* <P> The reason for dropping the jar file in this private instance
* method is that it allows us to share set up logic with add and
* replace.
*
* @exception StandardException Opps
*/
private void drop() throws StandardException {
//
// Like create table we say we are writing before we read the dd
dd.startWriting(lcc);
FileInfoDescriptor fid = getInfo();
if (fid == null)
throw StandardException.newException(SQLState.LANG_FILE_DOES_NOT_EXIST, sqlName, schemaName);
String dbcp_s = PropertyUtil.getServiceProperty(lcc.getTransactionExecute(), Property.DATABASE_CLASSPATH);
if (dbcp_s != null) {
String[][] dbcp = IdUtil.parseDbClassPath(dbcp_s);
boolean found = false;
// a database classpath that is stored in the propert congomerate.
for (int ix = 0; ix < dbcp.length; ix++) if (dbcp.length == 2 && dbcp[ix][0].equals(schemaName) && dbcp[ix][1].equals(sqlName))
found = true;
if (found)
throw StandardException.newException(SQLState.LANG_CANT_DROP_JAR_ON_DB_CLASS_PATH_DURING_EXECUTION, IdUtil.mkQualifiedName(schemaName, sqlName), dbcp_s);
}
try {
notifyLoader(false);
dd.invalidateAllSPSPlans();
DependencyManager dm = dd.getDependencyManager();
dm.invalidateFor(fid, DependencyManager.DROP_JAR, lcc);
UUID id = fid.getUUID();
dd.dropFileInfoDescriptor(fid);
fr.remove(JarUtil.mkExternalName(id, schemaName, sqlName, fr.getSeparatorChar()), fid.getGenerationId());
} finally {
notifyLoader(true);
}
}
use of org.apache.derby.catalog.UUID in project derby by apache.
the class BaseDataFileFactory method privGetJBMSLockOnDB.
// Called from within a privilege block
private void privGetJBMSLockOnDB() throws StandardException {
boolean fileLockExisted = false;
String blownUUID = null;
StorageFile fileLock = storageFactory.newStorageFile(DB_LOCKFILE_NAME);
try {
// SECURITY PERMISSION MP1
if (fileLock.exists()) {
fileLockExisted = true;
// see what it says in case we cannot count on delete failing
// when someone else have an opened file descriptor.
// I may be blowing this JBMS's lock away
// SECURITY PERMISSION MP1
// SECURITY PERMISSION OP4
fileLockOnDB = fileLock.getRandomAccessFile("rw");
try {
blownUUID = fileLockOnDB.readUTF();
} catch (IOException ioe) {
// The previous owner of the lock may have died before
// finish writing its UUID down.
fileLockExisted = false;
}
fileLockOnDB.close();
fileLockOnDB = null;
// SECURITY PERMISSION OP5
if (!fileLock.delete()) {
throw StandardException.newException(SQLState.DATA_MULTIPLE_JBMS_ON_DB, databaseDirectory);
}
}
// if file does not exists, we grab it immediately - there is a
// possibility that some other JBMS got to it sooner than we do,
// check the UUID after we write it to make sure
// SECURITY PERMISSION MP1
// SECURITY PERMISSION OP5
fileLockOnDB = fileLock.getRandomAccessFile("rw");
fileLock.limitAccessToOwner();
// write it out for future reference
fileLockOnDB.writeUTF(myUUID.toString());
fileLockOnDB.sync();
fileLockOnDB.seek(0);
// check the UUID
UUID checkUUID = uuidFactory.recreateUUID(fileLockOnDB.readUTF());
if (!checkUUID.equals(myUUID)) {
throw StandardException.newException(SQLState.DATA_MULTIPLE_JBMS_ON_DB, databaseDirectory);
}
} catch (IOException ioe) {
// probably a read only db, don't do anything more
readOnly = true;
try {
if (fileLockOnDB != null)
fileLockOnDB.close();
} catch (IOException ioe2) {
/* did the best I could */
}
fileLockOnDB = null;
return;
}
if (fileLock.delete()) {
// if I can delete it while I am holding a opened file descriptor,
// then the file lock is unreliable - send out a warning if I
// have blown off another JBMS's lock on the DB
Object[] args = new Object[3];
args[0] = myUUID;
args[1] = databaseDirectory;
args[2] = blownUUID;
// Try the exlcusive file lock method approach available in jdk1.4 or
// above jvms where delete machanism does not reliably prevent
// double booting of derby databases. If we don't get a reliable
// exclusive lock still we send out a warning.
int exLockStatus = StorageFile.NO_FILE_LOCK_SUPPORT;
// about applying exclusive file lock mechanism
if (!throwDBlckException) {
exFileLock = storageFactory.newStorageFile(DB_EX_LOCKFILE_NAME);
exLockStatus = exFileLock.getExclusiveFileLock();
}
if (exLockStatus == StorageFile.NO_FILE_LOCK_SUPPORT) {
if (fileLockExisted && !throwDBlckException) {
String warningMsg = MessageService.getTextMessage(SQLState.DATA_MULTIPLE_JBMS_WARNING, args);
logMsg(warningMsg);
// RESOLVE - need warning support. Output to
// system.err.println rather than just send warning
// message to derby.log.
System.err.println(warningMsg);
}
}
// there to warn the next person
try {
// again
if (fileLockOnDB != null)
fileLockOnDB.close();
fileLockOnDB = fileLock.getRandomAccessFile("rw");
fileLock.limitAccessToOwner();
// write it out for future reference
fileLockOnDB.writeUTF(myUUID.toString());
fileLockOnDB.sync();
fileLockOnDB.close();
} catch (IOException ioe) {
try {
fileLockOnDB.close();
} catch (IOException ioe2) {
/* did the best I could */
}
} finally {
fileLockOnDB = null;
}
if (fileLockExisted && throwDBlckException) {
// now that we have reinstated the lock file.
throw StandardException.newException(SQLState.DATA_MULTIPLE_JBMS_FORCE_LOCK, args);
}
if (exLockStatus == StorageFile.EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE) {
throw StandardException.newException(SQLState.DATA_MULTIPLE_JBMS_ON_DB, databaseDirectory);
}
}
}
use of org.apache.derby.catalog.UUID in project derby by apache.
the class XPLAINSystemTableVisitor method doXPLAIN.
/**
* the interface method, which gets called by the Top-ResultSet, which starts
* the tree traversal.
*/
public void doXPLAIN(RunTimeStatistics rss, Activation activation) throws StandardException {
// save this activation
this.activation = activation;
// reset this visitor
reset();
// get the timings settings
considerTimingInformation = lcc.getStatisticsTiming();
// placeholder for the stmt timings UUID
UUID stmtTimingsUUID = null;
// 1. create new stmt timings descriptor
if (considerTimingInformation) {
stmtTimingsUUID = dd.getUUIDFactory().createUUID();
Timestamp endExeTS = rss.getEndExecutionTimestamp();
Timestamp beginExeTS = rss.getBeginExecutionTimestamp();
long exeTime;
if (endExeTS != null && beginExeTS != null) {
exeTime = endExeTS.getTime() - beginExeTS.getTime();
} else {
exeTime = 0;
}
stmtTimings = new XPLAINStatementTimingsDescriptor(// the Timing UUID
stmtTimingsUUID, // the Parse Time
rss.getParseTimeInMillis(), // the Bind Time
rss.getBindTimeInMillis(), // the Optimize Time
rss.getOptimizeTimeInMillis(), // the Generate Time
rss.getGenerateTimeInMillis(), // the Compile Time
rss.getCompileTimeInMillis(), // the Execute Time, TODO resolve why getExecutionTime() returns 0
exeTime, // the Begin Compilation TS
rss.getBeginCompilationTimestamp(), // the End Compilation TS
rss.getEndCompilationTimestamp(), // the Begin Execution TS
rss.getBeginExecutionTimestamp(), // the End Execution TS
rss.getEndExecutionTimestamp());
}
// 2. create new Statement Descriptor
// create new UUID
stmtUUID = dd.getUUIDFactory().createUUID();
// extract stmt type
String type = XPLAINUtil.getStatementType(rss.getStatementText());
// TODO improve usability to switch between call stmt explanation on or off
if (type.equalsIgnoreCase("C") && no_call_stmts)
return;
// get transaction ID
String xaID = lcc.getTransactionExecute().getTransactionIdString();
// get session ID
String sessionID = Integer.toString(lcc.getInstanceNumber());
// get the JVM ID
String jvmID = Integer.toString(JVMInfo.JDK_ID);
// get the OS ID
String osID = System.getProperty("os.name");
// the current system time
long current = System.currentTimeMillis();
// the xplain type
String XPLAINtype = lcc.getXplainOnlyMode() ? XPLAINUtil.XPLAIN_ONLY : XPLAINUtil.XPLAIN_FULL;
// the xplain time
Timestamp time = new Timestamp(current);
// the thread id
String threadID = Thread.currentThread().toString();
stmt = new XPLAINStatementDescriptor(// unique statement UUID
stmtUUID, // the statement name
rss.getStatementName(), // the statement type
type, // the statement text
rss.getStatementText(), // the JVM ID
jvmID, // the OS ID
osID, // the EXPLAIN tpye
XPLAINtype, // the EXPLAIN Timestamp
time, // the Thread ID
threadID, // the transaction ID
xaID, // the Session ID
sessionID, // the Database name
lcc.getDbname(), // the DRDA ID
lcc.getDrdaID(), // Timing ID, if available
stmtTimingsUUID);
try {
// add it to system catalog
addStmtDescriptorsToSystemCatalog();
// get TopRSS and start the traversal of the RSS-tree
rss.acceptFromTopResultSet(this);
// add the filled lists to the dictionary
addArraysToSystemCatalogs();
} catch (SQLException e) {
throw StandardException.plainWrapException(e);
}
// clean up to free kept resources
clean();
}
use of org.apache.derby.catalog.UUID in project derby by apache.
the class XPLAINSystemTableVisitor method visit.
/**
* Visit this node, calling back to it to get details.
*
* This method visits the RS Statisitcs node, calling back to the
* node to get detailed descriptor information about it.
*/
public void visit(ResultSetStatistics statistics) {
UUID timingID = null;
if (considerTimingInformation) {
timingID = dd.getUUIDFactory().createUUID();
rsetsTimings.add(statistics.getResultSetTimingsDescriptor(timingID));
}
UUID sortID = dd.getUUIDFactory().createUUID();
XPLAINSortPropsDescriptor sortRSDescriptor = (XPLAINSortPropsDescriptor) statistics.getSortPropsDescriptor(sortID);
if (sortRSDescriptor != null)
sortrsets.add(sortRSDescriptor);
else
sortID = null;
UUID scanID = dd.getUUIDFactory().createUUID();
XPLAINScanPropsDescriptor scanRSDescriptor = (XPLAINScanPropsDescriptor) statistics.getScanPropsDescriptor(scanID);
if (scanRSDescriptor != null)
scanrsets.add(scanRSDescriptor);
else
scanID = null;
UUID rsID = dd.getUUIDFactory().createUUID();
rsets.add((XPLAINResultSetDescriptor) statistics.getResultSetDescriptor(rsID, UUIDStack.empty() ? (UUID) null : UUIDStack.pop(), scanID, sortID, stmtUUID, timingID));
pushUUIDnoChildren(rsID);
}
use of org.apache.derby.catalog.UUID in project derby by apache.
the class ForeignKeyRIChecker method doCheck.
/**
* Check that the row either has a null column(s), or
* corresponds to a row in the referenced key.
* <p>
* If the referenced key is found, then it is locked
* when this method returns. The lock is held until
* the next call to doCheck() or close().
*
* @param a the activation
* @param row the row to check
* @param restrictCheckOnly
* {@code true} if the check is relevant only for RESTRICTED
* referential action.
* @param deferredRowReq
* dummy (interface obligation only)
*
* @exception StandardException on unexpected error, or
* on a foreign key violation
*/
void doCheck(Activation a, ExecRow row, boolean restrictCheckOnly, int deferredRowReq) throws StandardException {
if (// RESTRICT rule checks are not valid here.
restrictCheckOnly)
return;
/*
** If any of the columns are null, then the
** check always succeeds.
*/
if (isAnyFieldNull(row)) {
return;
}
/*
** Otherwise, we had better find this row in the
** referenced key
*/
ScanController scan = getScanController(fkInfo.refConglomNumber, refScoci, refDcoci, row);
if (!scan.next()) {
final UUID fkId = fkInfo.fkIds[0];
close();
if (fkInfo.deferrable[0] && lcc.isEffectivelyDeferred(lcc.getCurrentSQLSessionContext(a), fkId)) {
deferredRowsHashTable = DeferredConstraintsMemory.rememberFKViolation(lcc, deferredRowsHashTable, fkInfo.fkIds[0], indexQualifierRow.getRowArray(), fkInfo.schemaName, fkInfo.tableName);
} else {
StandardException se = StandardException.newException(SQLState.LANG_FK_VIOLATION, fkInfo.fkConstraintNames[0], fkInfo.tableName, StatementUtil.typeName(fkInfo.stmtType), RowUtil.toString(row, fkInfo.colArray));
throw se;
}
}
/*
** If we found the row, we are currently positioned on
** the row when we leave this method. So we hold the
** lock on the referenced key, which is very important.
*/
}
Aggregations