Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.1.0)

E17493-02

oracle.javatools.db
Class DatabaseFactory

java.lang.Object
  extended by oracle.javatools.db.DBObjectProviderFactory.Creator
      extended by oracle.javatools.db.DatabaseFactory

public final class DatabaseFactory
extends DBObjectProviderFactory.Creator

DatabaseFactory is a DBObjectProviderFactory.Creator implementation. It provides an extra ability to create new Connections for a given connection name. This provision requires a DatabaseFactory plugin that supports such an operation, by default the API does not contain one. The JDeveloper connection architecture provides such functionality and if used with jdeveloper this functionality will be available.

It is unlikely that the DatabaseFactory would be needed in the product. For the vast majority of cases, the oracle.jdeveloper.db.DatabaseConnections API (and associated classes) should be used.

Since:
10.1.3
See Also:
Database, DBObjectProviderFactory

Nested Class Summary
static class DatabaseFactory.ConnectionCreator
          A connection creator should be registered for each connection store that exists.
static class DatabaseFactory.ConnectionCreatorFactory
          Provide ConnectionCreatorFactory implementations to provide ConnectionCreators for different stores in the product.
static class DatabaseFactory.DatabaseCreator
          Plugin to the DatabaseFactory for creating Databases and DatabaseDescriptors.
 
Method Summary
static java.sql.Connection createConnection(Database db)
          This will return a new Connection for the given database if possible.
static Database createDatabase(java.lang.String connName, DatabaseFactory.ConnectionCreator factory)
          Creates a Database using the given ConnectionCreator to create a connection for the given connection name.
protected  DBObjectProvider createProviderImpl(java.lang.Object identifier)
          Creates a provider for the given identifier if that identifier is a valid Database identifier.
static Database createStandaloneDatabase(java.lang.String name, java.sql.Connection conn)
          Creates a standalone Database for the given Connection.
static java.lang.String[] decodeIdentifier(java.lang.String id)
          Decodes the store name and connection name from the given encoded identifier.
static java.lang.String encodeIdentifier(java.lang.String storeName, java.lang.String connName)
          Encodes the given store name and connection name into a valid factory identifier.
static
<T extends DatabaseFactory.ConnectionCreator>
T
findConnectionCreator(java.lang.Class<T> ccc)
          Deprecated. 
static DatabaseFactory.ConnectionCreator findConnectionCreator(Database db)
          Deprecated. 
static DatabaseFactory.ConnectionCreator findConnectionCreator(java.lang.String storeName)
           
static Database findOrCreateDatabase(java.lang.String name, java.sql.Connection conn)
          Deprecated. - use createStandaloneDatabase(java.lang.String, java.sql.Connection) to create a Database for an isolated connection. If a Database is required for a given connection name in the product use the appropriate connection store (e.g. Application Connections, or central IDE Connections).
static Database findOrCreateDatabase(java.lang.String storeName, java.lang.String connName)
          Utility method that calls DBObjectProvider.findOrCreateProvider with the correcty provider type for Databases, and a fully qualified name encoded from the given store name and connection name.
protected  DBObjectProvider findProvider(java.lang.Object identifier)
           
static java.util.Collection<java.lang.Class<? extends Database>> getClasses()
          Gets the supported Database implementations from the API.
static DatabaseDescriptor getDatabaseDescriptor(java.lang.Class providerClass)
          Returns a DatabaseDescriptor for the given provider class.
static DatabaseDescriptor getDatabaseDescriptor(Database db)
          Returns a DatabaseDescriptor for the given database.
static java.lang.String getDatabaseName(java.lang.Class<? extends Database> dbClz)
          Gets a translated string that describes the given database class to the nearest supported version.
protected  java.lang.String getDescription(java.lang.Object identifier)
          Gets a displayable string to represent the database with the given identifier.
protected  java.lang.String getIdentifier(DBObjectProvider provider)
          Returns an identifier for the given provider that is used when notifying listeners of provider events.
 java.lang.String getProviderType()
          This method must return a String unique to the Creator that identifies the type of DBObjectProvider that will be created.
