Class SPSDescriptor

  • All Implemented Interfaces:
    Dependable, Dependent, Provider

    public class SPSDescriptor
    extends UniqueSQLObjectDescriptor
    implements Dependent, Provider
    A SPSDescriptor describes a Stored Prepared Statement. It correlates to a row in SYS.SYSSTATEMENTS. SYNCHRONIZATION: Stored prepared statements may be cached. Thus they may be shared by multiple threads. It is very hard for two threads to try to muck with an sps simultaeously because all ddl (including sps recompilation) clears out the sps cache and invalidates whatever statement held a cached sps. But it is possible for two statements to do a prepare execute statment at the exact same time, so both try to do an sps.prepare() at the same time during code generation, so we synchronize most everything except getters on immutable objects just to be on the safe side.
    • Field Detail

      • SPS_TYPE_TRIGGER

        public static final char SPS_TYPE_TRIGGER
        Statement types.
        • SPS_TYPE_TRIGGER - trigger
        • SPS_TYPE_EXPLAIN - explain (NOT IMPLEMENTED)
        • SPS_TYPE_REGULAR - catchall
        See Also:
        Constant Field Values
      • RECOMPILE

        private static final int RECOMPILE
        interface to this class is:
        1. public void prepare() throws StandardException;
        2. public void prepareAndRelease(LanguageConnectionContext lcc) throws StandardException;
        3. public void prepareAndRelease(...);
        4. public String getQualifiedName();
        5. public char getType();
        6. public String getTypeAsString();
        7. public boolean isValid();
        8. public boolean initiallyCompilable();
        9. public java.sql.Timestamp getCompileTime();
        10. public void setCompileTime();
        11. public String getText();
        12. public String getUsingText();
        13. public void setUsingText(String usingText);
        14. public void setUUID(UUID uuid);
        15. public DataTypeDescriptor[] getParams() throws StandardException;
        16. public void setParams(DataTypeDescriptor[] params);
        17. Object[] getParameterDefaults() throws StandardException;
        18. void setParameterDefaults(Object[] values);
        19. public UUID getCompSchemaId();
        20. public ExecPreparedStatement getPreparedStatement() throws StandardException;
        21. public ExecPreparedStatement getPreparedStatement(boolean recompIfInvalid) throws StandardException;
        22. public void revalidate(LanguageConnectionContext lcc) throws StandardException;
        See Also:
        Constant Field Values
      • name

        private final java.lang.String name
      • compSchemaId

        private final UUID compSchemaId
      • type

        private final char type
      • text

        private java.lang.String text
      • usingText

        private final java.lang.String usingText
      • uuid

        private final UUID uuid
      • valid

        private boolean valid
      • compileTime

        private java.sql.Timestamp compileTime
      • paramDefaults

        private java.lang.Object[] paramDefaults
        Old code - never used.
      • initiallyCompilable

        private final boolean initiallyCompilable
      • lookedUpParams

        private boolean lookedUpParams
    • Constructor Detail

      • SPSDescriptor

        public SPSDescriptor​(DataDictionary dataDictionary,
                             java.lang.String name,
                             UUID uuid,
                             UUID suuid,
                             UUID compSchemaUUID,
                             char type,
                             boolean valid,
                             java.lang.String text,
                             boolean initiallyCompilable)
                      throws StandardException
        Constructor for a SPS Descriptor
        Parameters:
        dataDictionary - The data dictionary that this descriptor lives in
        name - the SPS name
        uuid - the UUID
        suuid - the schema UUID
        compSchemaUUID - the schema UUID at compilation time
        type - type
        valid - is the sps valid
        text - the text for this statement
        initiallyCompilable - is the statement initially compilable?
        Throws:
        StandardException - on error
      • SPSDescriptor

        public SPSDescriptor​(DataDictionary dataDictionary,
                             java.lang.String name,
                             UUID uuid,
                             UUID suuid,
                             UUID compSchemaUUID,
                             char type,
                             boolean valid,
                             java.lang.String text,
                             java.lang.String usingText,
                             java.sql.Timestamp compileTime,
                             ExecPreparedStatement preparedStatement,
                             boolean initiallyCompilable)
                      throws StandardException
        Constructor for a SPS Descriptor. Used when constructing an SPS descriptor from a row in SYSSTATEMENTS.
        Parameters:
        dataDictionary - The data dictionary that this descriptor lives in
        name - the SPS name
        uuid - the UUID
        suuid - the schema UUID
        compSchemaUUID - the schema UUID at compilation time
        type - type
        valid - is the sps valid
        text - the text for this statement
        usingText - the text for the USING clause supplied to CREATE or ALTER STATEMENT
        compileTime - the time this was compiled
        preparedStatement - the PreparedStatement
        initiallyCompilable - is the statement initially compilable?
        Throws:
        StandardException - on error
    • Method Detail

      • prepareAndRelease

        public final void prepareAndRelease​(LanguageConnectionContext lcc,
                                            TableDescriptor triggerTable,
                                            TransactionController tc)
                                     throws StandardException
        FOR TRIGGERS ONLY

        Generate the class for this SPS and immediately release it. This is useful for cases where we don't want to immediately execute the statement corresponding to this sps (e.g. CREATE STATEMENT).

        SIDE EFFECTS: will update and SYSDEPENDS with the prepared statement dependency info.

        Parameters:
        lcc - the language connection context
        triggerTable - the table descriptor to bind against. Had better be null if this isn't a trigger sps.
        tc - the transaction controller
        Throws:
        StandardException - on error
      • prepareAndRelease

        public final void prepareAndRelease​(LanguageConnectionContext lcc,
                                            TableDescriptor triggerTable)
                                     throws StandardException
        FOR TRIGGERS ONLY

        Generate the class for this SPS and immediately release it. This is useful for cases where we don't want to immediately execute the statement corresponding to this sps (e.g. CREATE STATEMENT).

        SIDE EFFECTS: will update and SYSDEPENDS with the prepared statement dependency info.

        Parameters:
        lcc - the language connection context
        triggerTable - the table descriptor to bind against. Had better be null if this isn't a trigger sps.
        Throws:
        StandardException - on error
      • prepareAndRelease

        public final void prepareAndRelease​(LanguageConnectionContext lcc)
                                     throws StandardException
        Generate the class for this SPS and immediately release it. This is useful for cases where we don't want to immediately execute the statement corresponding to this sps (e.g. CREATE STATEMENT).

        SIDE EFFECTS: will update and SYSDEPENDS with the prepared statement dependency info.

        Parameters:
        lcc - the language connection context
        Throws:
        StandardException - on error
      • compileStatement

        private void compileStatement​(LanguageConnectionContext lcc,
                                      TableDescriptor triggerTable,
                                      TransactionController tc)
                               throws StandardException
        Compiles this SPS.

        Note: This SPS may still be marked as invalid after this method has completed, because an invalidation request may have been received while compiling.

        Parameters:
        lcc - connection
        triggerTable - subject table (may be null)
        tc - transaction controller to use (may be null)
        Throws:
        StandardException - if something fails
      • getName

        public final java.lang.String getName()
        Gets the name of the sps.
        Specified by:
        getName in class UniqueSQLObjectDescriptor
        Returns:
        A String containing the name of the statement.
      • getQualifiedName

        public final java.lang.String getQualifiedName()
        Gets the full, qualified name of the statement.
        Returns:
        A String containing the name of the statement.
      • getType

        public final char getType()
        Gets an identifier telling what type of table this is. Types match final ints in this interface. Currently returns SPS_TYPE_REGULAR or SPS_TYPE_TRIGGER.
        Returns:
        An identifier telling what type of statement we are.
      • getTypeAsString

        public final java.lang.String getTypeAsString()
        Simple little helper function to convert your type to a string, which is easier to use.
        Returns:
        type as a string
      • initiallyCompilable

        public boolean initiallyCompilable()
        Is the statement initially compilable?
        Returns:
        false if statement was created with the NOCOMPILE flag true otherwise
      • validType

        public static boolean validType​(char type)
        Validate the type. NOTE: Only SPS_TYPE_REGULAR and SPS_TYPE_TRIGGER are currently valid.
        Parameters:
        type - the type
        Returns:
        true/false
      • getCompileTime

        public final java.sql.Timestamp getCompileTime()
        The time this prepared statement was compiled
        Returns:
        the time this class was last compiled
      • setCompileTime

        public final void setCompileTime()
        Set the compile time to now
      • getText

        public final java.lang.String getText()
        Get the text used to create this statement. Returns original text in a cleartext string.
        Returns:
        The text
      • setText

        public final void setText​(java.lang.String newText)
        It is possible that when a trigger is invalidated, the generated trigger action sql associated with it needs to be regenerated. One example of such a case would be when ALTER TABLE on the trigger table changes the length of a column. The need for this code was found as part of DERBY-4874 where the Alter table had changed the length of a varchar column from varchar(30) to varchar(64) but the generated trigger action plan continued to use varchar(30). To fix varchar(30) in in trigger action sql to varchar(64), we need to regenerate the trigger action sql which is saved as stored prepared statement. This new trigger action sql will then get updated into SYSSTATEMENTS table. DERBY-4874
        Parameters:
        newText -
      • getUsingText

        public final java.lang.String getUsingText()
        Get the text of the USING clause used on CREATE or ALTER statement.
        Returns:
        The text
      • getParams

        public final DataTypeDescriptor[] getParams()
                                             throws StandardException
        Get the array of date type descriptors for this statement. Currently, we do a lookup if we don't already have the parameters saved. When SPSes are cached, the parameters should be set up when the sps is constructed.
        Returns:
        the array of data type descriptors
        Throws:
        StandardException - on error
      • setParams

        public final void setParams​(DataTypeDescriptor[] params)
        Set the list of parameters for this statement
        Parameters:
        params - the parameter list
      • getParameterDefaults

        public final java.lang.Object[] getParameterDefaults()
                                                      throws StandardException
        Get the default parameter values for this statement. Default parameter values are supplied by a USING clause on either a CREATE or ALTER STATEMENT statement.
        Returns:
        the default parameter values
        Throws:
        StandardException - on error
      • setParameterDefaults

        public final void setParameterDefaults​(java.lang.Object[] values)
        Set the parameter defaults for this statement.
        Parameters:
        values - the parameter defaults
      • getPreparedStatement

        public final ExecPreparedStatement getPreparedStatement()
                                                         throws StandardException
        Get the preparedStatement for this statement. If stmt is invalid or hasn't been compiled yet, it will be recompiled.
        Returns:
        the preparedStatement
        Throws:
        StandardException - on error
      • getPreparedStatement

        public final ExecPreparedStatement getPreparedStatement​(boolean recompIfInvalid)
                                                         throws StandardException
        Get the preparedStatement for this statement. Expects the prepared statement to have already been added to SYS.SYSSTATEMENTS.

        Side Effects: will update SYS.SYSSTATEMENTS with the new plan if it needs to be recompiled.

        Parameters:
        recompIfInvalid - if false, never recompile even if statement is invalid
        Returns:
        the preparedStatement
        Throws:
        StandardException - on error
      • getCompSchemaId

        public final UUID getCompSchemaId()
        Get the compilation type schema id when this view was first bound.
        Returns:
        the schema UUID
      • toString

        public final java.lang.String toString()
        Prints the contents of the TableDescriptor
        Overrides:
        toString in class java.lang.Object
        Returns:
        The contents as a String
      • getObjectName

        public final java.lang.String getObjectName()
        Return the name of this Provider. (Useful for errors.)
        Specified by:
        getObjectName in interface Dependable
        Returns:
        String The name of this provider.
      • getObjectID

        public final UUID getObjectID()
        Get the provider's UUID
        Specified by:
        getObjectID in interface Dependable
        Returns:
        String The provider's UUID
      • getClassType

        public final java.lang.String getClassType()
        Get the provider's type.
        Specified by:
        getClassType in interface Dependable
        Returns:
        String The provider's type.
      • isValid

        public final boolean isValid()
        Check that all of the dependent's dependencies are valid.
        Specified by:
        isValid in interface Dependent
        Returns:
        true if the dependent is currently valid
      • prepareToInvalidate

        public final void prepareToInvalidate​(Provider p,
                                              int action,
                                              LanguageConnectionContext lcc)
                                       throws StandardException
        Prepare to mark the dependent as invalid (due to at least one of its dependencies being invalid).
        Specified by:
        prepareToInvalidate in interface Dependent
        Parameters:
        action - The action causing the invalidation
        p - the provider
        lcc - The LanguageConnectionContext
        Throws:
        StandardException - thrown if unable to make it invalid
      • makeInvalid

        public final void makeInvalid​(int action,
                                      LanguageConnectionContext lcc)
                               throws StandardException
        Mark the dependent as invalid (due to at least one of its dependencies being invalid).
        Specified by:
        makeInvalid in interface Dependent
        Parameters:
        action - The action causing the invalidation
        lcc - The LanguageConnectionContext
        Throws:
        StandardException - thrown if unable to make it invalid
      • loadGeneratedClass

        public void loadGeneratedClass()
                                throws StandardException
        Load the underlying generatd class. This is not expected to be used outside of the datadictionary package. It is used for optimizing class loading for sps cacheing.
        Throws:
        StandardException - on error
      • recreateUUID

        private UUID recreateUUID​(java.lang.String idString)
        Get the UUID for the given string
        Parameters:
        idString - the string
        Returns:
        the UUID
      • getContextService

        private static ContextService getContextService()
        Privileged lookup of the ContextService. Must be private so that user code can't call this entry point.