use of org.apache.derby.iapi.sql.dictionary.ViewDescriptor in project derby by apache.
the class BasicDependencyManager method coreInvalidateFor.
/**
* A version of invalidateFor that does not provide synchronization among
* invalidators.
*
* @param p the provider
* @param action the action causing the invalidation
* @param lcc language connection context
*
* @throws StandardException if something goes wrong
*/
private void coreInvalidateFor(Provider p, int action, LanguageConnectionContext lcc) throws StandardException {
List<Dependency> list = getDependents(p);
if (list.isEmpty()) {
return;
}
// affectedCols is passed in from table descriptor provider to indicate
// which columns it cares; subsetCols is affectedCols' intersection
// with column bit map found in the provider of SYSDEPENDS line to
// find out which columns really matter. If SYSDEPENDS line's
// dependent is view (or maybe others), provider is table, yet it
// doesn't have column bit map because the view was created in a
// previous version of server which doesn't support column dependency,
// and we really want it to have (such as in drop column), in any case
// if we passed in table descriptor to this function with a bit map,
// we really need this, we generate the bitmaps on the fly and update
// SYSDEPENDS
//
// Note: Since the "previous version of server" mentioned above must
// be a version that predates Derby, and we don't support upgrade from
// those versions, we no longer have code to generate the column
// dependency list on the fly. Instead, an assert has been added to
// verify that we always have a column bitmap in SYSDEPENDS if the
// affectedCols bitmap is non-null.
FormatableBitSet affectedCols = null, subsetCols = null;
if (p instanceof TableDescriptor) {
affectedCols = ((TableDescriptor) p).getReferencedColumnMap();
if (affectedCols != null)
subsetCols = new FormatableBitSet(affectedCols.getLength());
}
{
StandardException noInvalidate = null;
// entries from this list.
for (int ei = list.size() - 1; ei >= 0; ei--) {
if (ei >= list.size())
continue;
Dependency dependency = list.get(ei);
Dependent dep = dependency.getDependent();
if (affectedCols != null) {
TableDescriptor td = (TableDescriptor) dependency.getProvider();
FormatableBitSet providingCols = td.getReferencedColumnMap();
if (providingCols == null) {
if (dep instanceof ViewDescriptor) {
// this code was removed as part of DERBY-6169.
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("Expected view to " + "have referenced column bitmap");
}
} else
// if dep instanceof ViewDescriptor
((TableDescriptor) p).setReferencedColumnMap(null);
} else // if providingCols == null
{
subsetCols.copyFrom(affectedCols);
subsetCols.and(providingCols);
if (subsetCols.anySetBit() == -1)
continue;
((TableDescriptor) p).setReferencedColumnMap(subsetCols);
}
}
// generate a list of invalidations that fail.
try {
dep.prepareToInvalidate(p, action, lcc);
} catch (StandardException sqle) {
if (noInvalidate == null) {
noInvalidate = sqle;
} else {
try {
sqle.initCause(noInvalidate);
noInvalidate = sqle;
} catch (IllegalStateException ise) {
// We weren't able to chain the exceptions. That's
// OK, since we always have the first exception we
// caught. Just skip the current exception.
}
}
}
if (noInvalidate == null) {
if (affectedCols != null)
((TableDescriptor) p).setReferencedColumnMap(affectedCols);
// REVISIT: future impl will want to mark the individual
// dependency as invalid as well as the dependent...
dep.makeInvalid(action, lcc);
}
}
if (noInvalidate != null)
throw noInvalidate;
}
}
use of org.apache.derby.iapi.sql.dictionary.ViewDescriptor in project derby by apache.
the class DropViewConstantAction method executeConstantAction.
// INTERFACE METHODS
/**
* This is the guts of the Execution-time logic for DROP VIEW.
*
* @see ConstantAction#executeConstantAction
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
TableDescriptor td;
ViewDescriptor vd;
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
/*
** 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);
/* Get the table descriptor. We're responsible for raising
* the error if it isn't found
*/
td = dd.getTableDescriptor(tableName, sd, lcc.getTransactionExecute());
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, fullTableName);
}
/* Verify that TableDescriptor represents a view */
if (td.getTableType() != TableDescriptor.VIEW_TYPE) {
throw StandardException.newException(SQLState.LANG_DROP_VIEW_ON_NON_VIEW, fullTableName);
}
vd = dd.getViewDescriptor(td);
vd.drop(lcc, sd, td);
}
use of org.apache.derby.iapi.sql.dictionary.ViewDescriptor 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.dictionary.ViewDescriptor 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.
}
}
}
}
Aggregations