Search in sources :

Example 26 with DataDescriptorGenerator

use of org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator in project derby by apache.

the class SYSSTATEMENTSRowFactory method buildDescriptor.

// /////////////////////////////////////////////////////////////////////////
// 
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
// 
// /////////////////////////////////////////////////////////////////////////
/**
 * Make an  Tuple Descriptor out of a SYSSTATEMENTS row
 *
 * @param row 					a SYSSTATEMENTS row
 * @param parentTupleDescriptor	unused
 * @param dd 					dataDictionary
 *
 * @return	a  descriptor equivalent to a SYSSTATEMENTS row
 *
 * @exception   StandardException thrown on failure
 */
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
    DataValueDescriptor col;
    SPSDescriptor descriptor;
    String name;
    String text;
    String usingText;
    UUID uuid;
    UUID compUuid = null;
    String uuidStr;
    // schema
    UUID suuid;
    // schema
    String suuidStr;
    String typeStr;
    char type;
    boolean valid;
    Timestamp time = null;
    ExecPreparedStatement preparedStatement = null;
    boolean initiallyCompilable;
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(row.nColumns() == SYSSTATEMENTS_COLUMN_COUNT, "Wrong number of columns for a SYSSTATEMENTS row");
    }
    // 1st column is STMTID (UUID - char(36))
    col = row.getColumn(1);
    uuidStr = col.getString();
    uuid = getUUIDFactory().recreateUUID(uuidStr);
    // 2nd column is STMTNAME (varchar(128))
    col = row.getColumn(2);
    name = col.getString();
    // 3rd column is SCHEMAID (UUID - char(36))
    col = row.getColumn(3);
    suuidStr = col.getString();
    suuid = getUUIDFactory().recreateUUID(suuidStr);
    // 4th column is TYPE (char(1))
    col = row.getColumn(4);
    type = col.getString().charAt(0);
    if (SanityManager.DEBUG) {
        if (!SPSDescriptor.validType(type)) {
            SanityManager.THROWASSERT("Bad type value (" + type + ") for  statement " + name);
        }
    }
    // so force a recompile.
    if (dd.isReadOnlyUpgrade()) {
        valid = false;
    } else {
        // 5th column is VALID (boolean)
        col = row.getColumn(5);
        valid = col.getBoolean();
    }
    // 6th column is TEXT (LONG VARCHAR)
    col = row.getColumn(6);
    text = col.getString();
    /* 7th column is LASTCOMPILED (TIMESTAMP) */
    col = row.getColumn(7);
    time = col.getTimestamp(new java.util.GregorianCalendar());
    // 8th column is COMPILATIONSCHEMAID (UUID - char(36))
    col = row.getColumn(8);
    uuidStr = col.getString();
    if (uuidStr != null)
        compUuid = getUUIDFactory().recreateUUID(uuidStr);
    // 9th column is TEXT (LONG VARCHAR)
    col = row.getColumn(9);
    usingText = col.getString();
    // Only load the compiled plan if the statement is valid
    if (valid) {
        col = row.getColumn(10);
        preparedStatement = (ExecPreparedStatement) col.getObject();
    }
    // 11th column is INITIALLY_COMPILABLE (boolean)
    col = row.getColumn(11);
    if (col.isNull()) {
        initiallyCompilable = true;
    } else {
        initiallyCompilable = col.getBoolean();
    }
    descriptor = new SPSDescriptor(dd, name, uuid, suuid, compUuid, type, valid, text, usingText, time, preparedStatement, initiallyCompilable);
    return descriptor;
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) ExecPreparedStatement(org.apache.derby.iapi.sql.execute.ExecPreparedStatement) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID) Timestamp(java.sql.Timestamp) SPSDescriptor(org.apache.derby.iapi.sql.dictionary.SPSDescriptor)

Example 27 with DataDescriptorGenerator

use of org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator in project derby by apache.

the class SYSUSERSRowFactory method buildDescriptor.

