Interface StoreContext

    • Method Detail

      • getBroker

        Broker getBroker()
        Return the broker for this context, if possible. Note that a broker will be unavailable in remote contexts, and this method may return null.
      • getConfiguration

        OpenJPAConfiguration getConfiguration()
        Return the configuration associated with this context.
      • getFetchConfiguration

        FetchConfiguration getFetchConfiguration()
        Return the (mutable) fetch configuration for loading objects from this context.
      • pushFetchConfiguration

        FetchConfiguration pushFetchConfiguration()
        Pushes a new fetch configuration that inherits from the current fetch configuration onto a stack, and makes the new configuration the active one.
        Returns:
        the new fetch configuration
        Since:
        1.1.0
      • pushFetchConfiguration

        FetchConfiguration pushFetchConfiguration​(FetchConfiguration fc)
        Pushes the fetch configuration argument onto a stack, and makes the new configuration the active one.
        Returns:
        the new fetch configuration
        Since:
        2.1.1
      • popFetchConfiguration

        void popFetchConfiguration()
        Pops the fetch configuration from the top of the stack, making the next one down the active one. This returns void to avoid confusion, since fetch configurations tend to be used in method-chaining patterns often.
        Throws:
        UserException - if the fetch configuration stack is empty
        Since:
        1.1.0
      • getClassLoader

        ClassLoader getClassLoader()
        Return the current thread's class loader at the time this context was obtained.
      • getLockManager

        LockManager getLockManager()
        Return the lock manager in use.
      • getConnectionUserName

        String getConnectionUserName()
        Return the connection user name.
      • getConnectionPassword

        String getConnectionPassword()
        Return the connection password.
      • findCached

        Object findCached​(Object oid,
                          FindCallbacks call)
        Return the instance for the given oid/object , or null if not found in the L1 cache.
        Parameters:
        oid - the object's id
        Returns:
        the cached object, or null if not cached
      • find

        Object find​(Object oid,
                    boolean validate,
                    FindCallbacks call)
        Find the persistence object with the given oid. If validate is true, the broker will check the store for the object, and return null if it does not exist. If validate is false, this method never returns null. The broker will either return its cached instance, attempt to create a hollow instance, or throw an ObjectNotFoundException if unable to return a hollow instance.
        Parameters:
        validate - if true, validate that the instance exists in the store and load fetch group fields, otherwise return any cached or hollow instance
      • find

        Object find​(Object oid,
                    FetchConfiguration fetch,
                    BitSet exclude,
                    Object edata,
                    int flags)
        Return the object with the given oid. If present, the cached instance will be returned. Otherwise, the instance will be initialized through the store as usual; however, in this case the store will be passed the given execution data, and the system will load the object according to the given fetch configuration (or the context's configuration, if the given one is null). Fields can optionally be excluded from required loading using the exclude mask. By default this method does not find new unflushed instances, validates, and does not throw an exception if a cached instance has been deleted concurrently. These options are controllable through the given OID_XXX flags.
      • retrieve

        void retrieve​(Object pc,
                      boolean fgOnly,
                      OpCallbacks call)
        Immediately load the given object's persistent fields. One might use this action to make sure that an instance's fields are loaded before transitioning it to transient. Note that this action is not recursive. Any related objects that are loaded will not necessarily have their fields loaded. Unmanaged target is ignored.
        Parameters:
        fgOnly - indicator as to whether to retrieve only fields in the current fetch groups, or all fields
        See Also:
        retrieve(java.lang.Object, boolean, org.apache.openjpa.kernel.OpCallbacks)
      • embed

        OpenJPAStateManager embed​(Object obj,
                                  Object id,
                                  OpenJPAStateManager owner,
                                  ValueMetaData ownerMeta)
        Make the given instance embedded.
        Parameters:
        obj - the instance to embed; may be null to create a new instance
        id - the id to give the embedded state manager; may be null for default
        owner - the owning state manager
        ownerMeta - the value in which the object is embedded
        Returns:
        the state manager for the embedded instance
      • getObjectIdType

        Class<?> getObjectIdType​(Class<?> cls)
        Return the application or datastore identity class the given persistent class uses for object ids.
      • newObjectId

        Object newObjectId​(Class<?> cls,
                           Object val)
        Create a new object id instance from the given value.
        Parameters:
        cls - the persistent class that uses this identity value
        val - an object id instance, stringified object id, or primary key value
      • getPersistedTypes

        Collection<Class<?>> getPersistedTypes()
        Return the set of classes that have been made persistent in the current transaction.
        Since:
        0.3.4
      • getDeletedTypes

        Collection<Class<?>> getDeletedTypes()
        Return the set of classes that have been deleted in the current transaction.
        Since:
        0.3.4
      • getUpdatedTypes

        Collection<Class<?>> getUpdatedTypes()
        Return the set of classes for objects that have been modified in the current transaction.
        Since:
        0.3.4
      • getManagedObjects

        Collection<Object> getManagedObjects()
        Return a list of all managed instances.
      • getTransactionalObjects

        Collection<Object> getTransactionalObjects()
        Return a list of current transaction instances.
      • getPendingTransactionalObjects

        Collection<Object> getPendingTransactionalObjects()
        Return a list of instances which will become transactional upon the next transaction.
      • getDirtyObjects

        Collection<Object> getDirtyObjects()
        Return a list of current dirty instances.
      • getOrderDirtyObjects

        boolean getOrderDirtyObjects()
        Whether to maintain the order in which objects are dirtied for getDirtyObjects(). Default is the store manager's decision.
      • setOrderDirtyObjects

        void setOrderDirtyObjects​(boolean order)
        Whether to maintain the order in which objects are dirtied for getDirtyObjects(). Default is the store manager's decision.
      • getStateManager

        OpenJPAStateManager getStateManager​(Object obj)
        Return the state manager for the given instance. Includes objects made persistent in the current transaction. If obj is not a managed type or is managed by another context, throw an exception.
      • getLockLevel

        int getLockLevel​(Object obj)
        Return the lock level of the specified object.
      • getVersion

        Object getVersion​(Object obj)
        Returns the current version indicator for o.
      • isDirty

        boolean isDirty​(Object obj)
        Return whether the given object is dirty.
      • isTransactional

        boolean isTransactional​(Object obj)
        Return whether the given object is transactional.
      • transactional

        void transactional​(Object pc,
                           boolean updateVersion,
                           OpCallbacks call)
        Make the given object transactional.
        Parameters:
        pc - instance to make transactional
        updateVersion - if true, the instance's version will be incremented at the next flush
      • transactionalAll

        void transactionalAll​(Collection<Object> objs,
                              boolean updateVersion,
                              OpCallbacks call)
        Make the given objects transactional.
        Parameters:
        objs - instances to make transactional
        updateVersion - if true, the instance's version will be incremented at the next flush
      • nontransactional

        void nontransactional​(Object pc,
                              OpCallbacks call)
        Make the given object non-transactional.
      • nontransactionalAll

        void nontransactionalAll​(Collection<Object> objs,
                                 OpCallbacks call)
        Make the given objects nontransactional.
      • isPersistent

        boolean isPersistent​(Object obj)
        Return whether the given object is persistent.
      • isNew

        boolean isNew​(Object obj)
        Return whether the given object is a newly-created instance registered with broker.
      • isDeleted

        boolean isDeleted​(Object obj)
        Return whether the given object is deleted.
      • getObjectId

        Object getObjectId​(Object obj)
        Return the oid of the given instance.
      • getDetachState

        int getDetachState()
        Detach mode constant to determine which fields are part of the detached graph. Defaults to DetachState.DETACH_LOADED.
      • setDetachState

        void setDetachState​(int mode)
        Detach mode constant to determine which fields are part of the detached graph. Defaults to DetachState.DETACH_LOADED.
      • getPopulateDataCache

        boolean getPopulateDataCache()
        Whether objects accessed during this transaction will be added to the store cache. Defaults to true.
        Since:
        0.3.4
      • setPopulateDataCache

        void setPopulateDataCache​(boolean cache)
        Whether to populate the store cache with objects used by this transaction. Defaults to true.
        Since:
        0.3.4
      • isTrackChangesByType

        boolean isTrackChangesByType()
        Whether memory usage is reduced during this transaction at the expense of tracking changes at the type level instead of the instance level, resulting in more aggressive cache invalidation.
        Since:
        1.0.0
      • setTrackChangesByType

        void setTrackChangesByType​(boolean largeTransaction)
        If a large number of objects will be created, modified, or deleted during this transaction setting this option to true will reduce memory usage if you perform periodic flushes by tracking changes at the type level instead of the instance level, resulting in more aggressive cache invalidation. Upon transaction commit the data cache will have to more aggressively flush objects. The store cache will have to flush instances of objects for each class of object modified during the transaction. A side benefit of large transaction mode is that smaller update messages can be used for RemoteCommitEvents. Defaults to false.
        Since:
        1.0.0
      • isManaged

        boolean isManaged()
        Whether this context is using managed transactions.
      • isActive

        boolean isActive()
        Whether a logical transaction is active.
      • isStoreActive

        boolean isStoreActive()
        Whether a data store transaction is active.
      • beginStore

        void beginStore()
        Begin a data store transaction.
      • hasConnection

        boolean hasConnection()
        Whether the broker has a dedicated connection based on the configured connection retain mode and transaction status.
      • getConnection

        Object getConnection()
        Return the connection in use by the context, or a new connection if none.
      • lock

        void lock()
        Synchronizes on an internal lock if the Multithreaded flag is set to true. Make sure to call unlock() in a finally clause of the same method.
      • unlock

        void unlock()
        Releases the internal lock.
      • getConnectionFactoryName

        String getConnectionFactoryName()
        Return the 'JTA' connectionFactoryName
      • setConnectionFactoryName

        void setConnectionFactoryName​(String connectionFactoryName)
        Set the 'JTA' ConnectionFactoryName.
      • getConnectionFactory2Name

        String getConnectionFactory2Name()
        Return the 'NonJTA' ConnectionFactoryName.
      • setConnectionFactory2Name

        void setConnectionFactory2Name​(String connectionFactory2Name)
        Set the 'NonJTA' ConnectionFactoryName.
      • getConnectionFactory

        Object getConnectionFactory()
        Return the 'JTA' ConnectionFactory, looking it up from JNDI if needed.
        Returns:
        the JTA connection factory or null if connectionFactoryName is blank.
      • getConnectionFactory2

        Object getConnectionFactory2()
        Return the 'NonJTA' ConnectionFactory, looking it up from JNDI if needed.
        Returns:
        the NonJTA connection factory or null if connectionFactoryName is blank.
      • isCached

        boolean isCached​(List<Object> oid)
        Indicate whether the oid can be found in the StoreContext's L1 cache or in the StoreManager cache.
        Parameters:
        oid - List of ObjectIds for PersistenceCapables which may be found in memory.
        Returns:
        true if the oid is available in memory (cached) otherwise false.
        Since:
        2.0.0.
      • setAllowReferenceToSiblingContext

        void setAllowReferenceToSiblingContext​(boolean flag)
        Affirms if this context will allow its managed instances to refer instances that are managed by other contexts. Note: Some specification (such as JPA) does not warranty predictable behavior when strict group-like property of a persistent context (where managed instances can only refer to instances managed by the same context). Please be aware of consequences when the flag is set to true.
        Since:
        2.1
      • getAllowReferenceToSiblingContext

        boolean getAllowReferenceToSiblingContext()
        Affirms if this context will allow its managed instances to refer instances that are managed by other contexts.
        Returns:
        false by default.
        Since:
        2.1
      • setPostLoadOnMerge

        void setPostLoadOnMerge​(boolean allow)
        Set to true if the merge operation should trigger a @PostLoad lifecycle event.
        Parameters:
        allow - PostLoad lifecycle events to be triggered on a merge operation
      • getPostLoadOnMerge

        boolean getPostLoadOnMerge()
        Force sending a @PostLoad lifecycle event while merging.
        Returns:
        false by default
        Since:
        2.2