use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class DropIndexConstantAction method executeConstantAction.
// INTERFACE METHODS
/**
* This is the guts of the Execution-time logic for DROP INDEX.
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
TableDescriptor td;
ConglomerateDescriptor cd;
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
TransactionController tc = lcc.getTransactionExecute();
/*
** Inform the data dictionary that we are about to write to it.
** There are several calls to data dictionary "get" methods here
** that might be done in "read" mode in the data dictionary, but
** it seemed safer to do this whole operation in "write" mode.
**
** We tell the data dictionary we're done writing at the end of
** the transaction.
*/
dd.startWriting(lcc);
// older version (or target) has to get td first, potential deadlock
if (tableConglomerateId == 0) {
td = dd.getTableDescriptor(tableId);
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
}
tableConglomerateId = td.getHeapConglomerateId();
}
lockTableForDDL(tc, tableConglomerateId, true);
td = dd.getTableDescriptor(tableId);
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
}
/*
** If the schema descriptor is null, then
** we must have just read ourselves in.
** So we will get the corresponding schema
** descriptor from the data dictionary.
*/
SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true);
/* Get the conglomerate descriptor for the index, along
* with an exclusive row lock on the row in sys.sysconglomerates
* in order to ensure that no one else compiles against the
* index.
*/
cd = dd.getConglomerateDescriptor(indexName, sd, true);
if (cd == null) {
throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND_DURING_EXECUTION, fullIndexName);
}
/* Since we support the sharing of conglomerates across
* multiple indexes, dropping the physical conglomerate
* for the index might affect other indexes/constraints
* which share the conglomerate. The following call will
* deal with that situation by creating a new physical
* conglomerate to replace the dropped one, if necessary.
*/
dropConglomerate(cd, td, activation, lcc);
return;
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class JarUtil method add.
/**
* Add a jar file to the current connection's database.
*
* <P> The reason for adding the jar file in this private instance
* method is that it allows us to share set up logic with drop and
* replace.
* @param is A stream for reading the content of the file to add.
* @exception StandardException Opps
*/
private long add(final InputStream is) throws StandardException {
//
// Like create table we say we are writing before we read the dd
dd.startWriting(lcc);
FileInfoDescriptor fid = getInfo();
if (fid != null)
throw StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS_IN_OBJECT, fid.getDescriptorType(), sqlName, fid.getSchemaDescriptor().getDescriptorType(), schemaName);
SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, null, true);
try {
notifyLoader(false);
dd.invalidateAllSPSPlans();
UUID id = BaseActivation.getMonitor().getUUIDFactory().createUUID();
final String jarExternalName = JarUtil.mkExternalName(id, schemaName, sqlName, fr.getSeparatorChar());
long generationId = setJar(jarExternalName, is, true, 0L);
fid = ddg.newFileInfoDescriptor(id, sd, sqlName, generationId);
dd.addDescriptor(fid, sd, DataDictionary.SYSFILES_CATALOG_NUM, false, lcc.getTransactionExecute());
return generationId;
} finally {
notifyLoader(true);
}
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class SetConstraintsConstantAction method executeConstantAction.
/**
* This is the guts of the execution time logic for SET CONSTRAINT.
*
* @param activation
*
* @see ConstantAction#executeConstantAction
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
final LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
final DataDictionary dd = lcc.getDataDictionary();
final List<String> boundConstraints = new ArrayList<String>();
if (constraints != null) {
for (TableName c : constraints) {
final SchemaDescriptor sd = dd.getSchemaDescriptor(c.getSchemaName(), lcc.getTransactionExecute(), true);
final ConstraintDescriptor cd = dd.getConstraintDescriptor(c.getTableName(), sd.getUUID());
if (cd == null) {
throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "CONSTRAINT", c.getFullSQLName());
}
final String bound = IdUtil.normalToDelimited(sd.getSchemaName()) + "." + IdUtil.normalToDelimited(cd.getConstraintName());
if (boundConstraints.contains(bound)) {
throw StandardException.newException(SQLState.LANG_DB2_DUPLICATE_NAMES, cd.getConstraintName(), bound);
} else {
boundConstraints.add(bound);
}
if (deferred && !cd.deferrable()) {
throw StandardException.newException(SQLState.LANG_SET_CONSTRAINT_NOT_DEFERRABLE, cd.getConstraintName());
}
lcc.setConstraintDeferred(activation, cd, deferred);
}
} else {
lcc.setDeferredAll(activation, deferred);
}
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class GenericPrivilegeInfo method executeGrantRevoke.
// /////////////////////////////////////////////////////////////////////////////////
//
// PrivilegeInfo BEHAVIOR
//
// /////////////////////////////////////////////////////////////////////////////////
/**
* This is the guts of the Execution-time logic for GRANT/REVOKE generic privileges.
*
* @param activation
* @param grant true if grant, false if revoke
* @param grantees a list of authorization ids (strings)
*
* @exception StandardException Thrown on failure
*/
public void executeGrantRevoke(Activation activation, boolean grant, List grantees) throws StandardException {
// Check that the current user has permission to grant the privileges.
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
String currentUser = lcc.getCurrentUserId(activation);
TransactionController tc = lcc.getTransactionExecute();
SchemaDescriptor sd = _tupleDescriptor.getSchemaDescriptor();
UUID objectID = _tupleDescriptor.getUUID();
String objectTypeName = _tupleDescriptor.getObjectTypeName();
// Check that the current user has permission to grant the privileges.
checkOwnership(currentUser, (TupleDescriptor) _tupleDescriptor, sd, dd);
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
PermDescriptor permDesc = ddg.newPermDescriptor(null, objectTypeName, objectID, _privilege, currentUser, null, false);
dd.startWriting(lcc);
for (Iterator itr = grantees.iterator(); itr.hasNext(); ) {
// Keep track to see if any privileges are revoked by a revoke
// statement. If a privilege is not revoked, we need to raise a
// warning.
boolean privileges_revoked = false;
String grantee = (String) itr.next();
if (dd.addRemovePermissionsDescriptor(grant, permDesc, grantee, tc)) {
//
// We fall in here if we are performing REVOKE.
//
privileges_revoked = true;
int invalidationType = _restrict ? DependencyManager.REVOKE_PRIVILEGE_RESTRICT : DependencyManager.REVOKE_PRIVILEGE;
dd.getDependencyManager().invalidateFor(permDesc, invalidationType, lcc);
// Now invalidate all GPSs refering to the object.
dd.getDependencyManager().invalidateFor(_tupleDescriptor, invalidationType, lcc);
}
addWarningIfPrivilegeNotRevoked(activation, grant, privileges_revoked, grantee);
}
}
use of org.apache.derby.iapi.sql.dictionary.SchemaDescriptor in project derby by apache.
the class TestPropertyInfo method getConglomerateProperties.
private static Properties getConglomerateProperties(String schemaName, String conglomerateName, boolean isIndex) throws java.sql.SQLException {
ConglomerateController cc;
ConglomerateDescriptor cd;
DataDictionary dd;
Properties properties;
SchemaDescriptor sd;
TableDescriptor td;
TransactionController tc;
long conglomerateNumber;
// find the language context.
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
// Get the current transaction controller
tc = lcc.getTransactionExecute();
try {
// find the DataDictionary
dd = lcc.getDataDictionary();
// get the SchemaDescriptor
sd = dd.getSchemaDescriptor(schemaName, tc, true);
if (!isIndex) {
// get the TableDescriptor for the table
td = dd.getTableDescriptor(conglomerateName, sd, tc);
// Return an empty Properties if table does not exist or if it is for a view.
if ((td == null) || td.getTableType() == TableDescriptor.VIEW_TYPE) {
return new Properties();
}
conglomerateNumber = td.getHeapConglomerateId();
} else {
// get the ConglomerateDescriptor for the index
cd = dd.getConglomerateDescriptor(conglomerateName, sd, false);
// Return an empty Properties if index does not exist
if (cd == null) {
return new Properties();
}
conglomerateNumber = cd.getConglomerateNumber();
}
cc = tc.openConglomerate(conglomerateNumber, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
properties = cc.getInternalTablePropertySet(new Properties());
cc.close();
} catch (StandardException se) {
throw PublicAPI.wrapStandardException(se);
}
return properties;
}
Aggregations