Class DatastoreAdapterFactory

java.lang.Object
org.datanucleus.store.rdbms.adapter.DatastoreAdapterFactory

public class DatastoreAdapterFactory extends Object
Factory of RDBMS datastore adapters. Acts as a registry of adapters to RDBMS that can be selected for use. Uses a singleton pattern, and the factory can be accessed using the getInstance() method.

Autodetection

Provides a level of autodetection of the adapter to use for a particular RDBMS. It uses the DatabaseMetaData to extract the "product name" and matches this against a series of "adapter aliases" that we define internally or that can be contributed by plugins that extend the org.datanucleus.store.rdbms.datastoreadapter extension point. These extension can define a priority, so if multiple adapter match for the given database connection the one with the highest priority is chosen.

Specification of adapter class

You can call getDatastoreAdapter(ClassLoaderResolver, Connection, String, PluginManager) passing the adapter class name directly if you know which you want to use. This allows for user-defined database adapters.
  • Constructor Details

    • DatastoreAdapterFactory

      protected DatastoreAdapterFactory()
      Protected constructor to prevent outside instantiation
  • Method Details

    • getInstance

      public static DatastoreAdapterFactory getInstance()
      Accessor for the RDBMSAdapterFactory.
      Returns:
      The manager of type information
    • getDatastoreAdapter

      public DatastoreAdapter getDatastoreAdapter(org.datanucleus.ClassLoaderResolver clr, Connection conn, String adapterClassName, org.datanucleus.plugin.PluginManager pluginMgr) throws SQLException
      Accessor for an adapter, given a Connection to the datastore.
      Parameters:
      clr - ClassLoader resolver for resolving the adapter class
      conn - The Connection
      adapterClassName - Name of the class of the database adapter to use
      pluginMgr - the Plug-in manager
      Returns:
      The database adapter for this connection.
      Throws:
      SQLException - Thrown if a DB error occurs.
    • getNewDatastoreAdapter

      protected DatastoreAdapter getNewDatastoreAdapter(org.datanucleus.ClassLoaderResolver clr, DatabaseMetaData metadata, String adapterClassName, org.datanucleus.plugin.PluginManager pluginMgr)
      Accessor for the adapter for a specified datastore product.
      Parameters:
      clr - ClassLoader resolver for resolving the adapter class
      metadata - Database MetaData for the RDBMS
      adapterClassName - Name of the class of the database adapter (null implies use autodetect)
      pluginMgr - the Plug-in manager
      Returns:
      Instance of the database adapter
    • getAdapterClass

      protected Class getAdapterClass(org.datanucleus.plugin.PluginManager pluginMgr, String adapterClassName, String productName, org.datanucleus.ClassLoaderResolver clr)
      Accessor for the adapter class for a specified datastore product.
      Parameters:
      pluginMgr - the Plug-in manager
      adapterClassName - Name of the class of the database adapter (null implies use autodetect)
      productName - the database product name
      clr - ClassLoader resolver for resolving the adapter class
      Returns:
      the adapter class