de.mathema.pride
Interface ResourceAccessor

All Superinterfaces:
SQLFormatter
All Known Implementing Classes:
AbstractResourceAccessor, ResourceAccessorJ2EE, ResourceAccessorJ2SE, ResourceAccessorWeb

public interface ResourceAccessor
extends SQLFormatter

Interface for access to physical resources. Each Database object has one resource accessor associated which is passed at construction time.

Author:
Jan Lessner

Nested Class Summary
static interface ResourceAccessor.AutoKeyMode
           
static interface ResourceAccessor.Config
           
static interface ResourceAccessor.DBType
           
 
Field Summary
static java.lang.String REVISION_ID
           
static java.util.Date SYSTIME_DEFAULT
          Default value for the database system time identifier, if the database specific CURRENT_TIMESTAMP has to be used Default: Thu Jan 01 00:00:01 CET 0001
 
Method Summary
 java.lang.String formatOperator(java.lang.String operator, java.lang.Object rawValue)
          Performs an SQL formating of the passed operator.
 java.lang.Object formatPreparedValue(java.lang.Object value)
          Performs a type conversion of a passed value for usage in a prepared statement write access function.
 java.lang.String formatValue(java.lang.Object value)
          Performs an SQL formating of the passed value
 java.lang.String[] getAutoFields(java.sql.Statement stmt, java.lang.String[] rawAutoFields)
          Return an array of auto fields to be used as parameter for an SQL insertion operation.
 java.sql.ResultSet getAutoFieldVals(java.sql.Statement stmt, java.lang.String[] rawAutoFields)
          Fetch the values for auto-generated fields from the last insertion execution performed on the passed statement.
 java.sql.Connection getConnection(java.lang.String db)
          Returns a connection to the database represented by the ResourceAccessor.
 java.lang.String getDBType()
          Returns the type of DB being represented by this resource accessor.
 java.util.Date getSystime()
          Returns the timestamp, that is currently used to identify, that a date has to be replaced by the database server's system time.
 java.lang.String getTableName(java.lang.String logicalTableName)
          Returns the physical table name for the logical table name refered to by parameter logicalTableName
 java.lang.String getURL(java.lang.String db)
          Retrieves the URL for this DBMS represented by the ResourceAccessor.
 java.lang.String getUserName(java.lang.String db)
          Retrieves the user name as known to this database represented by the ResourceAccessor.
 boolean isLogging()
          Returns the current SQL logging state
 void releaseConnection()
          Release any connections being allocated by calls of getConnection(java.lang.String).
 void releaseConnection(java.sql.Connection con)
          Release a particular connection being allocated by a call of getConnection(java.lang.String).
 boolean setLogging(Database db, boolean state)
          Switch SQL logging on and off, according to the the value of parameter state.
 void sqlLog(Database db, java.lang.String operation)
          Writes the passed operation to the SQL log, if logging is enabled
 void sqlLogError(Database db, java.sql.SQLException sqlx)
          Writes the passed SQL exception to the log, if logging is enabled
 

Field Detail

SYSTIME_DEFAULT

static final java.util.Date SYSTIME_DEFAULT
Default value for the database system time identifier, if the database specific CURRENT_TIMESTAMP has to be used Default: Thu Jan 01 00:00:01 CET 0001


REVISION_ID

static final java.lang.String REVISION_ID
See Also:
Constant Field Values
Method Detail

getSystime

java.util.Date getSystime()
Returns the timestamp, that is currently used to identify, that a date has to be replaced by the database server's system time. If a date for an sql statement matches this value, it will be replaced by a database specific string in insert and update statements.


setLogging

boolean setLogging(Database db,
                   boolean state)
Switch SQL logging on and off, according to the the value of parameter state.

Returns:
the new logging state. The value might defer from state if the ResourceAccessor denies toggling.

isLogging

boolean isLogging()
Returns the current SQL logging state


sqlLog

