Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.4.0)

E13403-05

oracle.javatools.db
Class AbstractDatabase

java.lang.Object
  extended by oracle.javatools.db.AbstractDBObjectProvider
      extended by oracle.javatools.db.AbstractDatabase
All Implemented Interfaces:
Database, DBObjectProvider
Direct Known Subclasses:
DDLDatabase

public abstract class AbstractDatabase
extends AbstractDBObjectProvider
implements Database

Base implementation of the Database interface. AbstractDatabase can be subclassed to provide support for specific types of databases.

Since:
9.0.5
See Also:
JdbcDatabase, BaseOracleDatabase

Field Summary
static java.lang.String SQLSTATE_NOT_IMPLEMENTED
           
 
Fields inherited from class oracle.javatools.db.AbstractDBObjectProvider
CASE_SENSITIVE_NAME_POLICY, EMPTY_LIST, LOWER_CASE_NAME_POLICY, MIXED_CASE_NAME_POLICY, NEW_FROM_TEMPLATE_TYPE, TIMESTAMP_PROPERTY, UPPER_CASE_NAME_POLICY
 
Fields inherited from interface oracle.javatools.db.Database
FOUR_GIG, GENERIC_JDBC_DATABASE, SOURCE_TYPE_BODY, SOURCE_TYPE_SPEC, TWO_GIG
 
Fields inherited from interface oracle.javatools.db.DBObjectProvider
CREATE_PRIVILEDGE, DELETE_PRIVILEDGE, MODIFY_PRIVILEDGE, NEW_FROM_TEMPLATE_TYPE
 
Constructor Summary
protected AbstractDatabase(java.lang.String connStore, java.lang.String connName, java.sql.Connection conn)
          Constructs a new AbstractDatabase.
 
Method Summary
 void cancelStatement()
          Cancels the Statement currently executing against this Database if: such a statement has been recorded by the use of a StatementWrapper/QueryWrapper both the DBMS and driver support aborting an SQL statement
 boolean canRestrictSchemaList()
          Whether this provider supports restricting the list of schemas to those with visible objects.
 void close()
          Closes the Database Connection (and the supplied JDBC Connection).
protected  SystemObject createByIDImpl(DBObjectID id)
           
protected  Schema createSchema(java.lang.String name)
           
 boolean exists(java.lang.String type, java.lang.String schema, java.lang.String name)
          Checks for existance of a schema object named objectName.
protected  boolean exists(SystemObject obj)
          Whether the specified object exists.
protected  void finishCreate(SystemObject[] objects, SystemObject[] oldObjects)
          Use to finish the create or update of objects after the changes have been made in the db.
protected  void finishDelete(Schema schema, SystemObject[] objs)
          Use to finish the delete of the given objects after the operation has been performed against the db.
protected  void finishDelete(SystemObject[] objs)
          Use to finish the delete of the given objects after the operation has been performed against the db.
protected  java.lang.String getAliveTestStatement()
          Returns a statement that, if executed succesfully, tests whether the given connections is live.
 java.sql.Connection getConnection()
          Gets the JDBC connection associated with this database.
 java.sql.Connection getConnection(boolean reconnect)
          Gets the JDBC connection associated with this database.
 java.lang.String getConnectionName()
          Retrieves the name for the Connection associated with this Database in whichever connection store it is stored in.
 java.lang.String getConnectionStore()
          Retrieves the connection store the Connection associated with this Database is stored in.
