use of org.apache.derby.iapi.sql.dictionary.DataDictionary in project derby by apache.
the class DropTriggerConstantAction method executeConstantAction.
/**
* This is the guts of the Execution-time logic for DROP STATEMENT.
*
* @see ConstantAction#executeConstantAction
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
TriggerDescriptor triggerd;
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
/*
** Inform the data dictionary that we are about to write to it.
** There are several calls to data dictionary "get" methods here
** that might be done in "read" mode in the data dictionary, but
** it seemed safer to do this whole operation in "write" mode.
**
** We tell the data dictionary we're done writing at the end of
** the transaction.
*/
dd.startWriting(lcc);
TableDescriptor td = dd.getTableDescriptor(tableId);
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableId.toString());
}
TransactionController tc = lcc.getTransactionExecute();
lockTableForDDL(tc, td.getHeapConglomerateId(), true);
// get td again in case table shape is changed before lock is acquired
td = dd.getTableDescriptor(tableId);
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableId.toString());
}
/*
** Get the trigger descriptor. We're responsible for raising
** the error if it isn't found
*/
triggerd = dd.getTriggerDescriptor(triggerName, sd);
if (triggerd == null) {
throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND_DURING_EXECUTION, "TRIGGER", (sd.getSchemaName() + "." + triggerName));
}
/*
** 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/trigger that the user is attempting to
** drop.) If no one objects, then invalidate any dependent objects.
*/
triggerd.drop(lcc);
}
use of org.apache.derby.iapi.sql.dictionary.DataDictionary in project derby by apache.
the class DropViewConstantAction method executeConstantAction.
// INTERFACE METHODS
/**
* This is the guts of the Execution-time logic for DROP VIEW.
*
* @see ConstantAction#executeConstantAction
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
TableDescriptor td;
ViewDescriptor vd;
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
/*
** Inform the data dictionary that we are about to write to it.
** There are several calls to data dictionary "get" methods here
** that might be done in "read" mode in the data dictionary, but
** it seemed safer to do this whole operation in "write" mode.
**
** We tell the data dictionary we're done writing at the end of
** the transaction.
*/
dd.startWriting(lcc);
/* Get the table descriptor. We're responsible for raising
* the error if it isn't found
*/
td = dd.getTableDescriptor(tableName, sd, lcc.getTransactionExecute());
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, fullTableName);
}
/* Verify that TableDescriptor represents a view */
if (td.getTableType() != TableDescriptor.VIEW_TYPE) {
throw StandardException.newException(SQLState.LANG_DROP_VIEW_ON_NON_VIEW, fullTableName);
}
vd = dd.getViewDescriptor(td);
vd.drop(lcc, sd, td);
}
use of org.apache.derby.iapi.sql.dictionary.DataDictionary in project derby by apache.
the class SystemProcedures method SYSCS_DROP_USER.
/**
* Drop a user.
*/
public static void SYSCS_DROP_USER(String userName) throws SQLException {
userName = normalizeUserName(userName);
try {
// make sure that application code doesn't bypass security checks
// by calling this public entry point
SecurityUtil.authorize(Securable.DROP_USER);
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
DataDictionary dd = lcc.getDataDictionary();
String dbo = dd.getAuthorizationDatabaseOwner();
// you can't drop the credentials of the dbo
if (dbo.equals(userName)) {
throw StandardException.newException(SQLState.CANT_DROP_DBO);
}
checkLegalUser(dd, userName);
/*
** Inform the data dictionary that we are about to write to it.
** There are several calls to data dictionary "get" methods here
** that might be done in "read" mode in the data dictionary, but
** it seemed safer to do this whole operation in "write" mode.
**
** We tell the data dictionary we're done writing at the end of
** the transaction.
*/
dd.startWriting(lcc);
dd.dropUser(userName, lcc.getTransactionExecute());
} catch (StandardException se) {
throw PublicAPI.wrapStandardException(se);
}
}
use of org.apache.derby.iapi.sql.dictionary.DataDictionary in project derby by apache.
the class SystemProcedures method SYSCS_INVALIDATE_STORED_STATEMENTS.
/**
* Invalidate all the stored statements so they will get recompiled when
* executed next time around.
*/
public static void SYSCS_INVALIDATE_STORED_STATEMENTS() throws SQLException {
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
DataDictionary dd = lcc.getDataDictionary();
try {
// make sure that application code doesn't bypass security checks
// by calling this public entry point
SecurityUtil.authorize(Securable.INVALIDATE_STORED_STATEMENTS);
dd.invalidateAllSPSPlans(lcc);
} catch (StandardException se) {
throw PublicAPI.wrapStandardException(se);
}
}
use of org.apache.derby.iapi.sql.dictionary.DataDictionary 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);
}
Aggregations