Search in sources :

Example 76 with UUID

use of org.apache.derby.catalog.UUID in project derby by apache.

the class DDLStatementNode method getSchemaDescriptor.

/**
 * Get a schema descriptor for this DDL object.
 * Uses this.objectName.  Always returns a schema,
 * we lock in the schema name prior to execution.
 *
 * The most common call to this method is with 2nd
 * parameter true which says that SchemaDescriptor
 * should not be requested for system schema. The only
 * time this method will get called with 2nd parameter
 * set to false will be when user has requested for
 * inplace compress using
 * SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE
 * Above inplace compress can be invoked on system tables.
 * A call to SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE
 * internally gets translated into ALTER TABLE sql.
 * When ALTER TABLE is executed for SYSCS_INPLACE_COMPRESS_TABLE,
 * we want to allow SchemaDescriptor request for system
 * tables. DERBY-1062
 *
 * @param ownerCheck		If check for schema owner is needed
 * @param doSystemSchemaCheck   If check for system schema is needed.
 *    If set to true, then throw an exception if schema descriptor
 *    is requested for a system schema. The only time this param
 *    will be set to false is when user is asking for inplace
 *    compress of a system table. DERBY-1062
 *
 * @return Schema Descriptor
 *
 * @exception	StandardException	throws on schema name
 *						that doesn't exist
 */
protected final SchemaDescriptor getSchemaDescriptor(boolean ownerCheck, boolean doSystemSchemaCheck) throws StandardException {
    String schemaName = tableName.getSchemaName();
    // boolean needError = !(implicitCreateSchema || (schemaName == null));
    boolean needError = !implicitCreateSchema;
    SchemaDescriptor sd = getSchemaDescriptor(schemaName, needError);
    CompilerContext cc = getCompilerContext();
    if (sd == null) {
        /* Disable creating schemas starting with SYS */
        if (schemaName.startsWith("SYS"))
            throw StandardException.newException(SQLState.LANG_NO_USER_DDL_IN_SYSTEM_SCHEMA, statementToString(), schemaName);
        sd = new SchemaDescriptor(getDataDictionary(), schemaName, (String) null, (UUID) null, false);
        if (isPrivilegeCollectionRequired())
            cc.addRequiredSchemaPriv(schemaName, null, Authorizer.CREATE_SCHEMA_PRIV);
    }
    if (ownerCheck && isPrivilegeCollectionRequired())
        cc.addRequiredSchemaPriv(sd.getSchemaName(), null, Authorizer.MODIFY_SCHEMA_PRIV);
    /*
		** Catch the system schema here if the caller wants us to.
		** Currently, the only time we allow system schema is for inplace
		** compress table calls.
		*/
    if (doSystemSchemaCheck && sd.isSystemSchema()) {
        throw StandardException.newException(SQLState.LANG_NO_USER_DDL_IN_SYSTEM_SCHEMA, statementToString(), sd);
    }
    return sd;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext) UUID(org.apache.derby.catalog.UUID)

Example 77 with UUID

use of org.apache.derby.catalog.UUID 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 78 with UUID

use of org.apache.derby.catalog.UUID in project derby by apache.

