Search in sources :

Example 16 with TupleDescriptor

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

the class TablePrivilegeInfo method checkPrivileges.

/**
 * Determines if the privilege is grantable by this grantor
 * for the given view.
 *
 * Note that the database owner can access database objects
 * without needing to be their owner.  This method should only
 * be called if it is a GRANT.
 *
 * @param user					authorizationId of current user
 * @param td		            TableDescriptor to be checked against
 * @param sd					SchemaDescriptor
 * @param dd					DataDictionary
 * @param lcc                   LanguageConnectionContext
 *
 * @exception StandardException if user does not have permission to grant
 */
private void checkPrivileges(String user, TableDescriptor td, SchemaDescriptor sd, DataDictionary dd, LanguageConnectionContext lcc) throws StandardException {
    if (user.equals(dd.getAuthorizationDatabaseOwner()))
        return;
    // check view specific
    if (td.getTableType() == TableDescriptor.VIEW_TYPE) {
        if (descriptorList != null) {
            TransactionController tc = lcc.getTransactionExecute();
            int siz = descriptorList.size();
            for (int i = 0; i < siz; i++) {
                TupleDescriptor p;
                SchemaDescriptor s = null;
                p = (TupleDescriptor) descriptorList.get(i);
                if (p instanceof TableDescriptor) {
                    TableDescriptor t = (TableDescriptor) p;
                    s = t.getSchemaDescriptor();
                } else if (p instanceof ViewDescriptor) {
                    ViewDescriptor v = (ViewDescriptor) p;
                    s = dd.getSchemaDescriptor(v.getCompSchemaId(), tc);
                } else if (p instanceof AliasDescriptor) {
                    AliasDescriptor a = (AliasDescriptor) p;
                    s = dd.getSchemaDescriptor(a.getSchemaUUID(), tc);
                }
                if (s != null && !user.equals(s.getAuthorizationId())) {
                    throw StandardException.newException(SQLState.AUTH_NO_OBJECT_PERMISSION, user, "grant", sd.getSchemaName(), td.getName());
                }
            // FUTURE: if object is not own by grantor then check if
            // the grantor have grant option.
            }
        }
    }
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) TransactionController(org.apache.derby.iapi.store.access.TransactionController) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ViewDescriptor(org.apache.derby.iapi.sql.dictionary.ViewDescriptor)

Example 17 with TupleDescriptor

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

the class DataDictionaryImpl method getUser.

public UserDescriptor getUser(String userName) throws StandardException {
    // 
    // No sense looking for the SYSUSERS congomerate until the database
    // is hard-upgraded to 10.9 or later.
    // 
    dictionaryVersion.checkVersion(DD_VERSION_DERBY_10_9, "NATIVE AUTHENTICATION");
    ExecIndexRow keyRow;
    TabInfoImpl ti = getNonCoreTI(SYSUSERS_CATALOG_NUM);
    /* Set up the start/stop position for the scan */
    keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow.setColumn(1, new SQLVarchar(userName));
    return getDescriptorViaIndex(SYSUSERSRowFactory.SYSUSERS_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, UserDescriptor.class, false);
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 18 with TupleDescriptor

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

the class DataDictionaryImpl method hashAllTableDescriptorsByTableId.

/**
 * Get all of the TableDescriptors in the database and hash them
 * by TableId This is useful as a performance optimization for the
 * locking VTIs.  NOTE: This method will scan SYS.SYSTABLES and
 * SYS.SYSSCHEMAS at READ UNCOMMITTED.
 *
 * @param tc		TransactionController for the transaction
 *
 * @return	A Hashtable with all of the Table descriptors in the database
 *			hashed by TableId
 *
 * @exception StandardException		Thrown on failure
 */
@SuppressWarnings("UseOfObsoleteCollectionType")
public Hashtable<UUID, TableDescriptor> hashAllTableDescriptorsByTableId(TransactionController tc) throws StandardException {
    Hashtable<UUID, TableDescriptor> ht = new Hashtable<UUID, TableDescriptor>();
    ScanController scanController;
    ExecRow outRow;
    TabInfoImpl ti = coreInfo[SYSTABLES_CORE_NUM];
    SYSTABLESRowFactory rf = (SYSTABLESRowFactory) ti.getCatalogRowFactory();
    outRow = rf.makeEmptyRow();
    scanController = tc.openScan(// sys.systable
    ti.getHeapConglomerate(), // don't hold open across commit
    false, // for read
    0, // scans whole table.
    TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED, // all fields as objects
    (FormatableBitSet) null, // start position - first row
    (DataValueDescriptor[]) null, // startSearchOperation
    ScanController.GE, // scanQualifier,
    (ScanQualifier[][]) null, // stop position-through last row
    (DataValueDescriptor[]) null, // stopSearchOperation
    ScanController.GT);
    // fetch() may find the row deleted or purged from the table.
    while (scanController.fetchNext(outRow.getRowArray())) {
        TableDescriptor td = (TableDescriptor) rf.buildDescriptor(outRow, (TupleDescriptor) null, this, TransactionController.ISOLATION_READ_UNCOMMITTED);
        ht.put(td.getUUID(), td);
    }
    scanController.close();
    return ht;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) Hashtable(java.util.Hashtable) TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ScanQualifier(org.apache.derby.iapi.sql.execute.ScanQualifier) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) UUID(org.apache.derby.catalog.UUID) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 19 with TupleDescriptor

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

the class DataDictionaryImpl method upgradeSYSROUTINEPERMS_10_6.

/**
 * 10.6 upgrade logic to update the permissions granted to SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE.
 * If a 10.0 database was upgraded to 10.2, 10.3, or 10.4, then there will
 * be an extra permissions tuple in SYSROUTINEPERMS--that tuple will have a
 * null grantor field. We must delete this tuple. See DERBY-4215.
 */
