org.apache.ojb.broker.platforms
Class PlatformDefaultImpl

java.lang.Object
  extended by org.apache.ojb.broker.platforms.PlatformDefaultImpl
All Implemented Interfaces:
JoinSyntaxTypes, Platform
Direct Known Subclasses:
PlatformDb2Impl, PlatformDerbyImpl, PlatformFirebirdImpl, PlatformHsqldbImpl, PlatformInformixImpl, PlatformMsAccessImpl, PlatformMsSQLServerImpl, PlatformMySQLImpl, PlatformOracleImpl, PlatformPostgreSQLImpl, PlatformSapdbImpl, PlatformSybaseImpl

public class PlatformDefaultImpl
extends Object
implements Platform, JoinSyntaxTypes

This class is a concrete implementation of Platform. Provides default implementations for all methods declared in Platform. It is intended as a vanilla implementation and as baseclass for platform specific implementations.

Version:
$Id: PlatformDefaultImpl.java,v 1.1 2007-08-24 22:17:35 ewestfal Exp $
Author:
Thomas Mahler

Field Summary
protected  Logger log
           
protected  boolean m_batchUpdatesChecked
           
protected  boolean m_supportsBatchUpdates
           
 
Fields inherited from interface org.apache.ojb.broker.accesslayer.JoinSyntaxTypes
ORACLE_JOIN_SYNTAX, SQL92_JOIN_SYNTAX, SQL92_NOPAREN_JOIN_SYNTAX, SYBASE_JOIN_SYNTAX
 
Constructor Summary
PlatformDefaultImpl()
           
 
Method Summary
 void addBatch(PreparedStatement stmt)
          Called when adding statements to current batch.
 void addPagingSql(StringBuffer anSqlString)
          Add the LIMIT or equivalent to the SQL SQL-Paging is not yet supported
 void afterStatementClose(Statement stmt, ResultSet rs)
          Called by StatementManagerIF implementation after invoking stmt.close() method.
 void afterStatementCreate(Statement stmt)
          Called after a statement has been created.
 void beforeBatch(PreparedStatement stmt)
          Called before batching operations on a statement.
 void beforeStatementClose(Statement stmt, ResultSet rs)
          Called by StatementManagerIF implementation before invoking stmt.close() method.
 int bindPagingParameters(PreparedStatement ps, int index, int startAt, int endAt)
          Bind the Paging Parameters SQL-Paging is not yet supported
 boolean bindPagingParametersFirst()
          Answer true if the LIMIT parameters are bound before the query parameters SQL-Paging is not yet supported
 void changeAutoCommitState(JdbcConnectionDescriptor jcd, Connection con, boolean newState)
          Used to do a temporary change of the m_connection autoCommit state.
protected  void checkForBatchSupport(Connection conn)
          Sets platform information for if the jdbc driver/db combo support batch operations.
 String concatenate(String[] theColumns)
          Concatenate the columns
ie: col1 || col2 || col3 (ANSI)
ie: col1 + col2 + col3 (MS SQL-Server)
ie: concat(col1, col2, col3) (MySql)
 String createSequenceQuery(String sequenceName)
          Override this method to enable database based sequence generation
 String createSequenceQuery(String sequenceName, Properties prop)
          Returns a query to create a sequence entry.
 String dropSequenceQuery(String sequenceName)
          Override this method to enable database based sequence generation
 int[] executeBatch(PreparedStatement stmt)
          Executes current batch.
protected  String getConcatenationCharacter()
          Answer the Character for Concatenation
 String getEscapeClause(LikeCriteria aCriteria)
          Answer the Clause used Escape wildcards in LIKE
 byte getJoinSyntaxType()
          Get join syntax type for this RDBMS - one on of the constants from JoinSyntaxType interface
 String getLastInsertIdentityQuery(String tableName)
          If database supports native key generation via identity column, this method should return the sql-query to obtain the last generated id.
 void initializeJdbcConnection(JdbcConnectionDescriptor jcd, Connection conn)
          Called immediately after a JDBC connection has been created by a ConnectionFactory implementation (not used for DataSource connections).
 String nextSequenceQuery(String sequenceName)
          Override this method to enable database based sequence generation
 CallableStatement prepareNextValProcedureStatement(Connection con, String procedureName, String sequenceName)
          Create stored procedure call for a special sequence manager implementation SequenceManagerStoredProcedureImpl, because it seems that jdbc-driver differ in handling of CallableStatement.
 void registerOutResultSet(CallableStatement stmt, int position)
          Registers call argument at position as returning a ResultSet value.
 void setNullForStatement(PreparedStatement ps, int index, int sqlType)
          Called to let the Platform implementation perform any JDBC type-specific operations needed by the driver when binding null parameters for a PreparedStatement.
 void setObjectForStatement(PreparedStatement ps, int index, Object value, int sqlType)
          Called to let the Platform implementation perform any JDBC type-specific operations needed by the driver when binding positional parameters for a PreparedStatement.
 boolean supportsBatchOperations()
          If this platform supports the batch operations jdbc 2.0 feature.
 boolean supportsMultiColumnCountDistinct()
          Whether the platform supports a COUNT DISTINCT across multiple columns.
 boolean supportsPaging()
          Answer true if LIMIT or equivalent is supported SQL-Paging is not yet supported
 boolean useCountForResultsetSize()
          Override default ResultSet size determination (rs.last();rs.getRow()) with select count(*) operation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected Logger log

