use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class DD_Version method dropSystemCatalog.
/**
* Drop a System catalog.
* @param tc TransactionController
* @param crf CatalogRowFactory for the catalog to drop.
* @exception StandardException Standard Derby error policy.
*/
protected void dropSystemCatalog(TransactionController tc, CatalogRowFactory crf) throws StandardException {
SchemaDescriptor sd = bootingDictionary.getSystemSchemaDescriptor();
TableDescriptor td = bootingDictionary.getTableDescriptor(crf.getCatalogName(), sd, tc);
ConglomerateDescriptor[] cds = td.getConglomerateDescriptors();
for (int index = 0; index < cds.length; index++) {
tc.dropConglomerate(cds[index].getConglomerateNumber());
}
dropSystemCatalogDescription(tc, td);
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class PrivilegeNode method bind.
/**
* Bind this GrantNode. Resolve all table, column, and routine references. Register
* a dependency on the object of the privilege if it has not already been done
*
* @param dependencies The list of privilege objects that this statement has already seen.
* If the object of this privilege is not in the list then this statement is registered
* as dependent on the object.
* @param grantees The list of grantees
* @param isGrant grant if true; revoke if false
* @return the bound node
*
* @exception StandardException Standard error policy.
*/
public QueryTreeNode bind(HashMap<Provider, Provider> dependencies, List<String> grantees, boolean isGrant) throws StandardException {
// The below code handles the case where objectName.getSchemaName()
// returns null, in which case we'll fetch the schema descriptor for
// the current compilation schema (see getSchemaDescriptor).
SchemaDescriptor sd = getSchemaDescriptor(objectName.getSchemaName(), true);
objectName.setSchemaName(sd.getSchemaName());
// Can not grant/revoke permissions from self
if (grantees.contains(sd.getAuthorizationId())) {
throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
}
switch(objectType) {
case TABLE_PRIVILEGES:
// can't grant/revoke privileges on system tables
if (sd.isSystemSchema()) {
throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
}
TableDescriptor td = getTableDescriptor(objectName.getTableName(), sd);
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, objectName);
}
// a temporary table is created later with same name.
if (isSessionSchema(sd.getSchemaName())) {
throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES);
}
if (td.getTableType() != TableDescriptor.BASE_TABLE_TYPE && td.getTableType() != TableDescriptor.VIEW_TYPE) {
throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
}
specificPrivileges.bind(td, isGrant);
dependencyProvider = td;
break;
case ROUTINE_PRIVILEGES:
if (!sd.isSchemaWithGrantableRoutines()) {
throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, objectName.getFullTableName());
}
AliasDescriptor proc = null;
List<AliasDescriptor> list = getDataDictionary().getRoutineList(sd.getUUID().toString(), objectName.getTableName(), routineDesignator.isFunction ? AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR : AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR);
if (routineDesignator.paramTypeList == null) {
// No signature was specified. Make sure that there is exactly one routine with that name.
if (list.size() > 1) {
throw StandardException.newException((routineDesignator.isFunction ? SQLState.LANG_AMBIGUOUS_FUNCTION_NAME : SQLState.LANG_AMBIGUOUS_PROCEDURE_NAME), objectName.getFullTableName());
}
if (list.size() != 1) {
if (routineDesignator.isFunction) {
throw StandardException.newException(SQLState.LANG_NO_SUCH_FUNCTION, objectName.getFullTableName());
} else {
throw StandardException.newException(SQLState.LANG_NO_SUCH_PROCEDURE, objectName.getFullTableName());
}
}
proc = list.get(0);
} else {
// The full signature was specified
boolean found = false;
for (int i = list.size() - 1; (!found) && i >= 0; i--) {
proc = list.get(i);
RoutineAliasInfo routineInfo = (RoutineAliasInfo) proc.getAliasInfo();
int parameterCount = routineInfo.getParameterCount();
if (parameterCount != routineDesignator.paramTypeList.size())
continue;
TypeDescriptor[] parameterTypes = routineInfo.getParameterTypes();
found = true;
for (int parmIdx = 0; parmIdx < parameterCount; parmIdx++) {
if (!parameterTypes[parmIdx].equals(routineDesignator.paramTypeList.get(parmIdx))) {
found = false;
break;
}
}
}
if (!found) {
// reconstruct the signature for the error message
StringBuilder sb = new StringBuilder(objectName.getFullTableName());
sb.append("(");
for (int i = 0; i < routineDesignator.paramTypeList.size(); i++) {
if (i > 0)
sb.append(",");
sb.append(routineDesignator.paramTypeList.get(i).toString());
}
throw StandardException.newException(SQLState.LANG_NO_SUCH_METHOD_ALIAS, sb.toString());
}
}
routineDesignator.setAliasDescriptor(proc);
dependencyProvider = proc;
break;
case AGGREGATE_PRIVILEGES:
dependencyProvider = getDataDictionary().getAliasDescriptor(sd.getUUID().toString(), objectName.getTableName(), AliasInfo.ALIAS_NAME_SPACE_AGGREGATE_AS_CHAR);
if (dependencyProvider == null) {
throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "DERBY AGGREGATE", objectName.getFullTableName());
}
break;
case SEQUENCE_PRIVILEGES:
dependencyProvider = getDataDictionary().getSequenceDescriptor(sd, objectName.getTableName());
if (dependencyProvider == null) {
throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "SEQUENCE", objectName.getFullTableName());
}
break;
case UDT_PRIVILEGES:
dependencyProvider = getDataDictionary().getAliasDescriptor(sd.getUUID().toString(), objectName.getTableName(), AliasInfo.ALIAS_NAME_SPACE_UDT_AS_CHAR);
if (dependencyProvider == null) {
throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "TYPE", objectName.getFullTableName());
}
break;
default:
throw unimplementedFeature();
}
if (dependencyProvider != null) {
if (dependencies.get(dependencyProvider) == null) {
getCompilerContext().createDependency(dependencyProvider);
dependencies.put(dependencyProvider, dependencyProvider);
}
}
return this;
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class QueryTreeNode method resolveTableToSynonym.
/**
* Resolve table/view reference to a synonym. May have to follow a synonym chain.
*
* @param tabName to match for a synonym
*
* @return Synonym TableName if a match is found, NULL otherwise.
*
* @exception StandardException Thrown on error
*/
TableName resolveTableToSynonym(TableName tabName) throws StandardException {
DataDictionary dd = getDataDictionary();
String nextSynonymTable = tabName.getTableName();
String nextSynonymSchema = tabName.getSchemaName();
boolean found = false;
CompilerContext cc = getCompilerContext();
// the following loop shouldn't loop forever.
for (; ; ) {
SchemaDescriptor nextSD = getSchemaDescriptor(nextSynonymSchema, false);
if (nextSD == null || nextSD.getUUID() == null)
break;
AliasDescriptor nextAD = dd.getAliasDescriptor(nextSD.getUUID().toString(), nextSynonymTable, AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR);
if (nextAD == null)
break;
/* Query is dependent on the AliasDescriptor */
cc.createDependency(nextAD);
found = true;
SynonymAliasInfo info = ((SynonymAliasInfo) nextAD.getAliasInfo());
nextSynonymTable = info.getSynonymTable();
nextSynonymSchema = info.getSynonymSchema();
}
if (!found)
return null;
TableName tableName = new TableName(nextSynonymSchema, nextSynonymTable, getContextManager());
return tableName;
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class QueryTreeNode method bindUserType.
/**
* Bind a UDT. This involves looking it up in the DataDictionary and filling
* in its class name.
*
* @param originalDTD A datatype: might be an unbound UDT and might not be
*
* @return The bound UDT if originalDTD was an unbound UDT; otherwise returns originalDTD.
*/
public DataTypeDescriptor bindUserType(DataTypeDescriptor originalDTD) throws StandardException {
// if the type is a table type, then we need to bind its user-typed columns
if (originalDTD.getCatalogType().isRowMultiSet()) {
return bindRowMultiSet(originalDTD);
}
// nothing to do if this is not a user defined type
if (!originalDTD.getTypeId().userType()) {
return originalDTD;
}
UserDefinedTypeIdImpl userTypeID = (UserDefinedTypeIdImpl) originalDTD.getTypeId().getBaseTypeId();
// also nothing to do if the type has already been resolved
if (userTypeID.isBound()) {
return originalDTD;
}
// ok, we have an unbound UDT. lookup this type in the data dictionary
DataDictionary dd = getDataDictionary();
SchemaDescriptor typeSchema = getSchemaDescriptor(userTypeID.getSchemaName());
char udtNameSpace = AliasInfo.ALIAS_NAME_SPACE_UDT_AS_CHAR;
String unqualifiedTypeName = userTypeID.getUnqualifiedName();
AliasDescriptor ad = dd.getAliasDescriptor(typeSchema.getUUID().toString(), unqualifiedTypeName, udtNameSpace);
if (ad == null) {
throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, AliasDescriptor.getAliasType(udtNameSpace), unqualifiedTypeName);
}
createTypeDependency(ad);
DataTypeDescriptor result = new DataTypeDescriptor(TypeId.getUserDefinedTypeId(typeSchema.getSchemaName(), unqualifiedTypeName, ad.getJavaClassName()), originalDTD.isNullable());
return result;
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class RenameNode method bindStatement.
// We inherit the generate() method from DDLStatementNode.
/**
* Bind this node. This means doing any static error checking that
* can be done before actually renaming the table/column/index.
*
* For a table rename: looking up the from table, verifying it exists
* verifying it's not a system table, verifying it's not view
* and looking up to table, verifying it doesn't exist.
*
* For a column rename: looking up the table, verifying it exists,
* verifying it's not a system table, verifying it's not view, verifying
* the from column exists, verifying the to column doesn't exist.
*
* For a index rename: looking up the table, verifying it exists,
* verifying it's not a system table, verifying it's not view, verifying
* the from index exists, verifying the to index doesn't exist.
*
* @exception StandardException Thrown on error
*/
@Override
public void bindStatement() throws StandardException {
CompilerContext cc = getCompilerContext();
DataDictionary dd = getDataDictionary();
ConglomerateDescriptor cd;
SchemaDescriptor sd;
/* in case of rename index, the only thing we get from parser is
* current and new index names with no information about the
* table it belongs to. This is because index names are unique
* within a schema and hence then is no need to qualify an index
* name with a table name which we have to do for rename column.
* But from the index name, using the data dictionary, you can
* find the table it belongs to. Since most of the checking
* in bind is done using table descriptor, in the following if
* statement, we are trying to get the table information from the
* index name so it is available for the rest of he bind code.
*/
TableName baseTable;
if (renamingWhat == StatementType.RENAME_INDEX) {
sd = getSchemaDescriptor((String) null);
ConglomerateDescriptor indexDescriptor = dd.getConglomerateDescriptor(oldObjectName, sd, false);
if (indexDescriptor == null)
throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND, oldObjectName);
/* Get the table descriptor */
td = dd.getTableDescriptor(indexDescriptor.getTableID());
initAndCheck(makeTableName(td.getSchemaName(), td.getName()));
} else
sd = getSchemaDescriptor();
td = getTableDescriptor();
// throw an exception if user is attempting a rename on temporary table
if (td.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
throw StandardException.newException(SQLState.LANG_NOT_ALLOWED_FOR_DECLARED_GLOBAL_TEMP_TABLE);
}
switch(this.renamingWhat) {
case StatementType.RENAME_TABLE:
/* Verify that new table name does not exist in the database */
TableDescriptor tabDesc = getTableDescriptor(newObjectName, sd);
if (tabDesc != null)
throw descriptorExistsException(tabDesc, sd);
renameTableBind(dd);
break;
case StatementType.RENAME_COLUMN:
renameColumnBind(dd);
break;
case StatementType.RENAME_INDEX:
ConglomerateDescriptor conglomDesc = dd.getConglomerateDescriptor(newObjectName, sd, false);
if (conglomDesc != null)
throw descriptorExistsException(conglomDesc, sd);
break;
default:
if (SanityManager.DEBUG)
SanityManager.THROWASSERT("Unexpected rename action in RenameNode");
break;
}
conglomerateNumber = td.getHeapConglomerateId();
/* Get the base conglomerate descriptor */
cd = td.getConglomerateDescriptor(conglomerateNumber);
/* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */
cc.createDependency(td);
cc.createDependency(cd);
}
Aggregations