Search in sources :

Example 56 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class DataDictionaryImpl method getConstraints.

/**
 * Return an List which of the relevant column matching
 * the indexed criteria.  If nothing matches, returns an
 * empty List (never returns null).
 *
 * @param uuid	The id of the constraint
 * @param indexId		The index id in SYS.SYSCONSTRAINTS
 * @param columnNum		The column to retrieve
 *
 * @return a list of UUIDs in an List.
 *
 * @exception StandardException		Thrown on error
 */
public List<UUID> getConstraints(UUID uuid, int indexId, int columnNum) throws StandardException {
    ExecIndexRow indexRow1;
    ExecRow outRow;
    RowLocation baseRowLocation;
    ConglomerateController heapCC = null;
    ScanController scanController = null;
    TransactionController tc;
    TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM);
    SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory();
    TableDescriptor td = null;
    List<UUID> slist = new ArrayList<UUID>();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(indexId == SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX1_ID || indexId == SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX3_ID, "bad index id, must be one of the indexes on a uuid");
        SanityManager.ASSERT(columnNum > 0 && columnNum <= SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_COLUMN_COUNT, "invalid column number for column to be retrieved");
    }
    try {
        /* Use tableIDOrderable in both start and stop positions for scan */
        DataValueDescriptor orderable = getIDValueAsCHAR(uuid);
        /* Set up the start/stop position for the scan */
        ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
        keyRow.setColumn(1, orderable);
        // Get the current transaction controller
        tc = getTransactionCompile();
        outRow = rf.makeEmptyRow();
        heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
        // create an index row template
        indexRow1 = getIndexRowFromHeapRow(ti.getIndexRowGenerator(indexId), heapCC.newRowLocationTemplate(), outRow);
        // just interested in one column
        DataValueDescriptor[] rowTemplate = new DataValueDescriptor[SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_COLUMN_COUNT];
        FormatableBitSet columnToGetSet = new FormatableBitSet(SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_COLUMN_COUNT);
        columnToGetSet.set(columnNum - 1);
        rowTemplate[columnNum - 1] = new SQLChar();
        // Scan the index and go to the data pages for qualifying rows
        scanController = tc.openScan(// conglomerate to open
        ti.getIndexConglomerate(indexId), // don't hold open across commit
        false, // for read
        0, TransactionController.MODE_RECORD, // RESOLVE: should be level 2
        TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
        (FormatableBitSet) null, // start position - exact key match.
        keyRow.getRowArray(), // startSearchOperation
        ScanController.GE, // scanQualifier (none)
        null, // stop position - exact key match.
        keyRow.getRowArray(), // stopSearchOperation
        ScanController.GT);
        while (scanController.fetchNext(indexRow1.getRowArray())) {
            baseRowLocation = (RowLocation) indexRow1.getColumn(indexRow1.nColumns());
            // get the row and grab the uuid
            boolean base_row_exists = heapCC.fetch(baseRowLocation, rowTemplate, columnToGetSet);
            if (SanityManager.DEBUG) {
                // it can not be possible for heap row to disappear while
                // holding scan cursor on index at ISOLATION_REPEATABLE_READ.
                SanityManager.ASSERT(base_row_exists, "base row not found");
            }
            slist.add(uuidFactory.recreateUUID((String) ((DataValueDescriptor) rowTemplate[columnNum - 1]).getObject()));
        }
    } finally {
        if (heapCC != null) {
            heapCC.close();
        }
        if (scanController != null) {
            scanController.close();
        }
    }
    return slist;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) ArrayList(java.util.ArrayList) SQLChar(org.apache.derby.iapi.types.SQLChar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) TransactionController(org.apache.derby.iapi.store.access.TransactionController) UUID(org.apache.derby.catalog.UUID) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 57 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class SYSALIASESRowFactory method makeRow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSALIASES row
 *
 * @return	Row suitable for inserting into SYSALIASES.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    DataValueDescriptor col;
    String schemaID = null;
    String javaClassName = null;
    String sAliasType = null;
    String aliasID = null;
    String aliasName = null;
    String specificName = null;
    char cAliasType = AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR;
    char cNameSpace = AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR;
    boolean systemAlias = false;
    AliasInfo aliasInfo = null;
    if (td != null) {
        AliasDescriptor ad = (AliasDescriptor) td;
        aliasID = ad.getUUID().toString();
        aliasName = ad.getDescriptorName();
        schemaID = ad.getSchemaUUID().toString();
        javaClassName = ad.getJavaClassName();
        cAliasType = ad.getAliasType();
        cNameSpace = ad.getNameSpace();
        systemAlias = ad.getSystemAlias();
        aliasInfo = ad.getAliasInfo();
        specificName = ad.getSpecificName();
        char[] charArray = new char[1];
        charArray[0] = cAliasType;
        sAliasType = new String(charArray);
        if (SanityManager.DEBUG) {
            switch(cAliasType) {
                case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
                case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
                case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
                case AliasInfo.ALIAS_TYPE_UDT_AS_CHAR:
                case AliasInfo.ALIAS_TYPE_AGGREGATE_AS_CHAR:
                    break;
                default:
                    SanityManager.THROWASSERT("Unexpected value (" + cAliasType + ") for aliasType");
            }
        }
    }
    /* Insert info into sysaliases */
    /* RESOLVE - It would be nice to require less knowledge about sysaliases
		 * and have this be more table driven.
		 */
    /* Build the row to insert */
    ExecRow row = getExecutionFactory().getValueRow(SYSALIASES_COLUMN_COUNT);
    /* 1st column is ALIASID (UUID - char(36)) */
    row.setColumn(SYSALIASES_ALIASID, new SQLChar(aliasID));
    /* 2nd column is ALIAS (varchar(128))) */
    row.setColumn(SYSALIASES_ALIAS, new SQLVarchar(aliasName));
    // System.out.println(" added row-- " + aliasName);
    /* 3rd column is SCHEMAID (UUID - char(36)) */
    row.setColumn(SYSALIASES_SCHEMAID, new SQLChar(schemaID));
    /* 4th column is JAVACLASSNAME (longvarchar) */
    row.setColumn(SYSALIASES_JAVACLASSNAME, dvf.getLongvarcharDataValue(javaClassName));
    /* 5th column is ALIASTYPE (char(1)) */
    row.setColumn(SYSALIASES_ALIASTYPE, new SQLChar(sAliasType));
    /* 6th column is NAMESPACE (char(1)) */
    String sNameSpace = new String(new char[] { cNameSpace });
    row.setColumn(SYSALIASES_NAMESPACE, new SQLChar(sNameSpace));
    /* 7th column is SYSTEMALIAS (boolean) */
    row.setColumn(SYSALIASES_SYSTEMALIAS, new SQLBoolean(systemAlias));
    /* 8th column is ALIASINFO (org.apache.derby.catalog.AliasInfo) */
    row.setColumn(SYSALIASES_ALIASINFO, new UserType(aliasInfo));
    /* 9th column is specific name */
    row.setColumn(SYSALIASES_SPECIFIC_NAME, new SQLVarchar(specificName));
    return row;
}
Also used : AliasInfo(org.apache.derby.catalog.AliasInfo) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) UserType(org.apache.derby.iapi.types.UserType) SQLBoolean(org.apache.derby.iapi.types.SQLBoolean)