protected  SystemObject getCreatedObject(java.lang.String type, Schema schema, java.lang.String name)
          Used by finishCreate() to get the object that's just been created back from the database so that it can be verified before returning to the user.
 java.lang.String getDatabaseSource(java.lang.String objectType, Schema schema, java.lang.String objectName)
          Retrieves the source for an object in the database.
 java.lang.String getDatabaseSource(java.lang.String objectType, Schema schema, java.lang.String objectName, java.lang.String sourceType)
          Retrieves the source for an object in the database.
 java.lang.String getDatabaseType()
          Gets the type of database.
 int getDatabaseVersion()
          Gets the version of the database for the api implementation.
 DDLGenerator getDDLGenerator()
          Deprecated. - pushed down to DDLDatabase
 Schema getDefaultSchema()
          Returns the default schema for the connection or null if there isn't one.
 DatabaseDescriptor getDescriptor()
          Returns the DatabaseDescriptor for this provider
 java.lang.String getName()
          Returns an identifier for this provider.
protected
<T extends SystemObject>
T
getObjectImpl(DBObjectCriteria<T> criteria)
           
 java.lang.String getQualifiedName()
          Retrieves a qualified name containing the connection store and connection name.
protected  java.lang.String getTransactionTestQuery()
           
 boolean hasTransaction()
          Tests whether there is currently a "transaction" open on the underlying java.sql.Connection.
 boolean isConnectionAlive()
          Tests whether the connection underneath this Database is "alive" - i.e.
protected  boolean isConnectionAlive(java.sql.Connection conn)
          Implementation that checks whether the given (current) connection is alive.
 java.lang.Boolean isConnectionClosed(java.sql.SQLException sqe)
          This default implementation returns null unless the SQLException has a SQLState of "08003" - the ANSI standard for "closed connection".
 boolean isObjectValid(java.lang.String objectType, java.lang.String schema, java.lang.String objectName)
          Determines whether the specified database object is in a valid state.
protected  boolean isUsernameCaseInsensitive()
          Returns true if the username is treated as case insensitive.
protected  void reconnect()
           
protected  void reconnected(java.sql.Connection c)
          Called when a reconnect happens to (re)initialise any member appropriately on the new Connection.
protected abstract  void registerBuilders()
          Called to request that the DBOBjectBuilders be registered.
protected  void registerValidators()
          By default this registers default validators for Schema, Sequences, Synonyms, Indexes, Constraints and Columns for the wizards to use.
 void setStatement(java.sql.Statement statement)
          Internal use only.
protected  void sqlTrace(java.lang.String query)
          Deprecated. - Tracing is done automatically by the QueryWrapper implementations. DDL tracing is done automatically for implementations of DDLDatabase.
protected  void sqlTrace(java.lang.String query, java.lang.Object[] params)
          Deprecated. - Tracing is done automatically by the QueryWrapper implementations. DDL tracing is done automatically for implementations of DDLDatabase.
 boolean supportsDebugging()
          Whether this database instance supports JDWP debugging.
 void testSQLStatement(java.lang.String sql)
          Tests that the given SQL executes against the database.
 
Methods inherited from class oracle.javatools.db.AbstractDBObjectProvider
addProviderListener, cacheObject, checkCachedObject, clearAllCaches, clearCache, convertObject, createObject, createObjectImpl, createObjectManager, createSchema, deleteObject, deleteSchema, destroyCache, findByID, findObject, findObject, findSchema, fireObjectsAdded, fireObjectsRemoved, fireProviderClosed, fireProviderDeleted, fireProviderOpened, fireProviderReloaded, fireSchemaAdded, fireSchemaObjectUpdated, fireSchemaRemoved, fireSchemaUpdated, getBuilderForType, getCachedTimestamp, getCascadeManager, getCasePolicy, getDataType, getDefaultTemplateForType, getDiffEngine, getExternalName, getExternalName, getExternalTimestamp, getExternalTimestampImpl, getIdentifierQuoteString, getInternalName, getInternalName, getLogger, getObject, getObject, getObjectFactory, getObjectManager, getOrCreateDataType, getPropertyManager, getQuotedNameCasePolicy, getSchema, getSchemaObjectExpanders, getTimestamp, getTimestamp, getUniqueName, getValidatorForType, hasPriviledge, isEditable, isNewFromTemplateType, isRequestedObject, isValidName, isValidName, listObjects, listObjects, listObjects, listObjects, listObjects, listObjectsFromCache, listObjectsImpl, listObjectsImpl, listObjectsImpl, listObjectTypes, listSchemas, listSchemas, listSupportedDataTypes, logEvent, markForLazyInit, markForLazyInit, normaliseType, putCachedTimestampKey, quoteIdentifier, registerBuilder, registerExpanders, registerSchemaObjectExpander, registerType, registerValidator, removeProviderListener, resetObject, resumeTimestampQueries, schemaUpdated, setDefaultTemplateForType, supportsObjectType, supportsTimestamps, supportsTimestamps, suspendTimestampQueries, uncacheObject, unregisterBuilder, unregisterValidator, updateObject, updateObjects, updateSchema, validateName, validateName, validateObject, validateObject, validateObject, validateObject, validateObjectProperty, validateObjectProperty, validateObjectProperty, validateObjectProperty, validateSchema, validateSchema, validateUniqueName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface oracle.javatools.db.Database
getIdentifierQuoteString, getUserName
 