the class SYSSTATEMENTSRowFactory method makeSYSSTATEMENTSrow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSSTATEMENTS row.
 * <p>
 * <B>WARNING</B>: When empty row is true, this method takes
 * a snapshot of the SPSD and creates a row.  It is imperative
 * that that row remain consistent with the descriptor (the
 * valid and StorablePreparedStatement fields must be in sync).
 * If this row is to be written out and valid is true, then
 * this call and the insert should be synchronized on the
 * SPSD. This method has <B>NO</B> synchronization.
 *
 * @param compileMe			passed into SPSDescriptorImpl.getPreparedStatement().
 *							if true, we (re)compile the stmt
 * @param spsDescriptor		In-memory tuple to be converted to a disk row.
 *
 * @return	Row suitable for inserting into SYSSTATEMENTS.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeSYSSTATEMENTSrow(boolean compileMe, SPSDescriptor spsDescriptor) throws StandardException {
    DataTypeDescriptor dtd;
    ExecRow row;
    DataValueDescriptor col;
    String name = null;
    UUID uuid = null;
    String uuidStr = null;
    // schema
    String suuidStr = null;
    // compilation schema
    String compUuidStr = null;
    String text = null;
    String usingText = null;
    ExecPreparedStatement preparedStatement = null;
    String typeStr = null;
    boolean valid = true;
    Timestamp time = null;
    boolean initiallyCompilable = true;
    if (spsDescriptor != null) {
        name = spsDescriptor.getName();
        uuid = spsDescriptor.getUUID();
        suuidStr = spsDescriptor.getSchemaDescriptor().getUUID().toString();
        uuidStr = uuid.toString();
        text = spsDescriptor.getText();
        valid = spsDescriptor.isValid();
        time = spsDescriptor.getCompileTime();
        typeStr = spsDescriptor.getTypeAsString();
        initiallyCompilable = spsDescriptor.initiallyCompilable();
        preparedStatement = spsDescriptor.getPreparedStatement(compileMe);
        compUuidStr = (spsDescriptor.getCompSchemaId() != null) ? spsDescriptor.getCompSchemaId().toString() : null;
        usingText = spsDescriptor.getUsingText();
    }
    /* Build the row to insert */
    row = getExecutionFactory().getValueRow(SYSSTATEMENTS_COLUMN_COUNT);
    /* 1st column is STMTID */
    row.setColumn(1, new SQLChar(uuidStr));
    /* 2nd column is STMTNAME */
    row.setColumn(2, new SQLVarchar(name));
    /* 3rd column is SCHEMAID */
    row.setColumn(3, new SQLChar(suuidStr));
    /* 4th column is TYPE */
    row.setColumn(4, new SQLChar(typeStr));
    /* 5th column is VALID */
    row.setColumn(5, new SQLBoolean(valid));
    /* 6th column is TEXT */
    row.setColumn(6, dvf.getLongvarcharDataValue(text));
    /* 7th column is LASTCOMPILED */
    row.setColumn(7, new SQLTimestamp(time));
    /* 8th column is COMPILATIONSCHEMAID */
    row.setColumn(8, new SQLChar(compUuidStr));
    /* 9th column is USINGTEXT */
    row.setColumn(9, dvf.getLongvarcharDataValue(usingText));
    /* 
		** 10th column is CONSTANTSTATE
		**
		** CONSTANTSTATE is really a formatable StorablePreparedStatement.
		*/
    row.setColumn(10, new UserType(preparedStatement));
    /* 11th column is INITIALLY_COMPILABLE */
    row.setColumn(11, new SQLBoolean(initiallyCompilable));
    return row;
}
Also used : DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) Timestamp(java.sql.Timestamp) ExecPreparedStatement(org.apache.derby.iapi.sql.execute.ExecPreparedStatement) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID) UserType(org.apache.derby.iapi.types.UserType) SQLBoolean(org.apache.derby.iapi.types.SQLBoolean)

Example 79 with UUID

use of org.apache.derby.catalog.UUID in project derby by apache.

the class SYSTABLESRowFactory method makeRow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSTABLES row
 *
 * @return	Row suitable for inserting into SYSTABLES.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    UUID oid;
    String tabSType = null;
    int tabIType;
    ExecRow row;
    String lockGranularity = null;
    String tableID = null;
    String schemaID = null;
    String tableName = null;
    if (td != null) {
        /*
			** We only allocate a new UUID if the descriptor doesn't already have one.
			** For descriptors replicated from a Source system, we already have an UUID.
			*/
        TableDescriptor descriptor = (TableDescriptor) td;
        SchemaDescriptor schema = (SchemaDescriptor) parent;
        oid = descriptor.getUUID();
        if (oid == null) {
            oid = getUUIDFactory().createUUID();
            descriptor.setUUID(oid);
        }
        tableID = oid.toString();
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(schema != null, "Schema should not be null unless empty row is true");
            if (schema.getUUID() == null) {
                SanityManager.THROWASSERT("schema " + schema + " has a null OID");
            }
        }
        schemaID = schema.getUUID().toString();
        tableName = descriptor.getName();
        /* RESOLVE - Table Type should really be a char in the descriptor
			 * T, S, V, S instead of 0, 1, 2, 3
			 */
        tabIType = descriptor.getTableType();
        switch(tabIType) {
            case TableDescriptor.BASE_TABLE_TYPE:
                tabSType = "T";
                break;
            case TableDescriptor.SYSTEM_TABLE_TYPE:
                tabSType = "S";
                break;
            case TableDescriptor.VIEW_TYPE:
                tabSType = "V";
                break;
            case TableDescriptor.SYNONYM_TYPE:
                tabSType = "A";
                break;
            default:
                if (SanityManager.DEBUG)
                    SanityManager.THROWASSERT("invalid table type");
        }
        char[] lockGChar = new char[1];
        lockGChar[0] = descriptor.getLockGranularity();
        lockGranularity = new String(lockGChar);
    }
    /* Insert info into systables */
    /* RESOLVE - It would be nice to require less knowledge about systables
		 * and have this be more table driven.
		 */
    /* Build the row to insert  */
    row = getExecutionFactory().getValueRow(SYSTABLES_COLUMN_COUNT);
    /* 1st column is TABLEID (UUID - char(36)) */
    row.setColumn(SYSTABLES_TABLEID, new SQLChar(tableID));
    /* 2nd column is NAME (varchar(30)) */
    row.setColumn(SYSTABLES_TABLENAME, new SQLVarchar(tableName));
    /* 3rd column is TABLETYPE (char(1)) */
    row.setColumn(SYSTABLES_TABLETYPE, new SQLChar(tabSType));
    /* 4th column is SCHEMAID (UUID - char(36)) */
    row.setColumn(SYSTABLES_SCHEMAID, new SQLChar(schemaID));
    /* 5th column is LOCKGRANULARITY (char(1)) */
    row.setColumn(SYSTABLES_LOCKGRANULARITY, new SQLChar(lockGranularity));
    return row;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) UUID(org.apache.derby.catalog.UUID) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 80 with UUID