void upgradeSYSROUTINEPERMS_10_6(TransactionController tc) throws StandardException {
    // 
    // Get the aliasID of SYSCS_INPLACE_COMPRESS_TABLE
    // 
    TabInfoImpl aliasTI = getNonCoreTI(SYSALIASES_CATALOG_NUM);
    ExecIndexRow aliasKeyRow = exFactory.getIndexableRow(3);
    DataValueDescriptor aliasNameOrderable = new SQLVarchar("SYSCS_INPLACE_COMPRESS_TABLE");
    ;
    DataValueDescriptor nameSpaceOrderable = new SQLChar(new String(new char[] { AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR }));
    aliasKeyRow.setColumn(1, new SQLChar(SchemaDescriptor.SYSCS_UTIL_SCHEMA_UUID));
    aliasKeyRow.setColumn(2, aliasNameOrderable);
    aliasKeyRow.setColumn(3, nameSpaceOrderable);
    AliasDescriptor oldAD = getDescriptorViaIndex(SYSALIASESRowFactory.SYSALIASES_INDEX1_ID, aliasKeyRow, (ScanQualifier[][]) null, aliasTI, (TupleDescriptor) null, (List<TupleDescriptor>) null, AliasDescriptor.class, true, TransactionController.ISOLATION_REPEATABLE_READ, tc);
    UUID aliasID = oldAD.getUUID();
    // 
    // Now delete the permissions tuple which has a null grantor
    // 
    TabInfoImpl rpTI = getNonCoreTI(SYSROUTINEPERMS_CATALOG_NUM);
    ExecIndexRow rpKeyRow = exFactory.getIndexableRow(3);
    rpKeyRow.setColumn(1, new SQLVarchar("PUBLIC"));
    rpKeyRow.setColumn(2, new SQLChar(aliasID.toString()));
    rpKeyRow.setColumn(3, new SQLVarchar((String) null));
    int deleteCount = rpTI.deleteRow(tc, rpKeyRow, SYSROUTINEPERMSRowFactory.GRANTEE_ALIAS_GRANTOR_INDEX_NUM);
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) UUID(org.apache.derby.catalog.UUID) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 20 with TupleDescriptor

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

the class DataDictionaryImpl method upgradeCLOBGETSUBSTRING_10_6.

/**
 * 10.6 upgrade logic to update the return type of SYSIBM.CLOBGETSUBSTRING. The length of the
 * return type was changed in 10.5 but old versions of the metadata were not
 * upgraded at that time. See DERBY-4214.
 */
void upgradeCLOBGETSUBSTRING_10_6(TransactionController tc) throws StandardException {
    TabInfoImpl ti = getNonCoreTI(SYSALIASES_CATALOG_NUM);
    ExecIndexRow keyRow = exFactory.getIndexableRow(3);
    DataValueDescriptor aliasNameOrderable = new SQLVarchar("CLOBGETSUBSTRING");
    DataValueDescriptor nameSpaceOrderable = new SQLChar(new String(new char[] { AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR }));
    keyRow.setColumn(1, new SQLChar(SchemaDescriptor.SYSIBM_SCHEMA_UUID));
    keyRow.setColumn(2, aliasNameOrderable);
    keyRow.setColumn(3, nameSpaceOrderable);
    AliasDescriptor oldAD = getDescriptorViaIndex(SYSALIASESRowFactory.SYSALIASES_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, AliasDescriptor.class, true, TransactionController.ISOLATION_REPEATABLE_READ, tc);
    RoutineAliasInfo oldRai = (RoutineAliasInfo) oldAD.getAliasInfo();
    TypeDescriptor newReturnType = DataTypeDescriptor.getCatalogType(Types.VARCHAR, Limits.MAX_CLOB_RETURN_LEN);
    RoutineAliasInfo newRai = new RoutineAliasInfo(oldRai.getMethodName(), oldRai.getParameterCount(), oldRai.getParameterNames(), oldRai.getParameterTypes(), oldRai.getParameterModes(), oldRai.getMaxDynamicResultSets(), oldRai.getParameterStyle(), oldRai.getSQLAllowed(), oldRai.isDeterministic(), oldRai.hasVarargs(), oldRai.hasDefinersRights(), oldRai.calledOnNullInput(), newReturnType);
    AliasDescriptor newAD = new AliasDescriptor(this, oldAD.getUUID(), oldAD.getObjectName(), oldAD.getSchemaUUID(), oldAD.getJavaClassName(), oldAD.getAliasType(), oldAD.getNameSpace(), oldAD.getSystemAlias(), newRai, oldAD.getSpecificName());
    ExecRow newRow = ti.getCatalogRowFactory().makeRow(newAD, null);
    ti.updateRow(keyRow, newRow, SYSALIASESRowFactory.SYSALIASES_INDEX1_ID, new boolean[] { false, false, false }, (int[]) null, tc);
}
Also used : RoutineAliasInfo(org.apache.derby.catalog.types.RoutineAliasInfo) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Aggregations

TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)30 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)27 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)24 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)13 SQLChar (org.apache.derby.iapi.types.SQLChar)8 ArrayList (java.util.ArrayList)5 ScanQualifier (org.apache.derby.iapi.sql.execute.ScanQualifier)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)4 ConglomerateDescriptorList (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList)4 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)4 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)4 TriggerDescriptorList (org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList)4 UUID (org.apache.derby.catalog.UUID)3 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)3 SequenceDescriptor (org.apache.derby.iapi.sql.dictionary.SequenceDescriptor)3 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)3 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)2 SPSDescriptor (org.apache.derby.iapi.sql.dictionary.SPSDescriptor)2