Search in sources :

Example 76 with DataDictionary

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);
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) TriggerDescriptor(org.apache.derby.iapi.sql.dictionary.TriggerDescriptor)

Example 77 with DataDictionary

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);
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ViewDescriptor(org.apache.derby.iapi.sql.dictionary.ViewDescriptor)

Example 78 with DataDictionary

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);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Example 79 with DataDictionary

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);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Example 80 with DataDictionary

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);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) TransactionController(org.apache.derby.iapi.store.access.TransactionController) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Aggregations

DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)102 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)57 TransactionController (org.apache.derby.iapi.store.access.TransactionController)40 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)33 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)23 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)22 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)17 StandardException (org.apache.derby.shared.common.error.StandardException)16 UUID (org.apache.derby.catalog.UUID)15 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)15 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)13 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)10 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)9 RoleGrantDescriptor (org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)8 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)7 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)7 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)7 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)6 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)6 Iterator (java.util.Iterator)5