Methods inherited from interface oracle.javatools.db.DBObjectProvider
addProviderListener, canCreate, canDelete, createObject, createObjects, createSchema, deleteObject, deleteObjects, deleteSchema, getCascadeManager, getDataType, getDefaultTemplateForType, getDiffEngine, getExternalName, getExternalName, getInternalName, getInternalName, getObject, getObject, getObjectFactory, getObjectManager, getOrCreateDataType, getPropertyManager, getSchema, getTimestamp, getTimestamp, getUniqueName, hasPriviledge, isEditable, isNewFromTemplateType, isValidName, isValidName, listObjects, listObjects, listObjects, listObjects, listObjects, listObjectTypes, listSchemas, listSchemas, listSupportedDataTypes, quoteIdentifier, removeProviderListener, setDefaultTemplateForType, supportsObjectType, undeleteObject, undeleteObjects, updateObject, updateObjects, updateObjects, updateSchema, validateName, validateName, validateObject, validateObject, validateObject, validateObject, validateObjectProperty, validateObjectProperty, validateObjectProperty, validateObjectProperty, validateSchema, validateSchema, validateUniqueName
 

Field Detail

SQLSTATE_NOT_IMPLEMENTED

public static final java.lang.String SQLSTATE_NOT_IMPLEMENTED
See Also:
Constant Field Values
Constructor Detail

AbstractDatabase

protected AbstractDatabase(java.lang.String connStore,
                           java.lang.String connName,
                           java.sql.Connection conn)
Constructs a new AbstractDatabase.

Parameters:
connName - a String containing the ConnectionManager name for the connection associated with this Database
conn - the Connection used by this AbstractDatabase
Method Detail

sqlTrace

@Deprecated
protected void sqlTrace(java.lang.String query)
Deprecated. - Tracing is done automatically by the QueryWrapper implementations. DDL tracing is done automatically for implementations of DDLDatabase.

Tracing method to print out SQL that is about to be executed against the db.


sqlTrace

@Deprecated
protected void sqlTrace(java.lang.String query,
                                   java.lang.Object[] params)
Deprecated. - Tracing is done automatically by the QueryWrapper implementations. DDL tracing is done automatically for implementations of DDLDatabase.

Tracing method to print out SQL that is about to be executed against the db.


getDatabaseType

public final java.lang.String getDatabaseType()
Description copied from interface: Database
Gets the type of database. This method uses JDBC metadata to determine the database type.

Specified by:
getDatabaseType in interface Database
Returns:
an String describing the type of database
See Also:
DatabaseMetaData.getDatabaseProductName()

getDatabaseVersion

public final int getDatabaseVersion()
Description copied from interface: Database
Gets the version of the database for the api implementation. This will not numerically correspond to the database model number, but is an int that the Database implementation uses to identify different versions.

Specified by:
getDatabaseVersion in interface Database

registerValidators

