Class FederatedStoreManager

java.lang.Object
org.datanucleus.store.federation.FederatedStoreManager
All Implemented Interfaces:
StoreManager

public class FederatedStoreManager extends Object implements StoreManager
A federated StoreManager orchestrates the persistence/retrieval for multiple datastores. It is responsible for creating the individual StoreManager instances for the datastore(s) that are being federated. Has a "primary" StoreManager where data is stored by default when no metadata is specified for a class, and then has a map of "secondary" StoreManagers keyed by name that can be used for persistence as defined in metadata. When a request comes in to persist some data, this class is responsible for selecting the appropriate StoreManager for persistence. When a request comes in to query some data, this class is responsible for selecting the appropriate StoreManager to query.

Assumes that there are persistence properties of the form

 datanucleus.datastore.SecondStore=secondstore.properties
 datanucleus.datastore.ThirdStore=thirdstore.properties
 
where these properties files have the properties for the secondary stores with names "SecondStore", "ThirdStore".
  • Field Details

    • PROPERTY_DATA_FEDERATION_DATASTORE_NAME

      public static final String PROPERTY_DATA_FEDERATION_DATASTORE_NAME
      See Also:
    • primaryStoreMgr

      protected StoreManager primaryStoreMgr
      Primary StoreManager.
    • secondaryStoreMgrMap

      protected Map<String,StoreManager> secondaryStoreMgrMap
      Map of secondary StoreManager keyed by their symbolic name.
    • nucleusContext

      protected PersistenceNucleusContext nucleusContext
    • persistenceHandler

      protected StorePersistenceHandler persistenceHandler
      Persistence handler.
    • queryMgr

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

  • Method Details

    • getNucleusContext

      public PersistenceNucleusContext getNucleusContext()
      Description copied from interface: StoreManager
      Accessor for the context in which this StoreManager is running.
      Specified by:
      getNucleusContext in interface StoreManager
      Returns:
      Returns the context.
    • getMetaDataManager

      public MetaDataManager getMetaDataManager()
      Specified by:
      getMetaDataManager in interface StoreManager
    • getFlushProcess

      public FlushProcess getFlushProcess()
      Specified by:
      getFlushProcess in interface StoreManager
    • close

      public void close()
      Specified by:
      close in interface StoreManager
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface StoreManager
    • getStoreManagerForClass

      public StoreManager getStoreManagerForClass(AbstractClassMetaData cmd)
      Accessor for the StoreManager to use for persisting the specified class. TODO Extend this so that we can persist some objects of one type into one datastore, and other objects of that type into a different datastore.
      Parameters:
      cmd - Metadata for the class
      Returns:
      The StoreManager to use
    • getStoreManagerForClass

      public StoreManager getStoreManagerForClass(String className, ClassLoaderResolver clr)
      Accessor for the StoreManager to use for the specified class.
      Parameters:
      className - Name of the class
      clr - ClassLoader resolver
      Returns:
      The StoreManager to use
    • 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
    • getNamingFactory

      public NamingFactory getNamingFactory()
      Specified by:
      getNamingFactory in interface StoreManager
    • getApiAdapter

      public ApiAdapter getApiAdapter()
      Description copied from interface: StoreManager
      Accessor for the API adapter.
      Specified by:
      getApiAdapter in interface StoreManager
      Returns:
      API adapter
    • 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.
    • getDatastoreDate

      public Date getDatastoreDate()
      Description copied from interface: StoreManager
      Get the date/time of the datastore.
      Specified by:
      getDatastoreDate in interface StoreManager
      Returns:
      Date/time of the datastore
    • 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.
    • 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
    • getNucleusSequence

      public NucleusSequence getNucleusSequence(ExecutionContext ec, SequenceMetaData seqmd)
      Description copied from interface: StoreManager
      Method to return a datastore sequence for this datastore matching the passed sequence MetaData.
      Specified by:
      getNucleusSequence in interface StoreManager
      Parameters:
      ec - execution context
      seqmd - SequenceMetaData
      Returns:
      The Sequence
    • getSchemaHandler

      public StoreSchemaHandler getSchemaHandler()
      Specified by:
      getSchemaHandler in interface StoreManager
    • getStoreDataForClass

      public StoreData getStoreDataForClass(String className)
      Specified by:
      getStoreDataForClass in interface StoreManager
    • getPersistenceHandler

      public StorePersistenceHandler getPersistenceHandler()
      Specified by:
      getPersistenceHandler in interface StoreManager
    • getQueryManager

      public QueryManager getQueryManager()
      Specified by:
      getQueryManager in interface StoreManager
    • getSupportedQueryLanguages

      public Collection<String> getSupportedQueryLanguages()
      Description copied from interface: StoreManager
      Accessor for the supported query languages.
      Specified by:
      getSupportedQueryLanguages in interface StoreManager
      Returns:
      The supported query languages
    • newQuery

      public Query newQuery(String language, ExecutionContext ec)
      Description copied from interface: StoreManager
      Method to return a new query, for the specified language and ExecutionContext.
      Specified by:
      newQuery in interface StoreManager
      Parameters:
      language - The query language
      ec - ExecutionContext
      Returns:
      The query
    • newQuery

      public Query newQuery(String language, ExecutionContext ec, String queryString)
      Description copied from interface: StoreManager
      Method to return a new query, for the specified language and ExecutionContext, using the specified query string.
      Specified by:
      newQuery in interface StoreManager
      Parameters:
      language - The query language
      ec - ExecutionContext
      queryString - The query string
      Returns:
      The query
    • newQuery

      public Query newQuery(String language, ExecutionContext ec, Query q)
      Description copied from interface: StoreManager
      Method to return a new query, for the specified language and ExecutionContext, using the specified existing query to copy from.
      Specified by:
      newQuery in interface StoreManager
      Parameters:
      language - The query language
      ec - ExecutionContext
      q - Existing query
      Returns:
      The query
    • getValueGenerationManager

      public ValueGenerationManager getValueGenerationManager()
      Description copied from interface: StoreManager
      Accessor for the ValueGenerationManager for generating field values.
      Specified by:
      getValueGenerationManager in interface StoreManager
      Returns:
      The ValueGenerationManager for this datastore
    • getStoreManagerKey

      public String getStoreManagerKey()
      Description copied from interface: StoreManager
      Accessor for the key for this store manager.
      Specified by:
      getStoreManagerKey in interface StoreManager
      Returns:
      StoreManager key
    • getQueryCacheKey

      public String getQueryCacheKey()
      Description copied from interface: StoreManager
      Accessor for the key used for representing this store manager in the query cache.
      Specified by:
      getQueryCacheKey in interface StoreManager
      Returns:
      Key for the query cache
    • getValueGenerationStrategyValue

      public Object getValueGenerationStrategyValue(ExecutionContext ec, AbstractClassMetaData cmd, AbstractMemberMetaData mmd)
      Description copied from interface: StoreManager
      Method to retrieve the value for a value generation strategy for a particular field or datastore-identity.
      Specified by:
      getValueGenerationStrategyValue in interface StoreManager
      Parameters:
      ec - execution context
      cmd - AbstractClassMetaData for the class
      mmd - MetaData for the member when this is for a member (or null for datastore-identity)
      Returns:
      The generated value
    • isValueGenerationStrategyDatastoreAttributed

      public boolean isValueGenerationStrategyDatastoreAttributed(AbstractClassMetaData cmd, int absFieldNumber)
      Description copied from interface: StoreManager
      Convenience method to return whether the value generation strategy used by the specified class/member is generated in the datastore during a persist.
      Specified by:
      isValueGenerationStrategyDatastoreAttributed in interface StoreManager
      Parameters:
      cmd - Metadata for the class
      absFieldNumber - number of the field (or -1 if for datastore-id)
      Returns:
      if the object for the value generation strategy is attributed by the database ("identity", etc)
    • getValueGenerationStrategyForNative

      public String getValueGenerationStrategyForNative(AbstractClassMetaData cmd)
      Description copied from interface: StoreManager
      Method defining which value-strategy to use when the user specifies "native"/"auto" on datastore-identity.
      Specified by:
      getValueGenerationStrategyForNative in interface StoreManager
      Parameters:
      cmd - Class requiring the strategy
      Returns:
      The value generation strategy used when "native"/"auto" is specified
    • getValueGenerationStrategyForNative

      public String getValueGenerationStrategyForNative(AbstractMemberMetaData mmd)
      Description copied from interface: StoreManager
      Method defining which value-strategy to use when the user specifies "native"/"auto" on a member
      Specified by:
      getValueGenerationStrategyForNative in interface StoreManager
      Parameters:
      mmd - Member requiring the strategy
      Returns:
      The value generation strategy used when "native"/"auto" is specified
    • 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.
    • 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
    • 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
    • printInformation

      public void printInformation(String category, PrintStream ps) throws Exception
      Description copied from interface: StoreManager
      Method to output particular information owned by this datastore. Each StoreManager can support whichever categories it likes.
      Specified by:
      printInformation in interface StoreManager
      Parameters:
      category - Category of information
      ps - PrintStream
      Throws:
      Exception - Thrown if an error occurs in the output process
    • 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)
    • 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.
    • getNativeQueryLanguage

      public String getNativeQueryLanguage()
      Description copied from interface: StoreManager
      Accessor for the native query language of this store.
      Specified by:
      getNativeQueryLanguage in interface StoreManager
      Returns:
      The native query language (e.g "SQL")
    • supportsValueGenerationStrategy

      public boolean supportsValueGenerationStrategy(String language)
      Description copied from interface: StoreManager
      Accessor for whether this value generation strategy is supported.
      Specified by:
      supportsValueGenerationStrategy in interface StoreManager
      Parameters:
      language - The value generation strategy
      Returns:
      Whether it is supported.
    • getSupportedOptions

      public Collection<String> getSupportedOptions()
      Description copied from interface: StoreManager
      Strings representing features that are supported by this datastore. Refer to the Strings in org.datanucleus.store.StoreManager with prefix "OPTION_".
      Specified by:
      getSupportedOptions in interface StoreManager
      Returns:
      The supported options
    • getConnectionManager

      public ConnectionManager getConnectionManager()
      Description copied from interface: StoreManager
      Accessor for the connection manager for this store manager.
      Specified by:
      getConnectionManager in interface StoreManager
      Returns:
      connection manager
    • getConnection

      public ManagedConnection getConnection(ExecutionContext ec)
    • getConnection

      public ManagedConnection getConnection(ExecutionContext ec, Map options)
    • getConnection

      public ManagedConnection getConnection(int isolation_level)
    • getConnectionDriverName

      public String getConnectionDriverName()
      Description copied from interface: StoreManager
      Convenience accessor for the driver name to use for the connections (where supported).
      Specified by:
      getConnectionDriverName in interface StoreManager
      Returns:
      driver name
    • getConnectionURL

      public String getConnectionURL()
      Description copied from interface: StoreManager
      Convenience accessor for the URL for the connections.
      Specified by:
      getConnectionURL in interface StoreManager
      Returns:
      connection URL
    • getConnectionUserName

      public String getConnectionUserName()
      Description copied from interface: StoreManager
      Convenience accessor for the user name to use for the connections (where required).
      Specified by:
      getConnectionUserName in interface StoreManager
      Returns:
      user name
    • getConnectionPassword

      public String getConnectionPassword()
      Description copied from interface: StoreManager
      Convenience accessor for the password to use for the connections (where required).
      Specified by:
      getConnectionPassword in interface StoreManager
      Returns:
      Password
    • getConnectionFactory

      public Object getConnectionFactory()
      Description copied from interface: StoreManager
      Convenience accessor for the primary connection factory (when a factory was provided by the user).
      Specified by:
      getConnectionFactory in interface StoreManager
      Returns:
      Connection Factory (primary)
    • getConnectionFactory2

      public Object getConnectionFactory2()
      Description copied from interface: StoreManager
      Convenience accessor for the secondary connection factory (when a factory was provided by the user).
      Specified by:
      getConnectionFactory2 in interface StoreManager
      Returns:
      Connection Factory (secondary)
    • getConnectionFactory2Name

      public String getConnectionFactory2Name()
      Description copied from interface: StoreManager
      Convenience accessor for the factory (JNDI) name for the secondary connection factory (when provided by the user).
      Specified by:
      getConnectionFactory2Name in interface StoreManager
      Returns:
      Connection Factory name (secondary)
    • getConnectionFactoryName

      public String getConnectionFactoryName()
      Description copied from interface: StoreManager
      Convenience accessor for the factory (JNDI) name for the primary connection factory (when provided by the user).
      Specified by:
      getConnectionFactoryName in interface StoreManager
      Returns:
      Connection Factory name (primary)
    • getProperty

      public Object getProperty(String name)
      Specified by:
      getProperty in interface StoreManager
    • hasProperty

      public boolean hasProperty(String name)
      Specified by:
      hasProperty in interface StoreManager
    • getIntProperty

      public int getIntProperty(String name)
      Specified by:
      getIntProperty in interface StoreManager
    • getBooleanProperty

      public boolean getBooleanProperty(String name)
      Specified by:
      getBooleanProperty in interface StoreManager
    • getBooleanProperty

      public boolean getBooleanProperty(String name, boolean resultIfNotSet)
      Specified by:
      getBooleanProperty in interface StoreManager
    • getBooleanObjectProperty

      public Boolean getBooleanObjectProperty(String name)
      Specified by:
      getBooleanObjectProperty in interface StoreManager
    • getStringProperty

      public String getStringProperty(String name)
      Specified by:
      getStringProperty in interface StoreManager
    • 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
    • transactionStarted

      public void transactionStarted(ExecutionContext ec)
      Description copied from interface: StoreManager
      Method to inform the StoreManager that a transaction has started for the specified execution context. This allows the StoreManager to initialise any objects as required.
      Specified by:
      transactionStarted in interface StoreManager
      Parameters:
      ec - ExecutionContext
    • transactionCommitted

      public void transactionCommitted(ExecutionContext ec)
      Description copied from interface: StoreManager
      Method to inform the StoreManager that a transaction has committed for the specified execution context. This allows the StoreManager to close any objects as required.
      Specified by:
      transactionCommitted in interface StoreManager
      Parameters:
      ec - ExecutionContext
    • transactionRolledBack

      public void transactionRolledBack(ExecutionContext ec)
      Description copied from interface: StoreManager
      Method to inform the StoreManager that a transaction has rolled back for the specified execution context. This allows the StoreManager to close any objects as required.
      Specified by:
      transactionRolledBack in interface StoreManager
      Parameters:
      ec - ExecutionContext
    • 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).
    • usesBackedSCOWrappers

      public boolean usesBackedSCOWrappers()
      Description copied from interface: StoreManager
      Whether this store manager uses backing-store based SCO wrappers.
      Specified by:
      usesBackedSCOWrappers in interface StoreManager
      Returns:
      Whether this store provides backing stores for SCO wrappers.
    • getDefaultStateManagerClassName

      public String getDefaultStateManagerClassName()
      Specified by:
      getDefaultStateManagerClassName in interface StoreManager