Search in sources :

Example 11 with SPSDescriptor

use of org.apache.derby.iapi.sql.dictionary.SPSDescriptor in project derby by apache.

the class DataDictionaryImpl method createSPSSet.

/**
 *		Create a set of stored prepared statements from a properties file.
 *		Key is the statement name, value is the SQL statement.
 */
protected void createSPSSet(TransactionController tc, boolean net, UUID schemaID) throws StandardException {
    Properties p = getQueryDescriptions(net);
    Enumeration e = p.keys();
    // statement will get compiled on first execution
    // Note: Don't change this to FALSE LCC is not available for compiling
    boolean nocompile = true;
    while (e.hasMoreElements()) {
        String spsName = (String) e.nextElement();
        String spsText = p.getProperty(spsName);
        SPSDescriptor spsd = new SPSDescriptor(this, spsName, getUUIDFactory().createUUID(), schemaID, schemaID, SPSDescriptor.SPS_TYPE_REGULAR, // it is valid, unless nocompile
        !nocompile, // sps text
        spsText, !nocompile);
        addSPSDescriptor(spsd, tc);
    }
}
Also used : Enumeration(java.util.Enumeration) Properties(java.util.Properties) SPSDescriptor(org.apache.derby.iapi.sql.dictionary.SPSDescriptor)

Example 12 with SPSDescriptor

use of org.apache.derby.iapi.sql.dictionary.SPSDescriptor in project derby by apache.

the class DataDictionaryImpl method getAllSPSDescriptors.

/**
 * Get every statement in this database.
 * Return the SPSDescriptors in an list.
 * The returned descriptors don't contain the compiled statement, so it
 * it safe to call this method during upgrade when it isn't known if the
 * saved statement can still be deserialized with the new version.
 *
 * @return the list of descriptors
 *
 * @exception StandardException		Thrown on failure
 */
public List<SPSDescriptor> getAllSPSDescriptors() throws StandardException {
    TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM);
    List<SPSDescriptor> list = newSList();
    // DERBY-3870: The compiled plan may not be possible to deserialize
    // during upgrade. Skip the column that contains the compiled plan to
    // prevent deserialization errors when reading the rows. We don't care
    // about the value in that column, since this method is only called
    // when we want to drop or invalidate rows in SYSSTATEMENTS.
    FormatableBitSet cols = new FormatableBitSet(ti.getCatalogRowFactory().getHeapColumnCount());
    for (int i = 0; i < cols.size(); i++) {
        if (i + 1 == SYSSTATEMENTSRowFactory.SYSSTATEMENTS_CONSTANTSTATE) {
            cols.clear(i);
        } else {
            cols.set(i);
        }
    }
    getDescriptorViaHeap(cols, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, list, SPSDescriptor.class);
    return list;
}
Also used : FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) SPSDescriptor(org.apache.derby.iapi.sql.dictionary.SPSDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 13 with SPSDescriptor

use of org.apache.derby.iapi.sql.dictionary.SPSDescriptor in project derby by apache.

the class DataDictionaryImpl method getSPSDescriptorIndex1Scan.

/**
 * Scan sysschemas_index1 (stmtname, schemaid) for a match.
 *
 * @return SPSDescriptor	The matching descriptor, if any.
 *
 * @exception StandardException		Thrown on failure
 */
private SPSDescriptor getSPSDescriptorIndex1Scan(String stmtName, String schemaUUID) throws StandardException {
    DataValueDescriptor schemaIDOrderable;
    DataValueDescriptor stmtNameOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM);
    /* Use stmtNameOrderable and schemaIdOrderable in both start 
		 * and stop position for scan. 
		 */
    stmtNameOrderable = new SQLVarchar(stmtName);
    schemaIDOrderable = new SQLChar(schemaUUID);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(2);
    keyRow.setColumn(1, stmtNameOrderable);
    keyRow.setColumn(2, schemaIDOrderable);
    SPSDescriptor spsd = getDescriptorViaIndex(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_INDEX2_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, SPSDescriptor.class, false);
    /*
		** Set up the parameter defaults.  We are only
		** doing this when we look up by name because
		** this is the only time we cache, and it can
		** be foolish to look up the parameter defaults
		** for someone that doesn't need them.
		*/
    if (spsd != null) {
        List<DataValueDescriptor> tmpDefaults = new ArrayList<DataValueDescriptor>();
        spsd.setParams(getSPSParams(spsd, tmpDefaults));
        Object[] defaults = tmpDefaults.toArray();
        spsd.setParameterDefaults(defaults);
    }
    return spsd;
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) ArrayList(java.util.ArrayList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) SPSDescriptor(org.apache.derby.iapi.sql.dictionary.SPSDescriptor)

Example 14 with SPSDescriptor

use of org.apache.derby.iapi.sql.dictionary.SPSDescriptor in project derby by apache.

the class GenericPreparedStatement method makeInvalid.

/**
 *		Mark the dependent as invalid (due to at least one of
 *		its dependencies being invalid).
 *
 *		@param	action	The action causing the invalidation
 *
 *	 	@exception StandardException Standard Derby error policy.
 */
public void makeInvalid(int action, LanguageConnectionContext lcc) throws StandardException {
    boolean alreadyInvalid;
    switch(action) {
        case DependencyManager.RECHECK_PRIVILEGES:
            return;
    }
    synchronized (this) {
        if (compilingStatement) {
            // Since the statement is in the process of being compiled,
            // and at the end of the compilation it will set isValid to
            // true and overwrite whatever we set it to here, set another
            // flag to indicate that an invalidation was requested. A
            // re-compilation will be triggered if this flag is set, but
            // not until the current compilation is done.
            invalidatedWhileCompiling = true;
            return;
        }
        alreadyInvalid = !isValid;
        // make ourseleves invalid
        isValid = false;
        // block compiles while we are invalidating
        beginCompiling();
    }
    try {
        DependencyManager dm = lcc.getDataDictionary().getDependencyManager();
        /* Clear out the old dependencies on this statement as we
			 * will build the new set during the reprepare in makeValid().
			 */
        dm.clearDependencies(lcc, this);
        /*
			** If we are invalidating an EXECUTE STATEMENT because of a stale
			** plan, we also need to invalidate the stored prepared statement.
			*/
        if (execStmtName != null) {
            switch(action) {
                case DependencyManager.INTERNAL_RECOMPILE_REQUEST:
                case DependencyManager.CHANGED_CURSOR:
                    {
                        /*
					** Get the DataDictionary, so we can get the descriptor for
					** the SPP to invalidate it.
					*/
                        DataDictionary dd = lcc.getDataDictionary();
                        SchemaDescriptor sd = dd.getSchemaDescriptor(execSchemaName, lcc.getTransactionCompile(), true);
                        SPSDescriptor spsd = dd.getSPSDescriptor(execStmtName, sd);
                        spsd.makeInvalid(action, lcc);
                        break;
                    }
            }
        }
    } finally {
        endCompiling();
    }
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) SPSDescriptor(org.apache.derby.iapi.sql.dictionary.SPSDescriptor)

Aggregations

SPSDescriptor (org.apache.derby.iapi.sql.dictionary.SPSDescriptor)14 UUID (org.apache.derby.catalog.UUID)4 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)4 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)3 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)3 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)3 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)2 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)2 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)2 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)2 SQLChar (org.apache.derby.iapi.types.SQLChar)2 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)2 StandardException (org.apache.derby.shared.common.error.StandardException)2 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 CacheFactory (org.apache.derby.iapi.services.cache.CacheFactory)1