protected void registerValidators()
By default this registers default validators for Schema, Sequences, Synonyms, Indexes, Constraints and Columns for the wizards to use.


getDDLGenerator

@Deprecated
public DDLGenerator getDDLGenerator()
Deprecated. - pushed down to DDLDatabase

Retrieves the DDLGenerator used by default.

Returns:
the DDLGenerator used for generating DDL

exists

protected final boolean exists(SystemObject obj)
Whether the specified object exists. Calls exists(String,String,String) with the appropriate details.

Parameters:
obj - The object being checked
Returns:
whether the object exists.

registerBuilders

protected abstract void registerBuilders()
Called to request that the DBOBjectBuilders be registered.


getConnection

public final java.sql.Connection getConnection()
Description copied from interface: Database
Gets the JDBC connection associated with this database. If the Connection is closed the Database will silently try and reconnect. If reconnect fails, the original (dead) Connection will be returned.

Code should, where possible, use one of the wrapper classes in oracle.javatools.db.execute to use a Connection and not need to directly call this method.

Specified by:
getConnection in interface Database
Returns:
the Connection owned by this database object
See Also:
Database.getConnection(boolean)

getConnection

public final java.sql.Connection getConnection(boolean reconnect)
                                        throws DBException
Description copied from interface: Database
Gets the JDBC connection associated with this database. If the given connection has been closed, the Database can attempt to reconnect it if desired. Any problem with the reconnect will be thrown as a DBException. Note that if reconnect is true, a test of the connection will be performed which hits the database using Database.isConnectionAlive().

Specified by:
getConnection in interface Database
Parameters:
reconnect - whether to try and reconnect to the db
Returns:
the Connection owned by this database object
Throws:
DBException - wrapping a SQLException if there is a problem reconnecting

isConnectionAlive

public final boolean isConnectionAlive()
Description copied from interface: Database
Tests whether the connection underneath this Database is "alive" - i.e. whether it is open and working.

Note the implementation of this is database specific - a positive can be assumed true but a negative could be incorrect.

Specified by:
isConnectionAlive in interface Database
Returns:
true if the underlying jdbc connection is working
See Also:
Database.getConnection(boolean)

isConnectionAlive

protected boolean isConnectionAlive(java.sql.Connection conn)
Implementation that checks whether the given (current) connection is alive. Implementations should not call getConnection() or similar, and only check the passed Connection object.

The calling of this method assumes that if the execution is blocked waiting for a monitor lock, the block is because of the Connection being busy and therefore alive. It is therefore illegal for any implemenation of this method to try and get the monitor lock for any object other than the connection.

Parameters:
conn - the connection to check (will not be null).
Returns:
whether the given connection is alive.

getAliveTestStatement

protected java.lang.String getAliveTestStatement()
Returns a statement that, if executed succesfully, tests whether the given connections is live. The statement must yield a positive return from Statement.execute(java.lang.String) to be a valid test (e.g. SELECT 1 FROM DUAL for Oracle).

Returns:

isConnectionClosed

public java.lang.Boolean isConnectionClosed(java.sql.SQLException sqe)
This default implementation returns null unless the SQLException has a SQLState of "08003" - the ANSI standard for "closed connection". Few JDBC drivers adhere to the standard, so for all other exceptions this method will return null indicating that the exception cannot be identified. Consequently for the connection closed support to work a Database implementation should override this method.

Specified by:
isConnectionClosed in interface Database
Parameters:
sqe - the exception to test
Returns:
true if the connection signifies that the connection is closed.

hasTransaction

public boolean hasTransaction()
Description copied from interface: Database
Tests whether there is currently a "transaction" open on the underlying java.sql.Connection.

Note the implementation of this is database specific - a positive can be assumed true but a negative could be incorrect.

Specified by:
hasTransaction in interface Database
Returns:
true we are able to determine that a transaction is currently open on the underlying jdbc connection.

getTransactionTestQuery

protected java.lang.String getTransactionTestQuery()

