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.
}
}
}
}
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);
}
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;
}
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);
}
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);
}
Aggregations