// /////////////////////////////////////////////////////////////////////////
// 
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
// 
// /////////////////////////////////////////////////////////////////////////
/**
 * Make a descriptor out of a SYSUSERS row. The password column in the
 * row will be zeroed out.
 *
 * @param row a row
 * @param parentTupleDescriptor	Null for this kind of descriptor.
 * @param dd dataDictionary
 *
 * @return	a descriptor equivalent to a row
 *
 * @exception   StandardException thrown on failure
 */
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
    if (SanityManager.DEBUG) {
        if (row.nColumns() != SYSUSERS_COLUMN_COUNT) {
            SanityManager.THROWASSERT("Wrong number of columns for a SYSUSERS row: " + row.nColumns());
        }
    }
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    String userName;
    String hashingScheme;
    char[] password = null;
    Timestamp lastModified;
    DataValueDescriptor col;
    SQLVarchar passwordCol = null;
    UserDescriptor result;
    try {
        /* 1st column is USERNAME */
        col = row.getColumn(USERNAME_COL_NUM);
        userName = col.getString();
        /* 2nd column is HASHINGSCHEME */
        col = row.getColumn(HASHINGSCHEME_COL_NUM);
        hashingScheme = col.getString();
        /* 3nd column is PASSWORD */
        passwordCol = (SQLVarchar) row.getColumn(PASSWORD_COL_NUM);
        password = passwordCol.getRawDataAndZeroIt();
        /* 4th column is LASTMODIFIED */
        col = row.getColumn(LASTMODIFIED_COL_NUM);
        lastModified = col.getTimestamp(new java.util.GregorianCalendar());
        result = ddg.newUserDescriptor(userName, hashingScheme, password, lastModified);
    } finally {
        // zero out the password so that it can't be memory-sniffed
        if (password != null) {
            Arrays.fill(password, (char) 0);
        }
        if (passwordCol != null) {
            passwordCol.zeroRawData();
        }
    }
    return result;
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) SQLTimestamp(org.apache.derby.iapi.types.SQLTimestamp) Timestamp(java.sql.Timestamp) UserDescriptor(org.apache.derby.iapi.sql.dictionary.UserDescriptor)

Example 28 with DataDescriptorGenerator

use of org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator in project derby by apache.

the class RoutinePrivilegeInfo method executeGrantRevoke.

/**
 *	This is the guts of the Execution-time logic for GRANT/REVOKE of a routine execute privilege
 *
 * @param activation
 * @param grant true if grant, false if revoke
 * @param grantees a list of authorization ids (strings)
 *
 * @exception StandardException		Thrown on failure
 */
