org.jpox.store.rdbms.adapter
Class RDBMSAdapterFactory

java.lang.Object
  extended byorg.jpox.store.rdbms.adapter.RDBMSAdapterFactory

public class RDBMSAdapterFactory
extends java.lang.Object

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

Autodetection

JPOX 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 JPOX has defined internally that it will find as part of the JDBC "product name". These "adapter aliases" can be primary or secondary. The primary is the main alias to match on. Typically if the primary is matched then that will define the DatabaseAdapter to use. In some situations (e.g DB2 AS/400) a primary alias matches ("db2"), yet we need to use an alternative adapter so we have a secondary alias ("as/400"). If a secondary alias matches then that takes priority in the autodetection process.

Specification of adapter class

You can call getDatastoreAdapter() passing the adapter class name directly if you know which you want to use. This allows for user-defined database adapters.

Version:
$Revision: 1.6 $

Constructor Summary
protected RDBMSAdapterFactory()
          Protected constructor to prevent outside instantiation
 
Method Summary
 void addAdapter(java.lang.String alias, java.lang.String adapterClassName, boolean secondary)
          Method to add support for a RDBMS product via an adapter.
protected  java.lang.String getAdapterClassNameForProductName(java.lang.String productName)
          Method to "autodetect" the adapter to be used, based on the supplied "product name".
 DatastoreAdapter getDatastoreAdapter(ClassLoaderResolver clr, java.sql.Connection conn, java.lang.String adapterClassName, Dictionary dictionary, PluginManager pluginMgr)
          Accessor for an adapter, given a Connection to the datastore.
static RDBMSAdapterFactory getInstance()
          Accessor for the RDBMSAdapterFactory for JPOX (singleton)
protected  DatastoreAdapter getNewDatastoreAdapter(ClassLoaderResolver clr, java.sql.DatabaseMetaData metadata, java.lang.String adapterClassName, Dictionary dictionary)
          Accessor for the adapter for a specified datastore product.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RDBMSAdapterFactory

protected RDBMSAdapterFactory()
Protected constructor to prevent outside instantiation

Method Detail

getInstance

public static RDBMSAdapterFactory getInstance()
Accessor for the RDBMSAdapterFactory for JPOX (singleton)

Returns:
The manager of type information

addAdapter

public void addAdapter(java.lang.String alias,
                       java.lang.String adapterClassName,
                       boolean secondary)
Method to add support for a RDBMS product via an adapter.

Parameters:
alias - Naming string found as part of the "product name" of the JDBC DatabaseMetaData
adapterClassName - Name of the adapter class to use
secondary - Whether this naming alias is secondary level

getDatastoreAdapter

public DatastoreAdapter getDatastoreAdapter(ClassLoaderResolver clr,
                                            java.sql.Connection conn,
                                            java.lang.String adapterClassName,
                                            Dictionary dictionary,
                                            PluginManager pluginMgr)
                                     throws java.sql.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
dictionary - The dictionary to use
pluginMgr - the Plug-in manager
Returns:
The database adapter for this connection.
Throws:
java.sql.SQLException - Thrown if a DB error occurs.

getAdapterClassNameForProductName

protected java.lang.String getAdapterClassNameForProductName(java.lang.String productName)
Method to "autodetect" the adapter to be used, based on the supplied "product name". Adaopts a simple procedure of finding one of our registered adapters that is part of the product name.

Parameters:
productName - The product name
Returns:
The class name of the adapter to use

getNewDatastoreAdapter

protected DatastoreAdapter getNewDatastoreAdapter(ClassLoaderResolver clr,
                                                  java.sql.DatabaseMetaData metadata,
                                                  java.lang.String adapterClassName,
                                                  Dictionary dictionary)
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)
dictionary - The Dictionary to use
Returns:
Instance of the database adapter


Copyright © -2007 . All Rights Reserved.