Example 58 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class SYSCOLPERMSRowFactory method makeRow.

public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    UUID oid;
    String colPermID = null;
    DataValueDescriptor grantee = null;
    DataValueDescriptor grantor = null;
    String tableID = null;
    String type = null;
    FormatableBitSet columns = null;
    if (td == null) {
        grantee = getNullAuthorizationID();
        grantor = getNullAuthorizationID();
    } else {
        ColPermsDescriptor cpd = (ColPermsDescriptor) td;
        oid = cpd.getUUID();
        if (oid == null) {
            oid = getUUIDFactory().createUUID();
            cpd.setUUID(oid);
        }
        colPermID = oid.toString();
        grantee = getAuthorizationID(cpd.getGrantee());
        grantor = getAuthorizationID(cpd.getGrantor());
        tableID = cpd.getTableUUID().toString();
        type = cpd.getType();
        columns = cpd.getColumns();
    }
    ExecRow row = getExecutionFactory().getValueRow(COLUMN_COUNT);
    row.setColumn(COLPERMSID_COL_NUM, new SQLChar(colPermID));
    row.setColumn(GRANTEE_COL_NUM, grantee);
    row.setColumn(GRANTOR_COL_NUM, grantor);
    row.setColumn(TABLEID_COL_NUM, new SQLChar(tableID));
    row.setColumn(TYPE_COL_NUM, new SQLChar(type));
    row.setColumn(COLUMNS_COL_NUM, new UserType((Object) columns));
    return row;
}
Also used : ColPermsDescriptor(org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID) UserType(org.apache.derby.iapi.types.UserType)

Example 59 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class SYSCOLPERMSRowFactory method buildIndexKeyRow.

/**
 * builds an index key row for a given index number.
 */