static void registerConnectionCreator(java.lang.String storeName, DatabaseFactory.ConnectionCreator cc)
          Registers a Connection creator that can duplicate connections for the Databases provided by the factory.
static void registerDatabaseCreator(DatabaseFactory.DatabaseCreator dc)
          Registers a Connection creator that can identify and create Databases and DatabaseDescriptors for the factory.
static void registerProviderClass(java.lang.Class<? extends Database> clz, java.lang.String name)
          Registers the given provider class with its translated name.
static void setJdbcDatabaseCreator(DatabaseFactory.DatabaseCreator dc)
          Sets the database creator for generic JDBC implmentations (i.e.
protected  DBObjectProvider uncacheProvider(java.lang.Object identifier)
           
static void unregisterConnectionCreator(java.lang.String storeName, DatabaseFactory.ConnectionCreator cc)
           
 
Methods inherited from class oracle.javatools.db.DBObjectProviderFactory.Creator
fireProviderDeleted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getProviderType

public java.lang.String getProviderType()
Description copied from class: DBObjectProviderFactory.Creator
This method must return a String unique to the Creator that identifies the type of DBObjectProvider that will be created. The same String should be returned by getProviderType() on any DBObjectProvider created by this provider.

Specified by:
getProviderType in class DBObjectProviderFactory.Creator

getDescription

protected java.lang.String getDescription(java.lang.Object identifier)
Description copied from class: DBObjectProviderFactory.Creator
Gets a displayable string to represent the database with the given identifier. The string can contain a description of the type as well, for example "database hr" or "offline database DATABASE1"

Overrides:
getDescription in class DBObjectProviderFactory.Creator

decodeIdentifier

public static java.lang.String[] decodeIdentifier(java.lang.String id)
Decodes the store name and connection name from the given encoded identifier. It is assumed that the given id was created using encodeIdentifier.

See Also:
encodeIdentifier(String,String)

encodeIdentifier

public static java.lang.String encodeIdentifier(java.lang.String storeName,
                                                java.lang.String connName)
Encodes the given store name and connection name into a valid factory identifier.

See Also:
decodeIdentifier(String)

getIdentifier

protected java.lang.String getIdentifier(DBObjectProvider provider)
Description copied from class: DBObjectProviderFactory.Creator
Returns an identifier for the given provider that is used when notifying listeners of provider events. This is also the expected identifier used in DBObjectProviderFactory.Creator.findProvider(java.lang.Object) etc.

Specified by:
getIdentifier in class DBObjectProviderFactory.Creator
Returns:
null if the provider isn't associated with this Creator implementation.

createProviderImpl

protected final DBObjectProvider createProviderImpl(java.lang.Object identifier)
                                             throws DBException
Creates a provider for the given identifier if that identifier is a valid Database identifier.

Specified by:
createProviderImpl in class DBObjectProviderFactory.Creator
Throws:
DBException

createDatabase

public static Database createDatabase(java.lang.String connName,
                                      DatabaseFactory.ConnectionCreator factory)
                               throws DBException
Creates a Database using the given ConnectionCreator to create a connection for the given connection name. If the ConnectionCreator can't create a connection for the given name null is returned. This does not check any cache for an existing connection or Database, use with care.

Throws:
DBException

findProvider

protected DBObjectProvider findProvider(java.lang.Object identifier)
Overrides:
findProvider in class DBObjectProviderFactory.Creator

uncacheProvider

protected DBObjectProvider uncacheProvider(java.lang.Object identifier)
Overrides:
uncacheProvider in class DBObjectProviderFactory.Creator

findOrCreateDatabase

public static final Database findOrCreateDatabase(java.lang.String storeName,
                                                  java.lang.String connName)
                                           throws DBException
Utility method that calls DBObjectProvider.findOrCreateProvider with the correcty provider type for Databases, and a fully qualified name encoded from the given store name and connection name.

Parameters:
storeName - the connection store the database connection is in
connName - the name of the connection within the store
Returns:
a Database wrapping the Connection to the database, or null if the connection name or store don't exist.
Throws:
DBException - if the connection details are found but a connection to the database cannot be established.

findOrCreateDatabase

@Deprecated
public static final Database findOrCreateDatabase(java.lang.String name,
                                                             java.sql.Connection conn)
                                           throws DBException
Deprecated. - use createStandaloneDatabase(java.lang.String, java.sql.Connection) to create a Database for an isolated connection. If a Database is required for a given connection name in the product use the appropriate connection store (e.g. Application Connections, or central IDE Connections).

Throws:
DBException

createStandaloneDatabase

public static final Database createStandaloneDatabase(java.lang.String name,
                                                      java.sql.Connection conn)
                                               throws DBException
Creates a standalone Database for the given Connection. This should only be used in testing a Connection. In the product, Database instances are cached for named connections so that their object caches can be shared. Creating a standalone Database impementation can therefore be slower.

Parameters:
name - the name to give the Database
conn - the Connection to a database
Returns:
a Database implementation appropriate to the given Connection
Throws:
DBException

getDatabaseDescriptor

public static final DatabaseDescriptor getDatabaseDescriptor(java.lang.Class providerClass)
Returns a DatabaseDescriptor for the given provider class. Will return null if no DatabaseDescriptor can be found for the given provider class.


setJdbcDatabaseCreator

public static void setJdbcDatabaseCreator(DatabaseFactory.DatabaseCreator dc)
Sets the database creator for generic JDBC implmentations (i.e. the fallback if no other creator can be found).

Parameters:
dc - the DatabaseCreator for JDBC databases.
For internal use only. Application developers should not use this

getDatabaseDescriptor

public static final DatabaseDescriptor getDatabaseDescriptor(Database db)
Returns a DatabaseDescriptor for the given database. Will return null if no DatabaseDescriptor can be found for the given database.


registerConnectionCreator

public static final void registerConnectionCreator(java.lang.String storeName,
                                                   DatabaseFactory.ConnectionCreator cc)
Registers a Connection creator that can duplicate connections for the Databases provided by the factory.


unregisterConnectionCreator

public static final void unregisterConnectionCreator(java.lang.String storeName,
                                                     DatabaseFactory.ConnectionCreator cc)

registerDatabaseCreator

public static final void registerDatabaseCreator(DatabaseFactory.DatabaseCreator dc)
Registers a Connection creator that can identify and create Databases and DatabaseDescriptors for the factory.


findConnectionCreator

public static DatabaseFactory.ConnectionCreator findConnectionCreator(java.lang.String storeName)

findConnectionCreator

@Deprecated
public static final <T extends DatabaseFactory.ConnectionCreator> T findConnectionCreator(java.lang.Class<T> ccc)
Deprecated. 


findConnectionCreator

@Deprecated
public static final DatabaseFactory.ConnectionCreator findConnectionCreator(Database db)
Deprecated. 


createConnection

public static final java.sql.Connection createConnection(Database db)
                                                  throws DBException
This will return a new Connection for the given database if possible. A suitable factory must be registered that can perform such an operation, if one is not present (this will be the case if using the api in standalone mode) the Database's existing connection will be returned.

This method is designed to create a duplicate Connection - the Database must have been setup with a Connection in the first place.

Throws:
DBException

registerProviderClass

public static void registerProviderClass(java.lang.Class<? extends Database> clz,
                                         java.lang.String name)
Registers the given provider class with its translated name.


getClasses

public static java.util.Collection<java.lang.Class<? extends Database>> getClasses()
Gets the supported Database implementations from the API. Although there are more Database implementations, this list is those that can be presented to a user as supported options.

Returns:
a collection of Database implementations we support.
See Also:
getDatabaseName(java.lang.Class)

getDatabaseName

public static java.lang.String getDatabaseName(java.lang.Class<? extends Database> dbClz)
Gets a translated string that describes the given database class to the nearest supported version. If no supported version is available, this will return "Generic JDBC Database" - i.e. we assume that there is no better support.

Returns:
a name for the given type (and version) of database.

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.1.0)

E17493-02

Copyright © 1997, 2011, Oracle. All rights reserved.