void sqlLog(Database db,
            java.lang.String operation)
Writes the passed operation to the SQL log, if logging is enabled


sqlLogError

void sqlLogError(Database db,
                 java.sql.SQLException sqlx)
Writes the passed SQL exception to the log, if logging is enabled


getConnection

java.sql.Connection getConnection(java.lang.String db)
                                  throws java.lang.Exception
Returns a connection to the database represented by the ResourceAccessor. This function is called before every single database operation and is therefore supposed to run very fast.

Throws:
java.lang.Exception

releaseConnection

void releaseConnection()
                       throws java.sql.SQLException
Release any connections being allocated by calls of getConnection(java.lang.String). This function may be called, before a worker thread is about to close down or fall asleep.

Throws:
java.sql.SQLException

releaseConnection

void releaseConnection(java.sql.Connection con)
                       throws java.sql.SQLException
Release a particular connection being allocated by a call of getConnection(java.lang.String). This function is called after every every single database operation

Throws:
java.sql.SQLException

getAutoFields

java.lang.String[] getAutoFields(java.sql.Statement stmt,
                                 java.lang.String[] rawAutoFields)
                                 throws java.lang.Exception
Return an array of auto fields to be used as parameter for an SQL insertion operation. If the function returns null, the insertion is executed without any parameters. This is in fact the main reason for this function because not all JDBC drivers support Statement.executeUpdate(String operation, String[] autoFields).

Parameters:
stmt - The statement which is about to be executed
rawAutoFields - The auto fields to consider as declared in a descriptor
Throws:
java.lang.Exception

getAutoFieldVals

java.sql.ResultSet getAutoFieldVals(java.sql.Statement stmt,
                                    java.lang.String[] rawAutoFields)
                                    throws java.sql.SQLException
Fetch the values for auto-generated fields from the last insertion execution performed on the passed statement. This is by default done using JDBC's getGeneratedKeys() function. However, some databases and JDBC drivers have their own specific ways to fetch that data.

Parameters:
stmt - SQL statement object which was last be used to execute an insertion.
rawAutoFields - The auto fields to consider as declared in a descriptor
Throws:
java.sql.SQLException

getTableName

java.lang.String getTableName(java.lang.String logicalTableName)
                              throws java.lang.Exception
Returns the physical table name for the logical table name refered to by parameter logicalTableName

Throws:
java.lang.Exception

formatValue

java.lang.String formatValue(java.lang.Object value)
Performs an SQL formating of the passed value

Specified by:
formatValue in interface SQLFormatter

formatOperator

java.lang.String formatOperator(java.lang.String operator,
                                java.lang.Object rawValue)
Performs an SQL formating of the passed operator.

Specified by:
formatOperator in interface SQLFormatter
Parameters:
operator - Any of the operators defined in SQLExpression.Operator
rawValue - The raw value the operator is applied to before it is formated by formatValue(java.lang.Object). May be null.

formatPreparedValue

java.lang.Object formatPreparedValue(java.lang.Object value)
Performs a type conversion of a passed value for usage in a prepared statement write access function. This function is required if the raw value can not directly be passed to a PreparedStatement, e.g. java.util.Date.

Specified by:
formatPreparedValue in interface SQLFormatter

getURL

java.lang.String getURL(java.lang.String db)
                        throws java.lang.Exception
Retrieves the URL for this DBMS represented by the ResourceAccessor.

Parameters:
db -
Returns:
the database url
Throws:
java.lang.Exception
See Also:
DatabaseMetaData

getUserName

java.lang.String getUserName(java.lang.String db)
                             throws java.lang.Exception
Retrieves the user name as known to this database represented by the ResourceAccessor.

Parameters:
db -
Returns:
the user name
Throws:
java.lang.Exception
See Also:
DatabaseMetaData

getDBType

java.lang.String getDBType()
Returns the type of DB being represented by this resource accessor. See constants in interface #DBType for the type keys which are supported by default.