m_batchUpdatesChecked

protected boolean m_batchUpdatesChecked

m_supportsBatchUpdates

protected boolean m_supportsBatchUpdates
Constructor Detail

PlatformDefaultImpl

public PlatformDefaultImpl()
Method Detail

supportsBatchOperations

public boolean supportsBatchOperations()
Description copied from interface: Platform
If this platform supports the batch operations jdbc 2.0 feature. This is by driver, so we check the driver's metadata once and set something in the platform.

Specified by:
supportsBatchOperations in interface Platform
Returns:
true if the platform supports batch, false otherwise.

checkForBatchSupport

protected void checkForBatchSupport(Connection conn)
Sets platform information for if the jdbc driver/db combo support batch operations. Will only be checked once, then have same batch support setting for the entire session.

Parameters:
conn -

afterStatementCreate

public void afterStatementCreate(Statement stmt)
                          throws PlatformException
Description copied from interface: Platform
Called after a statement has been created.

Specified by:
afterStatementCreate in interface Platform
Throws:
PlatformException

beforeStatementClose

public void beforeStatementClose(Statement stmt,
                                 ResultSet rs)
                          throws PlatformException
Description copied from interface: Platform
Called by StatementManagerIF implementation before invoking stmt.close() method.

Specified by:
beforeStatementClose in interface Platform
Throws:
PlatformException

afterStatementClose

public void afterStatementClose(Statement stmt,
                                ResultSet rs)
                         throws PlatformException
Description copied from interface: Platform
Called by StatementManagerIF implementation after invoking stmt.close() method.

Specified by:
afterStatementClose in interface Platform
Throws:
PlatformException

beforeBatch

public void beforeBatch(PreparedStatement stmt)
                 throws PlatformException
Description copied from interface: Platform
Called before batching operations on a statement.

Specified by:
beforeBatch in interface Platform
Parameters:
stmt - the statement you want to batch on
Throws:
PlatformException

addBatch

public void addBatch(PreparedStatement stmt)
              throws PlatformException
Description copied from interface: Platform
Called when adding statements to current batch.

Specified by:
addBatch in interface Platform
Parameters:
stmt - the statement you are adding to the batch
Throws:
PlatformException

executeBatch

public int[] executeBatch(PreparedStatement stmt)
                   throws PlatformException
Description copied from interface: Platform
Executes current batch.

Specified by:
executeBatch in interface Platform
Parameters:
stmt - the statement you want to execute the batch on
Throws:
PlatformException

initializeJdbcConnection

public void initializeJdbcConnection(JdbcConnectionDescriptor jcd,
                                     Connection conn)
                              throws PlatformException
Description copied from interface: Platform
Called immediately after a JDBC connection has been created by a ConnectionFactory implementation (not used for DataSource connections).

Specified by:
initializeJdbcConnection in interface Platform
conn - the Connection to be initialized
Throws:
PlatformException
See Also:
Platform.initializeJdbcConnection(org.apache.ojb.broker.metadata.JdbcConnectionDescriptor, java.sql.Connection)

changeAutoCommitState

public void changeAutoCommitState(JdbcConnectionDescriptor jcd,
                                  Connection con,
                                  boolean newState)
Description copied from interface: Platform
Used to do a temporary change of the m_connection autoCommit state. When using this method ensure to reset the original state before m_connection was returned to pool or closed. Only when JdbcConnectionDescriptor.getUseAutoCommit() was set to JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE the change of the autoCommit state take effect.

Specified by:
changeAutoCommitState in interface Platform

setObjectForStatement

public void setObjectForStatement(PreparedStatement ps,
                                  int index,
                                  Object value,
                                  int sqlType)
                           throws SQLException
Description copied from interface: Platform
Called to let the Platform implementation perform any JDBC type-specific operations needed by the driver when binding positional parameters for a PreparedStatement.

Specified by:
setObjectForStatement in interface Platform
Throws:
SQLException

setNullForStatement

public void setNullForStatement(PreparedStatement ps,
                                int index,
                                int sqlType)
                         throws SQLException
Description copied from interface: Platform
Called to let the Platform implementation perform any JDBC type-specific operations needed by the driver when binding null parameters for a PreparedStatement.

Specified by:
setNullForStatement in interface Platform
Throws:
SQLException

getJoinSyntaxType

public byte getJoinSyntaxType()
Get join syntax type for this RDBMS - one on of the constants from JoinSyntaxType interface

Specified by:
getJoinSyntaxType in interface Platform
See Also:
Platform.getJoinSyntaxType()

useCountForResultsetSize

public boolean useCountForResultsetSize()
Override default ResultSet size determination (rs.last();rs.getRow()) with select count(*) operation