use of org.apache.derby.catalog.UUID in project derby by apache.

the class CompilerContextImpl method addRequiredColumnPriv.

/**
 * Add a column privilege to the list of used column privileges.
 *
 * @param column The column whose privileges we're interested in.
 */
public void addRequiredColumnPriv(ColumnDescriptor column) {
    if (// Using old style authorization
    requiredColumnPrivileges == null || currPrivType == Authorizer.NULL_PRIV || // Table privilege only
    currPrivType == Authorizer.DELETE_PRIV || // Table privilege only
    currPrivType == Authorizer.INSERT_PRIV || // Table privilege only
    currPrivType == Authorizer.TRIGGER_PRIV || currPrivType == Authorizer.EXECUTE_PRIV || column == null) {
        return;
    }
    /*
		* Note that to look up the privileges for this column,
		* we need to know what table the column is in. However,
		* not all ColumnDescriptor objects are associated with
		* a table object. Sometimes a ColumnDescriptor
		* describes a column but doesn't specify the table. An
		* example of this occurs in the set-clause of the
		* UPDATE statement in SQL, where we may have a
		* ColumnDescriptor which describes the expression that
		* is being used in the UPDATE statement to provide the
		* new value that will be computed by the UPDATE. In such a
		* case, there is no column privilege to be added, so we
		* just take an early return. DERBY-1583 has more details.
		*/
    TableDescriptor td = column.getTableDescriptor();
    if (td == null)
        return;
    if (td.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
        // no priv needed, it is per session anyway
        return;
    }
    UUID tableUUID = td.getUUID();
    // DERBY-4191
    if (currPrivType == Authorizer.MIN_SELECT_PRIV) {
        // If we are here for MIN_SELECT_PRIV requirement, then first
        // check if there is already a SELECT privilege requirement on any
        // of the columns in the table, or on the table itself. If yes,
        // then we do not need to add MIN_SELECT_PRIV requirement for the
        // table because that requirement is already getting satisfied with
        // the already existing SELECT privilege requirement.
        StatementTablePermission key = new StatementTablePermission(tableUUID, Authorizer.SELECT_PRIV);
        if (requiredColumnPrivileges.containsKey(key) || requiredTablePrivileges.containsKey(key)) {
            return;
        }
    }
    if (currPrivType == Authorizer.SELECT_PRIV) {
        // If we are here for SELECT_PRIV requirement, then first check
        // if there is already any MIN_SELECT_PRIV privilege required
        // on this table. If yes, then that requirement will be fulfilled
        // by the SELECT_PRIV requirement we are adding now. Because of
        // that, remove the MIN_SELECT_PRIV privilege requirement
        StatementTablePermission key = new StatementTablePermission(tableUUID, Authorizer.MIN_SELECT_PRIV);
        requiredColumnPrivileges.remove(key);
    }
    StatementTablePermission key = new StatementTablePermission(tableUUID, currPrivType);
    StatementColumnPermission tableColumnPrivileges = requiredColumnPrivileges.get(key);
    if (tableColumnPrivileges == null) {
        tableColumnPrivileges = new StatementColumnPermission(tableUUID, currPrivType, new FormatableBitSet(td.getNumberOfColumns()));
        requiredColumnPrivileges.put(key, tableColumnPrivileges);
    }
    tableColumnPrivileges.getColumns().set(column.getPosition() - 1);
}
Also used : StatementColumnPermission(org.apache.derby.iapi.sql.dictionary.StatementColumnPermission) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) UUID(org.apache.derby.catalog.UUID) StatementTablePermission(org.apache.derby.iapi.sql.dictionary.StatementTablePermission) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Aggregations

UUID (org.apache.derby.catalog.UUID)101 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)31 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)23 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)22 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)21 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)19 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)15 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)15 SQLChar (org.apache.derby.iapi.types.SQLChar)15 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)14 TransactionController (org.apache.derby.iapi.store.access.TransactionController)14 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)12 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)12 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)11 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)10 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)10 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)10 ArrayList (java.util.ArrayList)9 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)9 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)8