public void executeGrantRevoke(Activation activation, boolean grant, List grantees) throws StandardException {
    // Check that the current user has permission to grant the privileges.
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    String currentUser = lcc.getCurrentUserId(activation);
    TransactionController tc = lcc.getTransactionExecute();
    // Check that the current user has permission to grant the privileges.
    checkOwnership(currentUser, aliasDescriptor, dd.getSchemaDescriptor(aliasDescriptor.getSchemaUUID(), tc), dd);
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    RoutinePermsDescriptor routinePermsDesc = ddg.newRoutinePermsDescriptor(aliasDescriptor, currentUser);
    dd.startWriting(lcc);
    for (Iterator itr = grantees.iterator(); itr.hasNext(); ) {
        // Keep track to see if any privileges are revoked by a revoke
        // statement. If a privilege is not revoked, we need to raise a
        // warning.
        boolean privileges_revoked = false;
        String grantee = (String) itr.next();
        if (dd.addRemovePermissionsDescriptor(grant, routinePermsDesc, grantee, tc)) {
            privileges_revoked = true;
            // Derby currently supports only restrict form of revoke execute
            // privilege and that is why, we are sending invalidation action
            // as REVOKE_PRIVILEGE_RESTRICT rather than REVOKE_PRIVILEGE
            dd.getDependencyManager().invalidateFor(routinePermsDesc, DependencyManager.REVOKE_PRIVILEGE_RESTRICT, lcc);
            // When revoking a privilege from a Routine we need to
            // invalidate all GPSs refering to it. But GPSs aren't
            // Dependents of RoutinePermsDescr, but of the
            // AliasDescriptor itself, so we must send
            // INTERNAL_RECOMPILE_REQUEST to the AliasDescriptor's
            // Dependents.
            dd.getDependencyManager().invalidateFor(aliasDescriptor, DependencyManager.INTERNAL_RECOMPILE_REQUEST, lcc);
        }
        addWarningIfPrivilegeNotRevoked(activation, grant, privileges_revoked, grantee);
    }
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Iterator(java.util.Iterator) RoutinePermsDescriptor(org.apache.derby.iapi.sql.dictionary.RoutinePermsDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 29 with DataDescriptorGenerator

use of org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator in project derby by apache.

the class TablePrivilegeInfo method executeGrantRevoke.

/**
 *	This is the guts of the Execution-time logic for GRANT/REVOKE of a table privilege
 *
 * @param activation
 * @param grant true if grant, false if revoke
 * @param grantees a list of authorization ids (strings)
 *
 * @exception StandardException		Thrown on failure
 */
public void executeGrantRevoke(Activation activation, boolean grant, List grantees) throws StandardException {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    String currentUser = lcc.getCurrentUserId(activation);
    TransactionController tc = lcc.getTransactionExecute();
    SchemaDescriptor sd = td.getSchemaDescriptor();
    // Check that the current user has permission to grant the privileges.
    checkOwnership(currentUser, td, sd, dd, lcc, grant);
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    TablePermsDescriptor tablePermsDesc = ddg.newTablePermsDescriptor(td, getPermString(SELECT_ACTION, false), getPermString(DELETE_ACTION, false), getPermString(INSERT_ACTION, false), getPermString(UPDATE_ACTION, false), getPermString(REFERENCES_ACTION, false), getPermString(TRIGGER_ACTION, false), currentUser);
    ColPermsDescriptor[] colPermsDescs = new ColPermsDescriptor[columnBitSets.length];
    for (int i = 0; i < columnBitSets.length; i++) {
        if (columnBitSets[i] != null || // should be removed.
        (!grant) && hasColumnPermissions(i) && actionAllowed[i]) {
            colPermsDescs[i] = ddg.newColPermsDescriptor(td, getActionString(i, false), columnBitSets[i], currentUser);
        }
    }
    dd.startWriting(lcc);
    // Add or remove the privileges to/from the SYS.SYSTABLEPERMS and SYS.SYSCOLPERMS tables
    for (Iterator itr = grantees.iterator(); itr.hasNext(); ) {
        // Keep track to see if any privileges are revoked by a revoke
        // statement. If a privilege is not revoked, we need to raise a
        // warning. For table privileges, we do not check if privilege for
        // a specific action has been revoked or not. Also, we do not check
        // privileges for specific columns. If at least one privilege has
        // been revoked, we do not raise a warning. This has to be refined
        // further to check for specific actions/columns and raise warning
        // if any privilege has not been revoked.
        boolean privileges_revoked = false;
        String grantee = (String) itr.next();
        if (tablePermsDesc != null) {
            if (dd.addRemovePermissionsDescriptor(grant, tablePermsDesc, grantee, tc)) {
                privileges_revoked = true;
                dd.getDependencyManager().invalidateFor(tablePermsDesc, DependencyManager.REVOKE_PRIVILEGE, lcc);
                // When revoking a privilege from a Table we need to
                // invalidate all GPSs refering to it. But GPSs aren't
                // Dependents of TablePermsDescr, but of the
                // TableDescriptor itself, so we must send
                // INTERNAL_RECOMPILE_REQUEST to the TableDescriptor's
                // Dependents.
                dd.getDependencyManager().invalidateFor(td, DependencyManager.INTERNAL_RECOMPILE_REQUEST, lcc);
            }
        }
        for (int i = 0; i < columnBitSets.length; i++) {
            if (colPermsDescs[i] != null) {
                if (dd.addRemovePermissionsDescriptor(grant, colPermsDescs[i], grantee, tc)) {
                    privileges_revoked = true;
                    dd.getDependencyManager().invalidateFor(colPermsDescs[i], DependencyManager.REVOKE_PRIVILEGE, lcc);
                    // When revoking a privilege from a Table we need to
                    // invalidate all GPSs refering to it. But GPSs aren't
                    // Dependents of colPermsDescs[i], but of the
                    // TableDescriptor itself, so we must send
                    // INTERNAL_RECOMPILE_REQUEST to the TableDescriptor's
                    // Dependents.
                    dd.getDependencyManager().invalidateFor(td, DependencyManager.INTERNAL_RECOMPILE_REQUEST, lcc);
                }
            }
        }
        addWarningIfPrivilegeNotRevoked(activation, grant, privileges_revoked, grantee);
    }
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) ColPermsDescriptor(org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Iterator(java.util.Iterator) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) TablePermsDescriptor(org.apache.derby.iapi.sql.dictionary.TablePermsDescriptor)

Example 30 with DataDescriptorGenerator

use of org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator in project derby by apache.

the class DataDictionaryImpl method makeCatalog.

/**
 *	The dirty work of creating a catalog.
 *
 *	@param	ti			TabInfoImpl describing catalog to create.
 *	@param	sd			Schema to create catalogs in.
 *	@param	tc			Transaction context.
 *
 *	@exception StandardException Standard Derby error policy
 */
private void makeCatalog(TabInfoImpl ti, SchemaDescriptor sd, TransactionController tc) throws StandardException {
    DataDescriptorGenerator ddg = getDataDescriptorGenerator();
    Properties heapProperties = ti.getCreateHeapProperties();
    ti.setHeapConglomerate(createConglomerate(ti.getTableName(), tc, ti.getCatalogRowFactory().makeEmptyRowForCurrentVersion(), heapProperties));
    // bootstrap indexes on core tables before bootstrapping the tables themselves
    if (ti.getNumberOfIndexes() > 0) {
        bootStrapSystemIndexes(sd, tc, ddg, ti);
    }
    addSystemTableToDictionary(ti, sd, tc, ddg);
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) Properties(java.util.Properties)

Aggregations

DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)33 UUID (org.apache.derby.catalog.UUID)23 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)15 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)14 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)13 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)13 TransactionController (org.apache.derby.iapi.store.access.TransactionController)12 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)7 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)5 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)5 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)5 Timestamp (java.sql.Timestamp)4 Iterator (java.util.Iterator)4 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)4 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)4 Provider (org.apache.derby.iapi.sql.depend.Provider)3 SubKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor)3 Properties (java.util.Properties)2 ReferencedColumns (org.apache.derby.catalog.ReferencedColumns)2 TypeDescriptor (org.apache.derby.catalog.TypeDescriptor)2