Specified by:
useCountForResultsetSize in interface Platform
See Also:
Platform.useCountForResultsetSize()

createSequenceQuery

public String createSequenceQuery(String sequenceName,
                                  Properties prop)
Description copied from interface: Platform
Returns a query to create a sequence entry.

Specified by:
createSequenceQuery in interface Platform
Parameters:
sequenceName - The name of the sequence to create.
prop - The database specific sequence properties.
Returns:
a sql string to create a sequence

createSequenceQuery

public String createSequenceQuery(String sequenceName)
Override this method to enable database based sequence generation

Specified by:
createSequenceQuery in interface Platform
Parameters:
sequenceName - The name of the sequence to create.
Returns:
a sql string to create a sequence

nextSequenceQuery

public String nextSequenceQuery(String sequenceName)
Override this method to enable database based sequence generation

Specified by:
nextSequenceQuery in interface Platform
Returns:
a sql string to get next sequence value

dropSequenceQuery

public String dropSequenceQuery(String sequenceName)
Override this method to enable database based sequence generation

Specified by:
dropSequenceQuery in interface Platform
Returns:
a sql string to drop a sequence

prepareNextValProcedureStatement

public CallableStatement prepareNextValProcedureStatement(Connection con,
                                                          String procedureName,
                                                          String sequenceName)
                                                   throws PlatformException
Description copied from interface: Platform
Create stored procedure call for a special sequence manager implementation SequenceManagerStoredProcedureImpl, because it seems that jdbc-driver differ in handling of CallableStatement.
Note: The out-parameter of the stored procedure must be registered at first position, because lookup for new long id in the implementation:
 Connection con = broker.serviceConnectionManager().getConnection();
 cs = getPlatform().prepareNextValProcedureStatement(con, PROCEDURE_NAME, sequenceName);
 cs.executeUpdate();
 return cs.getLong(1);
 

Specified by:
prepareNextValProcedureStatement in interface Platform
Throws:
PlatformException

getLastInsertIdentityQuery

public String getLastInsertIdentityQuery(String tableName)
Description copied from interface: Platform
If database supports native key generation via identity column, this method should return the sql-query to obtain the last generated id.

Specified by:
getLastInsertIdentityQuery in interface Platform

addPagingSql

public void addPagingSql(StringBuffer anSqlString)
Description copied from interface: Platform
Add the LIMIT or equivalent to the SQL SQL-Paging is not yet supported

Specified by:
addPagingSql in interface Platform
See Also:
Platform.addPagingSql(java.lang.StringBuffer)

bindPagingParametersFirst

public boolean bindPagingParametersFirst()
Description copied from interface: Platform
Answer true if the LIMIT parameters are bound before the query parameters SQL-Paging is not yet supported

Specified by:
bindPagingParametersFirst in interface Platform
See Also:
Platform.bindPagingParametersFirst()

supportsPaging

public boolean supportsPaging()
Description copied from interface: Platform
Answer true if LIMIT or equivalent is supported SQL-Paging is not yet supported

Specified by:
supportsPaging in interface Platform
See Also:
Platform.supportsPaging()

bindPagingParameters

public int bindPagingParameters(PreparedStatement ps,
                                int index,
                                int startAt,
                                int endAt)
                         throws SQLException
Description copied from interface: Platform
Bind the Paging Parameters SQL-Paging is not yet supported

Specified by:
bindPagingParameters in interface Platform
index - parameter index
Throws:
SQLException
See Also:
Platform.bindPagingParameters(java.sql.PreparedStatement, int, int, int)

getConcatenationCharacter

protected String getConcatenationCharacter()
Answer the Character for Concatenation


supportsMultiColumnCountDistinct

public boolean supportsMultiColumnCountDistinct()
Whether the platform supports a COUNT DISTINCT across multiple columns.

Specified by:
supportsMultiColumnCountDistinct in interface Platform
Returns:
true if it is supported

concatenate

public String concatenate(String[] theColumns)
Description copied from interface: Platform
Concatenate the columns
ie: col1 || col2 || col3 (ANSI)
ie: col1 + col2 + col3 (MS SQL-Server)
ie: concat(col1, col2, col3) (MySql)

Specified by:
concatenate in interface Platform
Returns:
the concatenated String
See Also:
Platform.concatenate(java.lang.String[])

getEscapeClause

public String getEscapeClause(LikeCriteria aCriteria)
Description copied from interface: Platform
Answer the Clause used Escape wildcards in LIKE

Specified by:
getEscapeClause in interface Platform
See Also:
Platform.getEscapeClause(org.apache.ojb.broker.query.LikeCriteria)

registerOutResultSet

public void registerOutResultSet(CallableStatement stmt,
                                 int position)
                          throws SQLException
Description copied from interface: Platform
Registers call argument at position as returning a ResultSet value.

Specified by:
registerOutResultSet in interface Platform
Parameters:
stmt - the statement
position - argument position
Throws:
SQLException
See Also:
Platform.registerOutResultSet(java.sql.CallableStatement, int)


Copyright © 2004-2012 The Kuali Foundation. All Rights Reserved.