use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class DataDictionaryImpl method dropSequenceID.
/**
* Drop a sequenceID from the ( schemaName, sequenceName ) map
*/
private void dropSequenceID(SequenceDescriptor sd) throws StandardException {
if (sd == null) {
return;
}
SchemaDescriptor schema = sd.getSchemaDescriptor();
String schemaName = schema.getSchemaName();
String sequenceName = sd.getSequenceName();
HashMap<String, String> sequencesInSchema = (HashMap<String, String>) sequenceIDs.get(schemaName);
if (sequencesInSchema == null) {
return;
}
if (sequencesInSchema.get(sequenceName) == null) {
return;
}
{
sequencesInSchema.remove(sequenceName);
}
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class SYSTABLESRowFactory method buildDescriptorBody.
public TupleDescriptor buildDescriptorBody(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd, int isolationLevel) throws StandardException {
if (SanityManager.DEBUG)
SanityManager.ASSERT(row.nColumns() == SYSTABLES_COLUMN_COUNT, "Wrong number of columns for a SYSTABLES row");
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
String tableUUIDString;
String schemaUUIDString;
int tableTypeEnum;
String lockGranularity;
String tableName, tableType;
DataValueDescriptor col;
UUID tableUUID;
UUID schemaUUID;
SchemaDescriptor schema;
TableDescriptor tabDesc;
/* 1st column is TABLEID (UUID - char(36)) */
col = row.getColumn(SYSTABLES_TABLEID);
tableUUIDString = col.getString();
tableUUID = getUUIDFactory().recreateUUID(tableUUIDString);
/* 2nd column is TABLENAME (varchar(128)) */
col = row.getColumn(SYSTABLES_TABLENAME);
tableName = col.getString();
/* 3rd column is TABLETYPE (char(1)) */
col = row.getColumn(SYSTABLES_TABLETYPE);
tableType = col.getString();
if (SanityManager.DEBUG) {
SanityManager.ASSERT(tableType.length() == 1, "Fourth column type incorrect");
}
switch(tableType.charAt(0)) {
case 'T':
tableTypeEnum = TableDescriptor.BASE_TABLE_TYPE;
break;
case 'S':
tableTypeEnum = TableDescriptor.SYSTEM_TABLE_TYPE;
break;
case 'V':
tableTypeEnum = TableDescriptor.VIEW_TYPE;
break;
case 'A':
tableTypeEnum = TableDescriptor.SYNONYM_TYPE;
break;
default:
if (SanityManager.DEBUG)
SanityManager.THROWASSERT("Fourth column value invalid");
tableTypeEnum = -1;
}
/* 4th column is SCHEMAID (UUID - char(36)) */
col = row.getColumn(SYSTABLES_SCHEMAID);
schemaUUIDString = col.getString();
schemaUUID = getUUIDFactory().recreateUUID(schemaUUIDString);
schema = dd.getSchemaDescriptor(schemaUUID, isolationLevel, null);
/* 5th column is LOCKGRANULARITY (char(1)) */
col = row.getColumn(SYSTABLES_LOCKGRANULARITY);
lockGranularity = col.getString();
if (SanityManager.DEBUG) {
SanityManager.ASSERT(lockGranularity.length() == 1, "Fifth column type incorrect");
}
// RESOLVE - Deal with lock granularity
tabDesc = ddg.newTableDescriptor(tableName, schema, tableTypeEnum, lockGranularity.charAt(0));
tabDesc.setUUID(tableUUID);
return tabDesc;
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class PermissionsCacheable method setIdentity.
/* Cacheable interface */
public Cacheable setIdentity(Object key) throws StandardException {
// to access that column subset.
if (key instanceof TablePermsDescriptor) {
TablePermsDescriptor tablePermsKey = (TablePermsDescriptor) key;
permissions = dd.getUncachedTablePermsDescriptor(tablePermsKey);
if (permissions == null) {
// The owner has all privileges unless they have been revoked.
TableDescriptor td = dd.getTableDescriptor(tablePermsKey.getTableUUID());
SchemaDescriptor sd = td.getSchemaDescriptor();
if (sd.isSystemSchema()) {
// RESOLVE The access to system tables is hard coded to SELECT only to everyone.
// Is this the way we want Derby to work? Should we allow revocation of read access
// to system tables? If so we must explicitly add a row to the SYS.SYSTABLEPERMISSIONS
// table for each system table when a database is created.
permissions = new TablePermsDescriptor(dd, tablePermsKey.getGrantee(), (String) null, tablePermsKey.getTableUUID(), "Y", "N", "N", "N", "N", "N");
// give the permission the same UUID as the system table
((TablePermsDescriptor) permissions).setUUID(tablePermsKey.getTableUUID());
} else if (tablePermsKey.getGrantee().equals(sd.getAuthorizationId())) {
permissions = new TablePermsDescriptor(dd, tablePermsKey.getGrantee(), Authorizer.SYSTEM_AUTHORIZATION_ID, tablePermsKey.getTableUUID(), "Y", "Y", "Y", "Y", "Y", "Y");
} else {
permissions = new TablePermsDescriptor(dd, tablePermsKey.getGrantee(), (String) null, tablePermsKey.getTableUUID(), "N", "N", "N", "N", "N", "N");
}
}
} else if (key instanceof ColPermsDescriptor) {
ColPermsDescriptor colPermsKey = (ColPermsDescriptor) key;
permissions = dd.getUncachedColPermsDescriptor(colPermsKey);
if (permissions == null)
permissions = new ColPermsDescriptor(dd, colPermsKey.getGrantee(), (String) null, colPermsKey.getTableUUID(), colPermsKey.getType(), (FormatableBitSet) null);
} else if (key instanceof RoutinePermsDescriptor) {
RoutinePermsDescriptor routinePermsKey = (RoutinePermsDescriptor) key;
permissions = dd.getUncachedRoutinePermsDescriptor(routinePermsKey);
if (permissions == null) {
// The owner has all privileges unless they have been revoked.
try {
AliasDescriptor ad = dd.getAliasDescriptor(routinePermsKey.getRoutineUUID());
SchemaDescriptor sd = dd.getSchemaDescriptor(ad.getSchemaUUID(), ConnectionUtil.getCurrentLCC().getTransactionExecute());
if (sd.isSystemSchema() && !sd.isSchemaWithGrantableRoutines())
permissions = new RoutinePermsDescriptor(dd, routinePermsKey.getGrantee(), (String) null, routinePermsKey.getRoutineUUID(), true);
else if (routinePermsKey.getGrantee().equals(sd.getAuthorizationId()))
permissions = new RoutinePermsDescriptor(dd, routinePermsKey.getGrantee(), Authorizer.SYSTEM_AUTHORIZATION_ID, routinePermsKey.getRoutineUUID(), true);
} catch (java.sql.SQLException sqle) {
throw StandardException.plainWrapException(sqle);
}
}
} else if (key instanceof PermDescriptor) {
PermDescriptor permKey = (PermDescriptor) key;
permissions = dd.getUncachedGenericPermDescriptor(permKey);
if (permissions == null) {
// The owner has all privileges unless they have been revoked.
String objectType = permKey.getObjectType();
String privilege = permKey.getPermission();
UUID protectedObjectsID = permKey.getPermObjectId();
PrivilegedSQLObject pso = PermDescriptor.getProtectedObject(dd, protectedObjectsID, objectType);
SchemaDescriptor sd = pso.getSchemaDescriptor();
if (permKey.getGrantee().equals(sd.getAuthorizationId())) {
permissions = new PermDescriptor(dd, null, objectType, pso.getUUID(), privilege, Authorizer.SYSTEM_AUTHORIZATION_ID, permKey.getGrantee(), true);
}
}
} else {
if (SanityManager.DEBUG)
SanityManager.NOTREACHED();
return null;
}
if (permissions != null) {
return this;
}
return null;
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class SYSFILESRowFactory method buildDescriptor.
// /////////////////////////////////////////////////////////////////////////
//
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
//
// /////////////////////////////////////////////////////////////////////////
/**
* Make a descriptor out of a SYSFILES row
*
* @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() != SYSFILES_COLUMN_COUNT) {
SanityManager.THROWASSERT("Wrong number of columns for a SYSFILES row: " + row.nColumns());
}
}
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
String id_S;
UUID id;
String schemaId_S;
UUID schemaId;
String name;
long generationId;
DataValueDescriptor col;
SchemaDescriptor schemaDescriptor;
FileInfoDescriptor result;
/* 1st column is ID (UUID - char(36)) */
col = row.getColumn(ID_COL_NUM);
id_S = col.getString();
id = getUUIDFactory().recreateUUID(id_S);
/* 2nd column is SchemaId */
col = row.getColumn(SCHEMA_ID_COL_NUM);
schemaId_S = col.getString();
schemaId = getUUIDFactory().recreateUUID(schemaId_S);
schemaDescriptor = dd.getSchemaDescriptor(schemaId, null);
if (SanityManager.DEBUG) {
if (schemaDescriptor == null) {
SanityManager.THROWASSERT("Missing schema for FileInfo: " + id_S);
}
}
/* 3nd column is NAME (varchar(128)) */
col = row.getColumn(NAME_COL_NUM);
name = col.getString();
/* 4th column is generationId (long) */
col = row.getColumn(GENERATION_ID_COL_NUM);
generationId = col.getLong();
result = ddg.newFileInfoDescriptor(id, schemaDescriptor, name, generationId);
return result;
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class SYSSCHEMASRowFactory method makeRow.
// ///////////////////////////////////////////////////////////////////////////
//
// METHODS
//
// ///////////////////////////////////////////////////////////////////////////
/**
* Make a SYSSCHEMAS row
*
* @return Row suitable for inserting into SYSSCHEMAS.
*
* @exception StandardException thrown on failure
*/
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
DataTypeDescriptor dtd;
ExecRow row;
DataValueDescriptor col;
String name = null;
UUID oid = null;
String uuid = null;
String aid = null;
if (td != null) {
SchemaDescriptor schemaDescriptor = (SchemaDescriptor) td;
name = schemaDescriptor.getSchemaName();
oid = schemaDescriptor.getUUID();
if (oid == null) {
oid = getUUIDFactory().createUUID();
schemaDescriptor.setUUID(oid);
}
uuid = oid.toString();
aid = schemaDescriptor.getAuthorizationId();
}
/* Build the row to insert */
row = getExecutionFactory().getValueRow(SYSSCHEMAS_COLUMN_COUNT);
/* 1st column is SCHEMAID */
row.setColumn(1, new SQLChar(uuid));
/* 2nd column is SCHEMANAME */
row.setColumn(2, new SQLVarchar(name));
/* 3rd column is SCHEMAAID */
row.setColumn(3, new SQLVarchar(aid));
return row;
}
Aggregations