Search in sources :

Example 6 with ProviderInfo

use of org.apache.derby.iapi.sql.depend.ProviderInfo in project derby by apache.

the class BasicDependencyManager method getPersistentProviderInfos.

/**
 * @see DependencyManager#getPersistentProviderInfos
 *
 * @exception StandardException		Thrown on error
 */
public ProviderInfo[] getPersistentProviderInfos(ProviderList pl) throws StandardException {
    Enumeration e = pl.elements();
    int numProviders = 0;
    ProviderInfo[] retval;
    /*
		** We make 2 passes - the first to count the number of persistent
 		** providers and the second to populate the array of ProviderInfos.
		*/
    while (e != null && e.hasMoreElements()) {
        Provider prov = (Provider) e.nextElement();
        if (prov.isPersistent()) {
            numProviders++;
        }
    }
    e = pl.elements();
    retval = new ProviderInfo[numProviders];
    int piCtr = 0;
    while (e != null && e.hasMoreElements()) {
        Provider prov = (Provider) e.nextElement();
        if (prov.isPersistent()) {
            retval[piCtr++] = new BasicProviderInfo(prov.getObjectID(), prov.getDependableFinder(), prov.getObjectName());
        }
    }
    return retval;
}
Also used : Enumeration(java.util.Enumeration) ProviderInfo(org.apache.derby.iapi.sql.depend.ProviderInfo) Provider(org.apache.derby.iapi.sql.depend.Provider)

Example 7 with ProviderInfo

use of org.apache.derby.iapi.sql.depend.ProviderInfo 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);
        }
    }
}
Also used : ProviderInfo(org.apache.derby.iapi.sql.depend.ProviderInfo) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ViewDescriptor(org.apache.derby.iapi.sql.dictionary.ViewDescriptor) Provider(org.apache.derby.iapi.sql.depend.Provider)

Example 8 with ProviderInfo

use of org.apache.derby.iapi.sql.depend.ProviderInfo 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;
}
Also used : ProviderList(org.apache.derby.iapi.sql.depend.ProviderList) ProviderInfo(org.apache.derby.iapi.sql.depend.ProviderInfo) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager)

Aggregations

ProviderInfo (org.apache.derby.iapi.sql.depend.ProviderInfo)8 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)6 Provider (org.apache.derby.iapi.sql.depend.Provider)5 UUID (org.apache.derby.catalog.UUID)3 ProviderList (org.apache.derby.iapi.sql.depend.ProviderList)3 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)2 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)2 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 DependableFinder (org.apache.derby.catalog.DependableFinder)1 ContextManager (org.apache.derby.iapi.services.context.ContextManager)1 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)1 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)1 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)1 DefaultDescriptor (org.apache.derby.iapi.sql.dictionary.DefaultDescriptor)1 SPSDescriptor (org.apache.derby.iapi.sql.dictionary.SPSDescriptor)1 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)1 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)1 TriggerDescriptor (org.apache.derby.iapi.sql.dictionary.TriggerDescriptor)1 ViewDescriptor (org.apache.derby.iapi.sql.dictionary.ViewDescriptor)1