use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.
the class SystemProcedures method SYSCS_SET_XPLAIN_SCHEMA.
/**
* This procedure sets the current xplain schema.
* If the schema is not set, runtime statistics are captured as a
* textual stream printout. If it is set, statisitcs information is
* stored in that schema in user tables.
* @param schemaName May be an empty string.
* @throws SQLException
*/
public static void SYSCS_SET_XPLAIN_SCHEMA(String schemaName) throws SQLException, StandardException {
try {
// make sure that application code doesn't bypass security checks
// by calling this public entry point
SecurityUtil.authorize(Securable.SET_XPLAIN_SCHEMA);
} catch (StandardException se) {
throw PublicAPI.wrapStandardException(se);
}
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
TransactionController tc = lcc.getTransactionExecute();
if (schemaName == null || schemaName.trim().length() == 0) {
lcc.setXplainSchema(null);
return;
}
boolean statsSave = lcc.getRunTimeStatisticsMode();
lcc.setRunTimeStatisticsMode(false);
createXplainSchema(schemaName);
createXplainTable(lcc, schemaName, new XPLAINStatementDescriptor());
createXplainTable(lcc, schemaName, new XPLAINStatementTimingsDescriptor());
createXplainTable(lcc, schemaName, new XPLAINResultSetDescriptor());
createXplainTable(lcc, schemaName, new XPLAINResultSetTimingsDescriptor());
createXplainTable(lcc, schemaName, new XPLAINScanPropsDescriptor());
createXplainTable(lcc, schemaName, new XPLAINSortPropsDescriptor());
lcc.setRunTimeStatisticsMode(statsSave);
lcc.setXplainSchema(schemaName);
}
use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.
the class SystemProcedures method SYSCS_CREATE_USER.
/**
* Create a new user.
*/
public static void SYSCS_CREATE_USER(String userName, String password) throws SQLException {
userName = normalizeUserName(userName);
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
TransactionController tc = lcc.getTransactionExecute();
// can add them
try {
// make sure that application code doesn't bypass security checks
// by calling this public entry point
SecurityUtil.authorize(Securable.CREATE_USER);
DataDictionary dd = lcc.getDataDictionary();
String dbo = dd.getAuthorizationDatabaseOwner();
if (!dbo.equals(userName)) {
if (dd.getUser(dbo) == null) {
throw StandardException.newException(SQLState.DBO_FIRST);
}
} else // we are trying to create credentials for the DBO
{
String currentUser = lcc.getStatementContext().getSQLSessionContext().getCurrentUser();
if (!dbo.equals(currentUser)) {
throw StandardException.newException(SQLState.DBO_ONLY);
}
}
} catch (StandardException se) {
throw PublicAPI.wrapStandardException(se);
}
addUser(userName, password, tc);
}
use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.
the class StatementNode method lockTableForCompilation.
/* We need to get some kind of table lock (IX here) at the beginning of
* compilation of DMLModStatementNode and DDLStatementNode, to prevent the
* interference of insert/update/delete/DDL compilation and DDL execution,
* see beetle 3976, 4343, and $WS/language/SolutionsToConcurrencyIssues.txt
*/
protected TableDescriptor lockTableForCompilation(TableDescriptor td) throws StandardException {
DataDictionary dd = getDataDictionary();
/* we need to lock only if the data dictionary is in DDL cache mode
*/
if (dd.getCacheMode() == DataDictionary.DDL_MODE) {
ConglomerateController heapCC;
TransactionController tc = getLanguageConnectionContext().getTransactionCompile();
heapCC = tc.openConglomerate(td.getHeapConglomerateId(), false, TransactionController.OPENMODE_FORUPDATE | TransactionController.OPENMODE_FOR_LOCK_ONLY, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
heapCC.close();
/*
** Need to get TableDescriptor again after getting the lock, in
** case for example, a concurrent add column thread commits
** while we are binding.
*/
String tableName = td.getName();
td = getTableDescriptor(td.getName(), getSchemaDescriptor(td.getSchemaName()));
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);
}
}
return td;
}
use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.
the class SequenceUpdater method updateCurrentValueOnDisk.
// /////////////////////////////////////////////////////////////////////////////////
//
// DISK WRITING MINIONS
//
// /////////////////////////////////////////////////////////////////////////////////
/**
* <p>
* Update the value on disk. Does its work in a subtransaction of the user's
* execution transaction. If that fails, raises a TOO MUCH CONTENTION exception.
* </p>
*
* @return Returns true if the value was successfully updated, false if we lost a race with another session.
*/
public synchronized boolean updateCurrentValueOnDisk(Long oldValue, Long newValue) throws StandardException {
LanguageConnectionContext lcc = getLCC();
//
if (lcc == null) {
if (SanityManager.DEBUG) {
SanityManager.ASSERT(oldValue == null, "We should be flushing unused sequence values here.");
}
ContextService csf = getContextService();
ContextManager cm = csf.getCurrentContextManager();
AccessFactory af = _dd.af;
TransactionController dummyTransaction = af.getTransaction(cm);
boolean retval = updateCurrentValueOnDisk(dummyTransaction, oldValue, newValue, false);
dummyTransaction.commit();
dummyTransaction.destroy();
return retval;
}
TransactionController executionTransaction = lcc.getTransactionExecute();
TransactionController nestedTransaction = executionTransaction.startNestedUserTransaction(false, true);
if (nestedTransaction != null) {
boolean retval = false;
boolean escalateToParentTransaction = false;
try {
retval = updateCurrentValueOnDisk(nestedTransaction, oldValue, newValue, false);
} catch (StandardException se) {
if (!se.isLockTimeout()) {
if (se.isSelfDeadlock()) {
// We're blocked by a lock held by our parent transaction.
// Escalate into the parent transaction now. See DERBY-6554.
escalateToParentTransaction = true;
} else {
Monitor.logThrowable(se);
throw se;
}
}
} finally {
// DERBY-5494, if this commit does not flush log then an
// unorderly shutdown could lose the update. Do not use
// commitNoSync(), and store needs to flush user nested update
// transaction commits by default.
nestedTransaction.commit();
nestedTransaction.destroy();
if (escalateToParentTransaction) {
retval = updateCurrentValueOnDisk(executionTransaction, oldValue, newValue, false);
}
return retval;
}
}
throw tooMuchContentionException();
}
use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.
the class IndexRowToBaseRowResultSet method openCore.
//
// ResultSet interface (leftover from NoPutResultSet)
//
/**
* open this ResultSet.
*
* @exception StandardException thrown if cursor finished.
*/
public void openCore() throws StandardException {
boolean lockingRequired = false;
TransactionController tc;
// is access to open controlled and ensured valid.
if (SanityManager.DEBUG) {
SanityManager.ASSERT(!isOpen, "IndexRowToBaseRowResultSet already open");
}
beginTime = getCurrentTimeMillis();
source.openCore();
/* Get a ConglomerateController for the base conglomerate
* NOTE: We only need to acquire locks on the data pages when
* going through the index when we are at READ COMMITTED and
* the source is a BulkTableScan or HashScan. (The underlying
* row will not be guaranteed to be locked.)
*/
if (source.requiresRelocking()) {
lockingRequired = true;
}
tc = activation.getTransactionController();
int openMode;
int isolationLevel;
if (forUpdate) {
openMode = TransactionController.OPENMODE_FORUPDATE;
} else {
openMode = 0;
}
isolationLevel = source.getScanIsolationLevel();
if (!lockingRequired) {
// flag indicates that lock has already been acquired by access to
// the secondary index, and need not be gotten again in the base
// table.
openMode |= TransactionController.OPENMODE_SECONDARY_LOCKED;
}
/* Try to get the ConglomerateController from the activation
* first, for the case that we are part of an update or delete.
* If so, then the RowChangerImpl did the correct locking.
* If not there, then we go off and open it ourself.
*/
if (forUpdate) {
baseCC = activation.getHeapConglomerateController();
}
if (baseCC == null) {
baseCC = tc.openCompiledConglomerate(activation.getResultSetHoldability(), openMode, // consistent with FromBaseTable's updateTargetLockMode
TransactionController.MODE_RECORD, isolationLevel, scoci, dcoci);
closeBaseCCHere = true;
}
isOpen = true;
numOpens++;
openTime += getElapsedMillis(beginTime);
}
Aggregations