use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class DropStatisticsConstantAction method executeConstantAction.
public void executeConstantAction(Activation activation) throws StandardException {
TableDescriptor td;
ConglomerateDescriptor cd = null;
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
DependencyManager dm = dd.getDependencyManager();
TransactionController tc = lcc.getTransactionExecute();
dd.startWriting(lcc);
if (forTable) {
td = dd.getTableDescriptor(objectName, sd, tc);
} else {
cd = dd.getConglomerateDescriptor(objectName, sd, false);
td = dd.getTableDescriptor(cd.getTableID());
}
/* invalidate all SPS's on the table-- bad plan on SPS, so user drops
* statistics and would want SPS's invalidated so that recompile would
* give good plans; thats the theory anyways....
*/
dm.invalidateFor(td, DependencyManager.DROP_STATISTICS, lcc);
dd.dropStatisticsDescriptors(td.getUUID(), ((cd != null) ? cd.getUUID() : null), tc);
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class TablePrivilegesNode method bindPrivilegesForView.
/**
* Retrieve all the underlying stored dependencies such as table(s),
* view(s) and routine(s) descriptors which the view depends on.
* This information is then passed to the runtime to determine if
* the privilege is grantable to the grantees by this grantor at
* execution time.
*
* Go through the providers regardless who the grantor is since
* the statement cache may be in effect.
*
* @param td the TableDescriptor to check
*
* @exception StandardException standard error policy.
*/
private void bindPrivilegesForView(TableDescriptor td) throws StandardException {
LanguageConnectionContext lcc = getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
ViewDescriptor vd = dd.getViewDescriptor(td);
DependencyManager dm = dd.getDependencyManager();
ProviderInfo[] pis = dm.getPersistentProviderInfos(vd);
this.descriptorList = new ArrayList<Provider>();
int siz = pis.length;
for (int i = 0; i < siz; i++) {
Provider provider = (Provider) pis[i].getDependableFinder().getDependable(dd, pis[i].getObjectId());
if (provider instanceof TableDescriptor || provider instanceof ViewDescriptor || provider instanceof AliasDescriptor) {
descriptorList.add(provider);
}
}
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class CreateViewNode method bindViewDefinition.
/**
* Bind the query expression for a view definition.
*
* @param dataDictionary The DataDictionary to use to look up
* columns, tables, etc.
*
* @return Array of providers that this view depends on.
*
* @exception StandardException Thrown on error
*/
private ProviderInfo[] bindViewDefinition(DataDictionary dataDictionary, CompilerContext compilerContext, LanguageConnectionContext lcc, OptimizerFactory optimizerFactory, ResultSetNode queryExpr, ContextManager cm) throws StandardException {
FromList fromList = new FromList(optimizerFactory.doJoinOrderOptimization(), cm);
ProviderList prevAPL = compilerContext.getCurrentAuxiliaryProviderList();
ProviderList apl = new ProviderList();
try {
compilerContext.setCurrentAuxiliaryProviderList(apl);
compilerContext.pushCurrentPrivType(Authorizer.SELECT_PRIV);
/* Bind the tables in the queryExpression */
queryExpr = queryExpr.bindNonVTITables(dataDictionary, fromList);
queryExpr = queryExpr.bindVTITables(fromList);
/* Bind the expressions under the resultSet */
queryExpr.bindExpressions(fromList);
// cannot define views on temporary tables
if (queryExpr instanceof SelectNode) {
// If attempting to reference a SESSION schema table (temporary or permanent) in the view, throw an exception
if (queryExpr.referencesSessionSchema())
throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES);
}
// bind the query expression
queryExpr.bindResultColumns(fromList);
// rejects any untyped nulls in the RCL
// e.g.: CREATE VIEW v1 AS VALUES NULL
queryExpr.bindUntypedNullsToResultColumns(null);
} finally {
compilerContext.popCurrentPrivType();
compilerContext.setCurrentAuxiliaryProviderList(prevAPL);
}
DependencyManager dm = dataDictionary.getDependencyManager();
ProviderInfo[] provInfo = dm.getPersistentProviderInfos(apl);
// need to clear the column info in case the same table descriptor
// is reused, eg., in multiple target only view definition
dm.clearColumnInfoInProviders(apl);
/* Verify that all underlying ResultSets reclaimed their FromList */
if (SanityManager.DEBUG) {
SanityManager.ASSERT(fromList.size() == 0, "fromList.size() is expected to be 0, not " + fromList.size() + " on return from RS.bindExpressions()");
}
return provInfo;
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class InsertResultSet method bulkInsertCore.
// Do the work for a bulk insert
private void bulkInsertCore(LanguageConnectionContext lcc, ExecRow fullTemplate, long oldHeapConglom) throws StandardException {
bulkHeapCC = tc.openCompiledConglomerate(false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, constants.heapSCOCI, heapDCOCI);
long newHeapConglom;
Properties properties = new Properties();
// Get the properties on the old heap
bulkHeapCC.getInternalTablePropertySet(properties);
if (triggerInfo != null) {
// no triggers in bulk insert mode
if (SanityManager.DEBUG) {
SanityManager.NOTREACHED();
}
}
/*
** If we have a before row trigger, then we
** are going to use a row holder pass to our
** trigger.
*/
if (hasBeforeRowTrigger && rowHolder != null) {
rowHolder = new TemporaryRowHolderImpl(activation, properties, resultDescription);
}
// Add any new properties or change the values of any existing properties
Properties targetProperties = constants.getTargetProperties();
Enumeration key = targetProperties.keys();
while (key.hasMoreElements()) {
String keyValue = (String) key.nextElement();
properties.put(keyValue, targetProperties.getProperty(keyValue));
}
// Are there indexes to be updated?
if (constants.irgs.length > 0) {
// Tell source whether or not we need the RIDs back
sourceResultSet.setNeedsRowLocation(true);
}
if (constants.hasDeferrableChecks) {
sourceResultSet.setHasDeferrableChecks();
}
dd = lcc.getDataDictionary();
td = dd.getTableDescriptor(constants.targetUUID);
/* Do the bulk insert - only okay to reuse the
* same conglomerate if bulkInsert.
*/
long[] loadedRowCount = new long[1];
if (bulkInsertReplace) {
newHeapConglom = tc.createAndLoadConglomerate("heap", fullTemplate.getRowArray(), // column sort order - not required for heap
null, td.getColumnCollationIds(), properties, TransactionController.IS_DEFAULT, sourceResultSet, loadedRowCount);
} else {
newHeapConglom = tc.recreateAndLoadConglomerate("heap", false, fullTemplate.getRowArray(), // column sort order - not required for heap
null, td.getColumnCollationIds(), properties, TransactionController.IS_DEFAULT, oldHeapConglom, sourceResultSet, loadedRowCount);
}
/* Nothing else to do if we get back the same conglomerate number.
* (In 2.0 this means that 0 rows were inserted.)
*/
if (newHeapConglom == oldHeapConglom) {
return;
}
// Find out how many rows were inserted
rowCount = loadedRowCount[0];
// Set the "estimated" row count
setEstimatedRowCount(newHeapConglom);
/*
** 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);
//
if (identitySequenceUUIDString == null) {
lcc.autoincrementFlushCache(constants.targetUUID);
} else {
for (BulkInsertCounter bic : bulkInsertCounters) {
if (bic != null) {
dd.flushBulkInsertCounter(identitySequenceUUIDString, bic);
}
}
}
// invalidate any prepared statements that
// depended on this table (including this one)
DependencyManager dm = dd.getDependencyManager();
dm.invalidateFor(td, DependencyManager.BULK_INSERT, lcc);
// Update all indexes
if (constants.irgs.length > 0) {
// MEN VI HAR MANGE SORTS, EN PR INDEX: alle blir droppet, hvordan
// assossiere alle med nye indekser som tildeles inni her???
// FIXME!!
updateAllIndexes(newHeapConglom, constants, td, dd, fullTemplate);
}
// Drop the old conglomerate
bulkHeapCC.close();
bulkHeapCC = null;
/* Update the DataDictionary
* RESOLVE - this will change in 1.4 because we will get
* back the same conglomerate number
*/
// Get the ConglomerateDescriptor for the heap
ConglomerateDescriptor cd = td.getConglomerateDescriptor(oldHeapConglom);
// Update sys.sysconglomerates with new conglomerate #
dd.updateConglomerateDescriptor(cd, newHeapConglom, tc);
tc.dropConglomerate(oldHeapConglom);
// END RESOLVE
}
use of org.apache.derby.iapi.sql.depend.DependencyManager in project derby by apache.
the class StatementTablePermission method hasPermissionOnTable.
// end of getTableDescriptor
/**
* Check if current session has permission on the table (current user,
* PUBLIC or role) and, if applicable, register a dependency of ps on the
* current role.
*
* @param lcc the current language connection context
* @param activation the activation of ps
* @param forGrant true if FOR GRANT is required
* @param ps the prepared statement for which we are checking necessary
* privileges
*/
protected boolean hasPermissionOnTable(LanguageConnectionContext lcc, Activation activation, boolean forGrant, ExecPreparedStatement ps) throws StandardException {
DataDictionary dd = lcc.getDataDictionary();
String currentUserId = lcc.getCurrentUserId(activation);
boolean result = oneAuthHasPermissionOnTable(dd, Authorizer.PUBLIC_AUTHORIZATION_ID, forGrant) || oneAuthHasPermissionOnTable(dd, currentUserId, forGrant);
if (!result) {
// Since no permission exists for the current user or PUBLIC,
// check if a permission exists for the current role (if set).
String role = lcc.getCurrentRoleId(activation);
if (role != null) {
// Check that role is still granted to current user or
// to PUBLIC: A revoked role which is current for this
// session, is lazily set to none when it is attempted
// used.
String dbo = dd.getAuthorizationDatabaseOwner();
RoleGrantDescriptor rd = dd.getRoleGrantDescriptor(role, currentUserId, dbo);
if (rd == null) {
rd = dd.getRoleGrantDescriptor(role, Authorizer.PUBLIC_AUTHORIZATION_ID, dbo);
}
if (rd == null) {
// We have lost the right to set this role, so we can't
// make use of any permission granted to it or its
// ancestors.
lcc.setCurrentRole(activation, null);
} else {
// The current role is OK, so we can make use of
// any permission granted to it.
//
// Look at the current role and, if necessary, the
// transitive closure of roles granted to current role to
// see if permission has been granted to any of the
// applicable roles.
RoleClosureIterator rci = dd.createRoleClosureIterator(activation.getTransactionController(), role, true);
String r;
while (!result && (r = rci.next()) != null) {
result = oneAuthHasPermissionOnTable(dd, r, forGrant);
}
if (result) {
// Also add a dependency on the role (qua provider), so
// that if role is no longer available to the current
// user (e.g. grant is revoked, role is dropped,
// another role has been set), we are able to
// invalidate the ps or activation (the latter is used
// if the current role changes).
DependencyManager dm = dd.getDependencyManager();
RoleGrantDescriptor rgd = dd.getRoleDefinitionDescriptor(role);
ContextManager cm = lcc.getContextManager();
dm.addDependency(ps, rgd, cm);
dm.addDependency(activation, rgd, cm);
}
}
}
}
return result;
}
Aggregations