Class JDBCStoreManager

    • Constructor Detail

      • JDBCStoreManager

        public JDBCStoreManager()
    • Method Detail

      • setContext

        public void setContext​(StoreContext ctx)
        Description copied from interface: StoreManager
        Set a reference to the corresponding context. This method will be called before the store manager is used. The store manager is responsible for pulling any necessary configuration data from the context, including the transaction mode and connection retain mode.
        Specified by:
        setContext in interface StoreManager
      • beginOptimistic

        public void beginOptimistic()
        Description copied from interface: StoreManager
        Notification that an optimistic transaction has started. This method does not replace the StoreManager.begin() method, which will still be called when a true data store transaction should begin.
        Specified by:
        beginOptimistic in interface StoreManager
      • rollbackOptimistic

        public void rollbackOptimistic()
        Description copied from interface: StoreManager
        Notification that an optimistic transaction was rolled back before a data store transaction ever began.
        Specified by:
        rollbackOptimistic in interface StoreManager
      • begin

        public void begin()
        Description copied from interface: StoreManager
        Begin a data store transaction. After this method is called, it is assumed that all further operations are operating in a single transaction that can be committed or rolled back. If optimistic transactions are in use, this method will only be called when the system requires a transactionally consistent connection due to a user request to flush or commit the transaction. In this case, it is possible that the optimistic transaction does not have the latest versions of all instances (i.e. another transaction has modified the same instances and committed since the optimistic transaction started). On commit, an exception must be thrown on any attempt to overwrite data for an instance with an older version.
        Specified by:
        begin in interface StoreManager
      • commit

        public void commit()
        Description copied from interface: StoreManager
        Commit the current data store transaction.
        Specified by:
        commit in interface StoreManager
      • rollback

        public void rollback()
        Description copied from interface: StoreManager
        Rollback the current data store transaction.
        Specified by:
        rollback in interface StoreManager
      • retainConnection

        public void retainConnection()
        Description copied from interface: StoreManager
        Instruct the store to retain a connection for continued use. This will be invoked automatically based on the user's configured connection retain mode.
        Specified by:
        retainConnection in interface StoreManager
      • releaseConnection

        public void releaseConnection()
        Description copied from interface: StoreManager
        Instruct the store to release a retained connection. This will be invoked automatically based on the user's configured connection retain mode.
        Specified by:
        releaseConnection in interface StoreManager
      • getClientConnection

        public java.lang.Object getClientConnection()
        Description copied from interface: StoreManager
        Return a connection to the data store suitable for client use. If this method is called during a data store transaction, thie connection must be transactional. If no connection is in use, this method should create one to return.
        Specified by:
        getClientConnection in interface StoreManager
      • getConnection

        public java.sql.Connection getConnection()
        Description copied from interface: JDBCStore
        Return a SQL connection to the database. The close method should always be called on the connection to free any resources it is using. When appropriate, the close method is implemented as a no-op.
        Specified by:
        getConnection in interface JDBCStore
      • getDataSource

        protected javax.sql.DataSource getDataSource()
      • exists

        public boolean exists​(OpenJPAStateManager sm,
                              java.lang.Object context)
        Description copied from interface: StoreManager
        Verify that the given instance exists in the data store; return false if it does not.
        Specified by:
        exists in interface StoreManager
      • isCached

        public boolean isCached​(java.util.List<java.lang.Object> oids,
                                java.util.BitSet edata)
        Description copied from interface: StoreManager
        Verify that the given instance exists in the data store in memory; return false if it does not. When an object is found in memory the corresponding element of the BitSet is set to 1.
        Specified by:
        isCached in interface StoreManager
      • syncVersion

        public boolean syncVersion​(OpenJPAStateManager sm,
                                   java.lang.Object context)
        Description copied from interface: StoreManager
        Update the version information in the given state manager to the version stored in the data store.
        Specified by:
        syncVersion in interface StoreManager
        Parameters:
        sm - the instance to check
        context - the current execution data, or null if not given to the calling method of the context
        Returns:
        true if the instance still exists in the datastore and is up-to-date, false otherwise
      • initializeState

        protected boolean initializeState​(OpenJPAStateManager sm,
                                          PCState state,
                                          JDBCFetchConfiguration fetch,
                                          ConnectionInfo info)
                                   throws java.lang.ClassNotFoundException,
                                          java.sql.SQLException
        Initialize a newly-loaded instance.
        Throws:
        java.lang.ClassNotFoundException
        java.sql.SQLException
      • getVersion

        protected void getVersion​(ClassMapping mapping,
                                  OpenJPAStateManager sm,
                                  Result res)
                           throws java.sql.SQLException
        This method is to provide override for non-JDBC or JDBC-like implementation of getting version from the result set.
        Throws:
        java.sql.SQLException
      • isEmptyResult

        protected boolean isEmptyResult​(Result res)
                                 throws java.sql.SQLException
        This method is to provide override for non-JDBC or JDBC-like implementation of checking whether the result set is empty or not.
        Throws:
        java.sql.SQLException
      • getType

        protected java.lang.Class<?> getType​(Result res,
                                             ClassMapping mapping)
        This method is to provide override for non-JDBC or JDBC-like implementation of getting type from the result set.
      • load

        public boolean load​(OpenJPAStateManager sm,
                            java.util.BitSet fields,
                            FetchConfiguration fetch,
                            int lockLevel,
                            java.lang.Object context)
        Description copied from interface: StoreManager
        Load the given state manager. Note that any collection or map types loaded into the state manager will be proxied with the correct type; therefore the store manager does not have to load the same concrete collection/map types as the instance declares. However, array types must be consistent with the array type stored by the persistence capable instance. If this method is called during a data store transaction, the instance should be locked. If the given state manager does not have its version set already, version information can be loaded if desired through the OpenJPAStateManager.setVersion(java.lang.Object) method.
        Specified by:
        load in interface StoreManager
        Parameters:
        sm - the instance to load
        fields - set of fields to load; all field indexes in this set must be loaded; this set is mutable
        fetch - the fetch configuration to use when loading related objects
        lockLevel - attempt to load simple fields at this lock level; relations should be loaded at the read lock level of the fetch configuration
        context - the current execution data, or null if not given to the calling method of the broker
        Returns:
        false if the object no longer exists in the database, true otherwise
      • beforeStateChange

        public void beforeStateChange​(OpenJPAStateManager sm,
                                      PCState fromState,
                                      PCState toState)
        Description copied from interface: StoreManager
        Notification that the given state manager is about to change its lifecycle state. The store manager is not required to do anything in this method, but some back ends may need to.
        Specified by:
        beforeStateChange in interface StoreManager
      • flush

        public java.util.Collection flush​(java.util.Collection<OpenJPAStateManager> sms)
        Description copied from interface: StoreManager
        Flush the given state manager collection to the datastore, returning a collection of exceptions encountered during flushing. The given collection may include states that do not require data store action, such as persistent-clean instances or persistent-dirty instances that have not been modified since they were last flushed. For datastore updates and inserts, the dirty, non-flushed fields of each state should be flushed. New instances without an assigned object id should be given one via OpenJPAStateManager.setObjectId(java.lang.Object). New instances with value-strategy fields that have not been assigned yet should have their fields set. Datastore version information should be updated during flush, and the state manager's version indicator updated through the OpenJPAStateManager.setNextVersion(java.lang.Object) method. The current version will roll over to this next version upon successful commit.
        Specified by:
        flush in interface StoreManager
        See Also:
        org.apache.openjpa.util.ApplicationIds#assign()
      • cancelAll

        public boolean cancelAll()
        Description copied from interface: StoreManager
        Cancel all pending data store statements.
        Specified by:
        cancelAll in interface StoreManager
        Returns:
        true if any statements cancelled, false otherwise
      • getManagedType

        public java.lang.Class<?> getManagedType​(java.lang.Object oid)
        Description copied from interface: StoreManager
        Return the persistent class for the given data store identity value. If the given value is not a datastore identity object, return null.
        Specified by:
        getManagedType in interface StoreManager
      • getDataStoreIdType

        public java.lang.Class<?> getDataStoreIdType​(ClassMetaData meta)
        Description copied from interface: StoreManager
        Return the class used by this StoreManager for datastore identity values. The given metadata may be null, in which case the return value should the common datastore identity class for all classes, or null if this store manager does not use a common identity class.
        Specified by:
        getDataStoreIdType in interface StoreManager
      • copyDataStoreId

        public java.lang.Object copyDataStoreId​(java.lang.Object oid,
                                                ClassMetaData meta)
        Description copied from interface: StoreManager
        Copy the given object id value. Use the described type of the given metadata, which may be a subclass of the given oid's described type.
        Specified by:
        copyDataStoreId in interface StoreManager
      • newDataStoreId

        public java.lang.Object newDataStoreId​(java.lang.Object val,
                                               ClassMetaData meta)
        Description copied from interface: StoreManager
        Create a new unique datastore identity for the given type from the given oid value (presumably pk, stringified oid, or oid instance).
        Specified by:
        newDataStoreId in interface StoreManager
      • newDataStoreId

        public Id newDataStoreId​(long id,
                                 ClassMapping mapping,
                                 boolean subs)
        Description copied from interface: JDBCStore
        Create a new datastore identity object from the given id value and mapping.
        Specified by:
        newDataStoreId in interface JDBCStore
      • executeExtent

        public ResultObjectProvider executeExtent​(ClassMetaData meta,
                                                  boolean subclasses,
                                                  FetchConfiguration fetch)
        Description copied from interface: StoreManager
        Return a provider for all instances of the given candidate class, optionally including subclasses. The given candidate may be an unmapped type with mapped subclasses. If the provider is iterated within a data store transaction, returned instances should be locked.
        Specified by:
        executeExtent in interface StoreManager
      • newQuery

        public StoreQuery newQuery​(java.lang.String language)
        Description copied from interface: StoreManager
        Return a query implementation suitable for this store. If the query is iterated within a data store transaction, returned instances should be locked. Return null if this store does not support native execution of the given language. OpenJPA can execute JPQL in memory even without back end support.
        Specified by:
        newQuery in interface StoreManager
        Parameters:
        language - the query language
      • close

        public void close()
        Description copied from interface: StoreManager
        Free any resources this store manager is using.
        Specified by:
        close in interface Closeable
        Specified by:
        close in interface StoreManager
      • connectInternal

        protected JDBCStoreManager.RefCountConnection connectInternal()
                                                               throws java.sql.SQLException
        Connect to the database. This method is separated out so that it can be overridden.
        Throws:
        java.sql.SQLException
      • getNewConnection

        public java.sql.Connection getNewConnection()
        Description copied from interface: JDBCStore
        Return a new SQL connection to the database. This is used when the current connection still has a open result set and a new database operation needs to be done. The close method should always be called on the connection to free any resources it is using. When appropriate, the close method is implemented as a no-op.
        Specified by:
        getNewConnection in interface JDBCStore
      • find

        public java.lang.Object find​(java.lang.Object oid,
                                     ValueMapping vm,
                                     JDBCFetchConfiguration fetch)
        Find the object with the given oid.
        Specified by:
        find in interface JDBCStore
        vm - the mapping holding this oid, or null if not applicable
      • load

        public java.lang.Object load​(ClassMapping mapping,
                                     JDBCFetchConfiguration fetch,
                                     java.util.BitSet exclude,
                                     Result result)
                              throws java.sql.SQLException
        Load the object in the current row of the given result.
        Throws:
        java.sql.SQLException
      • select

        public boolean select​(Select sel,
                              ClassMapping mapping,
                              int subs,
                              OpenJPAStateManager sm,
                              java.util.BitSet fields,
                              JDBCFetchConfiguration fetch,
                              int eager,
                              boolean ident,
                              boolean outer)
        For implementation use only. Return a select for the proper mappings. Return null if no select is needed. The method is designed to be complementary to the load methods.
        Parameters:
        sel - select to build on
        mapping - the mapping for the base type to select for
        subs - whether the select might include subclasses of the given mapping
        sm - state manager if an instance is being loaded or initialized, else null
        fields - if a state manager is being loaded, the set of fields that must be loaded in order, else null
        fetch - the fetch configuration; used if no specific fields must be loaded, and used when selecting relations
        eager - eager fetch mode to use
        ident - whether to select primary key columns as distinct identifiers
        outer - whether we're outer-joining to this type
        Returns:
        true if the select is required, false otherwise
      • loadSubclasses

        public void loadSubclasses​(ClassMapping mapping)
        Makes sure all subclasses of the given type are loaded in the JVM. This is usually done automatically.
        Specified by:
        loadSubclasses in interface JDBCStore