testSQLStatement

public void testSQLStatement(java.lang.String sql)
                      throws DBException
Description copied from interface: Database
Tests that the given SQL executes against the database. This is separate to the SQLQueryBuilder API and is a simple test against the database.

Specified by:
testSQLStatement in interface Database
Parameters:
sql - the sql to test
Throws:
InvalidSQLException - if the sql doesn't execute (because the syntax is invalid etc).
DBException - for any other error in executing the sql

getName

public final java.lang.String getName()
Description copied from class: AbstractDBObjectProvider
Returns an identifier for this provider.

Specified by:
getName in class AbstractDBObjectProvider

getConnectionName

public final java.lang.String getConnectionName()
Description copied from interface: Database
Retrieves the name for the Connection associated with this Database in whichever connection store it is stored in.

Specified by:
getConnectionName in interface Database
Returns:
a String containing the connection name
See Also:
Database.getConnectionStore(), Database.getQualifiedName()

getConnectionStore

public final java.lang.String getConnectionStore()
Description copied from interface: Database
Retrieves the connection store the Connection associated with this Database is stored in. This is not a displayable string.

Specified by:
getConnectionStore in interface Database
Returns:
a String containing the connection store identifier.
See Also:
Database.getQualifiedName()

getQualifiedName

public final java.lang.String getQualifiedName()
Description copied from interface: Database
Retrieves a qualified name containing the connection store and connection name. The string is encoded so that it can be used as part of a URL. This is not a displayable string.

If this connection has no connection store associated with it, this method will simply return the encoded connection name.

Specified by:
getQualifiedName in interface Database
Returns:
a String containing the encoded, qualified name.
See Also:
Database.getConnectionStore(), Database.getConnectionName()

reconnect

protected void reconnect()
                  throws DBException
Throws:
DBException

reconnected

protected void reconnected(java.sql.Connection c)
Called when a reconnect happens to (re)initialise any member appropriately on the new Connection.

Parameters:
c - the connection to initialise on

close

public void close()
Description copied from interface: Database
Closes the Database Connection (and the supplied JDBC Connection).

Specified by:
close in interface Database

exists

public boolean exists(java.lang.String type,
                      java.lang.String schema,
                      java.lang.String name)
Description copied from interface: Database
Checks for existance of a schema object named objectName.

Specified by:
exists in interface Database
name - The name of the schema object.
Returns:
true if the object exists, false otherwise.

isObjectValid

public boolean isObjectValid(java.lang.String objectType,
                             java.lang.String schema,
                             java.lang.String objectName)
Description copied from interface: Database
Determines whether the specified database object is in a valid state.

Specified by:
isObjectValid in interface Database
Parameters:
objectType - the type of the object.
schema - the name of the schema containing the object
objectName - the name of the object

createSchema

protected final Schema createSchema(java.lang.String name)

finishCreate

protected void finishCreate(SystemObject[] objects,
                            SystemObject[] oldObjects)
                     throws DBException
Use to finish the create or update of objects after the changes have been made in the db. This method will sort out any cache updates and fire approriate provider messages.

Throws:
DBException

getCreatedObject

protected SystemObject getCreatedObject(java.lang.String type,
                                        Schema schema,
                                        java.lang.String name)
                                 throws DBException
Used by finishCreate() to get the object that's just been created back from the database so that it can be verified before returning to the user. By default this just calls AbstractDBObjectProvider.getObject(String,Schema,String)

Throws:
DBException
See Also:
finishCreate(oracle.javatools.db.SystemObject[], oracle.javatools.db.SystemObject[])

finishDelete

protected void finishDelete(SystemObject[] objs)
Use to finish the delete of the given objects after the operation has been performed against the db. Calls overloaded finishDelete for each schema that the given objects are owned by.

See Also:
#finishDelete(Schema,SchemaObject[])

finishDelete

protected void finishDelete(Schema schema,
                            SystemObject[] objs)