public ExecIndexRow buildIndexKeyRow(int indexNumber, PermissionsDescriptor perm) throws StandardException {
    ExecIndexRow row = null;
    switch(indexNumber) {
        case GRANTEE_TABLE_TYPE_GRANTOR_INDEX_NUM:
            // RESOLVE We do not support the FOR GRANT OPTION, so column permission rows are unique on the
            // grantee, table UUID, and type columns. The grantor column will always have the name of the owner of the
            // table. So the index key, used for searching the index, only has grantee, table UUID, and type columns.
            // It does not have a grantor column.
            // 
            // If we support FOR GRANT OPTION then there may be multiple table permissions rows for a
            // (grantee, tableID, type) combination. We must either handle the multiple rows, which is necessary for
            // checking permissions, or add a grantor column to the key, which is necessary for granting or revoking
            // permissions.
            row = getExecutionFactory().getIndexableRow(3);
            row.setColumn(1, getAuthorizationID(perm.getGrantee()));
            ColPermsDescriptor colPerms = (ColPermsDescriptor) perm;
            String tableUUIDStr = colPerms.getTableUUID().toString();
            row.setColumn(2, new SQLChar(tableUUIDStr));
            row.setColumn(3, new SQLChar(colPerms.getType()));
            break;
        case COLPERMSID_INDEX_NUM:
            row = getExecutionFactory().getIndexableRow(1);
            String colPermsUUIDStr = perm.getObjectID().toString();
            row.setColumn(1, new SQLChar(colPermsUUIDStr));
            break;
        case TABLEID_INDEX_NUM:
            row = getExecutionFactory().getIndexableRow(1);
            colPerms = (ColPermsDescriptor) perm;
            tableUUIDStr = colPerms.getTableUUID().toString();
            row.setColumn(1, new SQLChar(tableUUIDStr));
            break;
    }
    return row;
}
Also used : ColPermsDescriptor(org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 60 with SQLChar

use of org.apache.derby.iapi.types.SQLChar in project derby by apache.

the class SYSCONGLOMERATESRowFactory method makeRow.

/**
 * Make a SYSCONGLOMERATES row
 *
 * @return	Row suitable for inserting into SYSCONGLOMERATES.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    ExecRow row;
    DataValueDescriptor col;
    String tabID = null;
    Long conglomNumber = null;
    String conglomName = null;
    Boolean supportsIndex = null;
    IndexRowGenerator indexRowGenerator = null;
    Boolean supportsConstraint = null;
    String conglomUUIDString = null;
    String schemaID = null;
    ConglomerateDescriptor conglomerate = (ConglomerateDescriptor) td;
    if (td != null) {
        /* Sometimes the SchemaDescriptor is non-null and sometimes it
			 * is null.  (We can't just rely on getting the schema id from 
			 * the ConglomerateDescriptor because it can be null when
			 * we are creating a new conglomerate.
			 */
        if (parent != null) {
            SchemaDescriptor sd = (SchemaDescriptor) parent;
            schemaID = sd.getUUID().toString();
        } else {
            schemaID = conglomerate.getSchemaID().toString();
        }
        tabID = conglomerate.getTableID().toString();
        conglomNumber = conglomerate.getConglomerateNumber();
        conglomName = conglomerate.getConglomerateName();
        conglomUUIDString = conglomerate.getUUID().toString();
        supportsIndex = conglomerate.isIndex();
        indexRowGenerator = conglomerate.getIndexDescriptor();
        supportsConstraint = conglomerate.isConstraint();
    }
    /* RESOLVE - It would be nice to require less knowledge about sysconglomerates
		 * and have this be more table driven.
		 */
    /* Build the row to insert */
    row = getExecutionFactory().getValueRow(SYSCONGLOMERATES_COLUMN_COUNT);
    /* 1st column is SCHEMAID (UUID - char(36)) */
    row.setColumn(1, new SQLChar(schemaID));
    /* 2nd column is TABLEID (UUID - char(36)) */
    row.setColumn(2, new SQLChar(tabID));
    /* 3rd column is CONGLOMERATENUMBER (long) */
    row.setColumn(3, new SQLLongint(conglomNumber));
    /* 4th column is CONGLOMERATENAME (varchar(128)) 
		** If null, use the tableid so we always
		** have a unique column
		*/
    row.setColumn(4, (conglomName == null) ? new SQLVarchar(tabID) : new SQLVarchar(conglomName));
    /* 5th  column is ISINDEX (boolean) */
    row.setColumn(5, new SQLBoolean(supportsIndex));
    /* 6th column is DESCRIPTOR
		*  (user type org.apache.derby.catalog.IndexDescriptor)
		*/
    row.setColumn(6, new UserType((indexRowGenerator == null ? (IndexDescriptor) null : indexRowGenerator.getIndexDescriptor())));
    /* 7th column is ISCONSTRAINT (boolean) */
    row.setColumn(7, new SQLBoolean(supportsConstraint));
    /* 8th column is CONGLOMERATEID (UUID - char(36)) */
    row.setColumn(8, new SQLChar(conglomUUIDString));
    return row;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) IndexDescriptor(org.apache.derby.catalog.IndexDescriptor) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) IndexRowGenerator(org.apache.derby.iapi.sql.dictionary.IndexRowGenerator) SQLLongint(org.apache.derby.iapi.types.SQLLongint) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLBoolean(org.apache.derby.iapi.types.SQLBoolean) UserType(org.apache.derby.iapi.types.UserType) SQLBoolean(org.apache.derby.iapi.types.SQLBoolean)

Aggregations

SQLChar (org.apache.derby.iapi.types.SQLChar)60 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)42 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)22 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)21 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)18 UUID (org.apache.derby.catalog.UUID)15 SQLLongint (org.apache.derby.iapi.types.SQLLongint)13 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)12 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)12 RowLocation (org.apache.derby.iapi.types.RowLocation)10 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)9 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)8 StandardException (org.apache.derby.shared.common.error.StandardException)8 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)7 UserType (org.apache.derby.iapi.types.UserType)7 ScanController (org.apache.derby.iapi.store.access.ScanController)6 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)4 LinkedList (java.util.LinkedList)3