Class AbstractStoreManager

  • All Implemented Interfaces:
    StoreManager

    public abstract class AbstractStoreManager
    extends PropertyStore
    implements StoreManager
    An abstract representation of a Store Manager. Manages the persistence of objects to the store. Will be implemented for the type of datastore (RDBMS, ODBMS, etc) in question. The store manager's responsibilities include:
    • Creating and/or validating datastore tables according to the persistent classes being accessed by the application.
    • Serving as the primary intermediary between StateManagers and the database.
    • Serving as the base Extent and Query factory.

    A store manager's knowledge of its contents is typically not complete. It knows about the classes that it has encountered in its lifetime. The ExecutionContext can make the StoreManager aware of a class, and can check if the StoreManager knows about a particular class.

    • Field Detail

      • storeManagerKey

        protected final String storeManagerKey
        Key for this StoreManager e.g "rdbms", "neo4j"
      • storeDataMgr

        protected StoreDataManager storeDataMgr
        Manager for the data definition in the datastore.
      • flushProcess

        protected FlushProcess flushProcess
        The flush process appropriate for this datastore.
      • queryMgr

        protected QueryManager queryMgr
        Query Manager. Lazy initialised, so use getQueryManager() to access.
      • namingFactory

        protected NamingFactory namingFactory
        Naming factory.
    • Constructor Detail

      • AbstractStoreManager

        protected AbstractStoreManager​(String key,
                                       ClassLoaderResolver clr,
                                       PersistenceNucleusContext nucleusContext,
                                       Map<String,​Object> props)
        Constructor for a new StoreManager. Stores the basic information required for the datastore management.
        Parameters:
        key - Key for this StoreManager
        clr - the ClassLoaderResolver
        nucleusContext - The corresponding nucleus context.
        props - Any properties controlling this datastore
    • Method Detail

      • registerConnectionMgr

        protected void registerConnectionMgr()
        Register the default ConnectionManager implementation. Having this in a separate method to allow overriding by store plugins if required.
      • getConnectionPassword

        public String getConnectionPassword()
        Convenience accessor for the password to use for the connection. Will perform decryption if the persistence property "datanucleus.ConnectionPasswordDecrypter" has also been specified.
        Specified by:
        getConnectionPassword in interface StoreManager
        Returns:
        Password
      • isJdbcStore

        public boolean isJdbcStore()
        Description copied from interface: StoreManager
        Returns whether the datastore is a "JDBC datastore". If it is then the JDO spec needs to return a connection that implements java.sql.Connection. RDBMS is the only one that will return true from here (or certainly as we can foresee now).
        Specified by:
        isJdbcStore in interface StoreManager
        Returns:
        Whether this is a JDBC datastore
      • getNucleusConnection

        public NucleusConnection getNucleusConnection​(ExecutionContext ec)
        Description copied from interface: StoreManager
        Method to return a connection to the user for the ExecutionContext. Typically provides a wrapper to the currently in-use ManagedConnection.
        Specified by:
        getNucleusConnection in interface StoreManager
        Parameters:
        ec - execution context
        Returns:
        The datastore Connection
      • registerStoreData

        protected void registerStoreData​(StoreData data)
        Method to register some data with the store. This will also register the data with the starter process.
        Parameters:
        data - The StoreData to add
      • deregisterAllStoreData

        protected void deregisterAllStoreData()
        Method to deregister all existing store data so that we are managing nothing.
      • logConfiguration

        protected void logConfiguration()
        Convenience method to log the configuration of this store manager.
      • printInformation

        public void printInformation​(String category,
                                     PrintStream ps)
                              throws Exception
        Method to output the information about the StoreManager. Supports the category "DATASTORE".
        Specified by:
        printInformation in interface StoreManager
        Parameters:
        category - Category of information
        ps - PrintStream
        Throws:
        Exception - Thrown if an error occurs in the output process
      • managesClass

        public boolean managesClass​(String className)
        Description copied from interface: StoreManager
        Accessor for whether the specified class is managed currently
        Specified by:
        managesClass in interface StoreManager
        Parameters:
        className - The name of the class
        Returns:
        Whether it is managed
      • manageClasses

        public void manageClasses​(ClassLoaderResolver clr,
                                  String... classNames)
        Description copied from interface: StoreManager
        Manage the specified classes. This method is primarily useful for applications that wish to perform all of their datastore initialization up front, rather than wait for the runtime to do it on-demand.
        Specified by:
        manageClasses in interface StoreManager
        Parameters:
        clr - The ClassLoaderResolver
        classNames - The class(es) to be managed
      • newStoreData

        protected StoreData newStoreData​(ClassMetaData cmd,
                                         ClassLoaderResolver clr)
        Instantiate a StoreData instance using the provided ClassMetaData and ClassLoaderResolver. Override this method if you want to instantiate a subclass of StoreData.
        Parameters:
        cmd - MetaData for the class
        clr - ClassLoader resolver
        Returns:
        The StoreData
      • unmanageAllClasses

        public void unmanageAllClasses​(ClassLoaderResolver clr)
        Description copied from interface: StoreManager
        Remove all classes from the persistence model for the datastore. This empties the datastore of all datastore objects managed by us. All objects of types not managed are left untouched. In the case of RDBMS this means drop all tables for types managed by us.
        Specified by:
        unmanageAllClasses in interface StoreManager
        Parameters:
        clr - The ClassLoaderResolver
      • unmanageClass

        public void unmanageClass​(ClassLoaderResolver clr,
                                  String className,
                                  boolean removeFromDatastore)
        Description copied from interface: StoreManager
        Method to remove knowledge of the specified class from this StoreManager. This can optionally also remove it from the datastore.
        Specified by:
        unmanageClass in interface StoreManager
        Parameters:
        clr - ClassLoader resolver
        className - Name of the class
        removeFromDatastore - Whether to also remove it from the datastore (otherwise just from the StoreManager)
      • manageClassForIdentity

        public String manageClassForIdentity​(Object id,
                                             ClassLoaderResolver clr)
        Description copied from interface: StoreManager
        Convenience method to ensure that the class defined by the passed DatastoreId/SingleFieldId is managed by the store.
        Specified by:
        manageClassForIdentity in interface StoreManager
        Parameters:
        id - identity
        clr - ClassLoader resolver
        Returns:
        The class name of the class associated to this identity
      • getExtent

        public <T> Extent<T> getExtent​(ExecutionContext ec,
                                       Class<T> c,
                                       boolean subclasses)
        Description copied from interface: StoreManager
        Interface to getting an Extent for a class.
        Specified by:
        getExtent in interface StoreManager
        Type Parameters:
        T - Type of the extent
        Parameters:
        ec - execution context
        c - The class requiring the Extent
        subclasses - Whether to include subclasses of 'c'
        Returns:
        The Extent.
      • supportsQueryLanguage

        public boolean supportsQueryLanguage​(String language)
        Description copied from interface: StoreManager
        Accessor for whether this query language is supported.
        Specified by:
        supportsQueryLanguage in interface StoreManager
        Parameters:
        language - The language
        Returns:
        Whether it is supported.
      • getClassNameForObjectID

        public String getClassNameForObjectID​(Object id,
                                              ClassLoaderResolver clr,
                                              ExecutionContext ec)
        Description copied from interface: StoreManager
        Returns the class corresponding to the given object identity. If the object is datastore-identity, return the PC class specified in the identity. If the object is single-field identity, return the PC class specified in the identity If the object is an AppID PK, return the PC class that uses it. If the object is a SCOID, return the SCO class. If the object is a persistable class, return the class.
        Specified by:
        getClassNameForObjectID in interface StoreManager
        Parameters:
        id - The identity of some object.
        clr - ClassLoader resolver
        ec - execution context
        Returns:
        For datastore identity, return the class of the corresponding object. For application identity, return the class of the corresponding object or null if object does not exist.
      • supportsValueGenerationStrategy

        public boolean supportsValueGenerationStrategy​(String strategy)
        Accessor for whether this value strategy is supported.
        Specified by:
        supportsValueGenerationStrategy in interface StoreManager
        Parameters:
        strategy - The strategy
        Returns:
        Whether it is supported.
      • isValueGenerationStrategyDatastoreAttributed

        public boolean isValueGenerationStrategyDatastoreAttributed​(AbstractClassMetaData cmd,
                                                                    int absFieldNumber)
        Convenience method to return whether the strategy used by the specified class/member is generated by the datastore (during a persist).
        Specified by:
        isValueGenerationStrategyDatastoreAttributed in interface StoreManager
        Parameters:
        cmd - Metadata for the class
        absFieldNumber - Absolute field number for the field (or -1 if datastore id)
        Returns:
        Whether the strategy is generated in the datastore
      • getValueGenerationStrategyForNative

        public String getValueGenerationStrategyForNative​(AbstractClassMetaData cmd)
        Method defining which value-strategy to use when the user specifies "native" on datastore-identity. This will return as follows
        • If your field is Numeric-based (or no jdbc-type) then chooses the first one that is supported of "identity", "sequence", "increment", otherwise exception.
        • Otherwise your field is String-based then chooses "uuid-hex".
        If your store plugin requires something else then override this
        Specified by:
        getValueGenerationStrategyForNative in interface StoreManager
        Parameters:
        cmd - Class requiring the strategy
        Returns:
        The strategy used when "native" is specified
      • getValueGenerationStrategyForNative

        public String getValueGenerationStrategyForNative​(AbstractMemberMetaData mmd)
        Method defining which value-strategy to use when the user specifies "native" on a member. This will return as follows
        • If your field is Numeric-based then chooses the first one that is supported of "identity", "sequence", "increment", otherwise exception.
        • Otherwise your field is String-based then chooses "uuid-hex".
        If your store plugin requires something else then override this
        Specified by:
        getValueGenerationStrategyForNative in interface StoreManager
        Parameters:
        mmd - Member requiring the strategy
        Returns:
        The strategy used when "native" is specified
      • getNextValueForValueGenerator

        protected Object getNextValueForValueGenerator​(ValueGenerator generator,
                                                       ExecutionContext ec)
        Accessor for the next value from the specified ValueGenerator. This implementation simply returns generator.next(). Any case where the generator requires datastore connections should override this method.
        Parameters:
        generator - The generator
        ec - execution context
        Returns:
        The next value.
      • getPropertiesForValueGenerator

        protected Properties getPropertiesForValueGenerator​(AbstractClassMetaData cmd,
                                                            int absoluteFieldNumber,
                                                            ClassLoaderResolver clr,
                                                            SequenceMetaData seqmd,
                                                            TableGeneratorMetaData tablegenmd)
        Method to return the properties to pass to the generator for the specified field. Will define the following properties "class-name", "root-class-name", "field-name" (if for a field), "sequence-name", "key-initial-value", "key-cache-size", "sequence-table-name", "sequence-schema-name", "sequence-catalog-name", "sequence-name-column-name", "sequence-nextval-column-name". In addition any extension properties on the respective field or datastore-identity are also passed through as properties.
        Parameters:
        cmd - MetaData for the class
        absoluteFieldNumber - Number of the field (-1 = datastore identity)
        clr - ClassLoader resolver
        seqmd - Any sequence metadata
        tablegenmd - Any table generator metadata
        Returns:
        The properties to use for this field
      • addValueGenerationPropertiesForIncrement

        protected void addValueGenerationPropertiesForIncrement​(Properties properties,
                                                                TableGeneratorMetaData tablegenmd)
      • addValueGenerationPropertiesForSequence

        protected void addValueGenerationPropertiesForSequence​(Properties properties,
                                                               SequenceMetaData seqmd)
      • getSubClassesForClass

        public Collection<String> getSubClassesForClass​(String className,
                                                        boolean includeDescendents,
                                                        ClassLoaderResolver clr)
        Description copied from interface: StoreManager
        Utility to return the names of the classes that are known subclasses of the provided class. Actually uses the MetaDataManager for determining what is a subclass since the MetaData is often registered before being needed by the Store. The important difference is that this method will then register the subclass as required
        Specified by:
        getSubClassesForClass in interface StoreManager
        Parameters:
        className - Class for which we search for subclasses.
        includeDescendents - Whether to include subclasses of subclasses etc
        clr - The ClassLoaderResolver
        Returns:
        Set of classes that are subclasses of the input class.
      • getSupportedOptions

        public Collection<String> getSupportedOptions()
        Accessor for the supported options in string form. Typical values specified here are :-
        • ApplicationIdentity - if the datastore supports application identity
        • DatastoreIdentity - if the datastore supports datastore identity
        • ORM - if the datastore supports (some) ORM concepts
        • TransactionIsolationLevel.read-committed - if supporting this txn isolation level
        • TransactionIsolationLevel.read-uncommitted - if supporting this txn isolation level
        • TransactionIsolationLevel.repeatable-read - if supporting this txn isolation level
        • TransactionIsolationLevel.serializable - if supporting this txn isolation level
        • TransactionIsolationLevel.snapshot - if supporting this txn isolation level
        • Query.Cancel - if supporting cancelling of queries
        • Query.Timeout - if supporting timeout of queries
        Specified by:
        getSupportedOptions in interface StoreManager
        Returns:
        The supported options
      • hasProperty

        public boolean hasProperty​(String name)
        Description copied from class: PropertyStore
        Accessor for whether a particular property is defined (but may be null).
        Specified by:
        hasProperty in interface StoreManager
        Overrides:
        hasProperty in class PropertyStore
        Parameters:
        name - Property name
        Returns:
        Whether the property is defined
      • getIntProperty

        public int getIntProperty​(String name)
        Description copied from class: PropertyStore
        Accessor for the specified property as an int. If the specified property isn't found returns 0.
        Specified by:
        getIntProperty in interface StoreManager
        Overrides:
        getIntProperty in class PropertyStore
        Parameters:
        name - Name of the property
        Returns:
        Int value for the property
      • getBooleanProperty

        public boolean getBooleanProperty​(String name)
        Description copied from class: PropertyStore
        Accessor for the specified property as a boolean. If the specified property isn't found returns false.
        Specified by:
        getBooleanProperty in interface StoreManager
        Overrides:
        getBooleanProperty in class PropertyStore
        Parameters:
        name - Name of the property
        Returns:
        Boolean value for the property
      • getBooleanProperty

        public boolean getBooleanProperty​(String name,
                                          boolean resultIfNotSet)
        Description copied from class: PropertyStore
        Accessor for the specified property as a boolean.
        Specified by:
        getBooleanProperty in interface StoreManager
        Overrides:
        getBooleanProperty in class PropertyStore
        Parameters:
        name - Name of the property
        resultIfNotSet - The value to return if no value for the specified property is found.
        Returns:
        Boolean value for the property
      • enableSchemaGeneration

        public void enableSchemaGeneration()
        Description copied from interface: StoreManager
        Convenience method to override the specified schema generation properties and enable schema generation.
        Specified by:
        enableSchemaGeneration in interface StoreManager
      • resetSchemaGeneration

        public void resetSchemaGeneration()
        Description copied from interface: StoreManager
        Convenience method to reset the schema generation properties to their initial creation values, effectively undoing a call to enableSchemaGeneration.
        Specified by:
        resetSchemaGeneration in interface StoreManager
      • useBackedSCOWrapperForMember

        public boolean useBackedSCOWrapperForMember​(AbstractMemberMetaData mmd,
                                                    ExecutionContext ec)
        Description copied from interface: StoreManager
        Method to return whether the specified member should use a backed SCO wrapper.
        Specified by:
        useBackedSCOWrapperForMember in interface StoreManager
        Parameters:
        mmd - Metadata for the member
        ec - ExecutionContext
        Returns:
        Whether to use a back SCO wrapper (false means use a simple SCO wrapper).