Use to finish the delete of the given objects after the operation has been performed against the db. The cache is updated, delete cascaded to any already built objects and any messages fired.


createByIDImpl

protected SystemObject createByIDImpl(DBObjectID id)
                               throws DBException
Overrides:
createByIDImpl in class AbstractDBObjectProvider
Throws:
DBException

getDatabaseSource

public java.lang.String getDatabaseSource(java.lang.String objectType,
                                          Schema schema,
                                          java.lang.String objectName)
                                   throws DBException
Description copied from interface: Database
Retrieves the source for an object in the database. The specified object is assumed to be of some type that represents source; non-source based objects will return null.

Specified by:
getDatabaseSource in interface Database
Parameters:
objectType - The type of object for which the source is needed
schema - The Schema containing the object
objectName - The name of the object
Returns:
The source representing the object
Throws:
DBException - if an error occurs fetching the source

getDatabaseSource

public java.lang.String getDatabaseSource(java.lang.String objectType,
                                          Schema schema,
                                          java.lang.String objectName,
                                          java.lang.String sourceType)
                                   throws DBException
Description copied from interface: Database
Retrieves the source for an object in the database. The specified object is assumed to be of some type that represents source; non-source based objects will return null. This method combines spec and body for those source types that support both.

Specified by:
getDatabaseSource in interface Database
Parameters:
objectType - The type of object for which the source is needed
schema - The Schema containing the object
objectName - The name of the object
sourceType - In the case of types that have more than one source, the type of source required. Can be Database.SOURCE_TYPE_SPEC or Database.SOURCE_TYPE_BODY. If null, the default of body is selected.
Returns:
The source representing the object
Throws:
DBException - if an error occurs fetching the source

getDefaultSchema

public Schema getDefaultSchema()
                        throws DBException
Returns the default schema for the connection or null if there isn't one. If the database doesn't support schemas, returns an anonymous schema.

Specified by:
getDefaultSchema in interface DBObjectProvider
Throws:
DBException

isUsernameCaseInsensitive

protected boolean isUsernameCaseInsensitive()
Returns true if the username is treated as case insensitive. This default implementation returns true. Override when it isn't true, e.g. MySQL, Sybase


supportsDebugging

public boolean supportsDebugging()
Description copied from interface: Database
Whether this database instance supports JDWP debugging. If the database does not support debugging, or only supports debugging using a custom protocol, this method should return false.

Specified by:
supportsDebugging in interface Database
Returns:
true if JDWP debugging is supported against this database, false otherwise

getObjectImpl

protected <T extends SystemObject> T getObjectImpl(DBObjectCriteria<T> criteria)
                                        throws DBException
Overrides:
getObjectImpl in class AbstractDBObjectProvider
Throws:
DBException

getDescriptor

public DatabaseDescriptor getDescriptor()
Description copied from interface: DBObjectProvider
Returns the DatabaseDescriptor for this provider

Specified by:
getDescriptor in interface DBObjectProvider

canRestrictSchemaList

public boolean canRestrictSchemaList()
Description copied from interface: Database
Whether this provider supports restricting the list of schemas to those with visible objects. For some providers, determining this list may be significantly more expensive than just returning a raw list of schemas.

Specified by:
canRestrictSchemaList in interface Database
Returns:
whether this provider allows the schema list to be restricted to those schemas with visible objects

setStatement

public void setStatement(java.sql.Statement statement)
Internal use only. Sets the current statement being executed against the database.

Parameters:
statement - the Statement being executed
Throws:
java.lang.IllegalArgumentException - if a non-null Statement is passed and there is already a non-null Statement recorded against the AbstractDatabase
For internal use only. Application developers should not use this

cancelStatement

public void cancelStatement()
Cancels the Statement currently executing against this Database if:
  1. such a statement has been recorded by the use of a StatementWrapper/QueryWrapper
  2. both the DBMS and driver support aborting an SQL statement


Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.4.0)

E13403-05

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