org.jaffa.persistence.engines.jdbcengine.datasource
Class DataSource

java.lang.Object
  extended byorg.jaffa.persistence.engines.jdbcengine.datasource.DataSource

public class DataSource
extends Object

Encapsulates the connection to a data storage mechanism


Method Summary
 void closeStatement(Statement statement)
          Closes the statement and removes it from the internal collection.
 void commit()
          Commits all changes executed against the persistent store.
 Collection executeQuery(String sql, ClassMetaData classMetaData, Criteria criteria, int queryTimeout)
          Executes a query against the underlying data source.
 void executeUpdate(PreparedStatement stmt)
          Execute the input PreparedStatement.
 void executeUpdate(String sql)
          Executes the sql, which should be an update/insert/delete statement.
 CallableStatement getCallableStatement(String sql)
          Returns the CallableStatement object for the input sql.
 String getEngineType()
          Getter for property engineType, as defined in init.xml
 Integer getHitlistSize()
          Getter for property hitlistSize.
 PreparedStatement getPreparedStatement(String sql)
          Returns the PreparedStatement object for the input sql.
 Statement getStatement()
          Returns a Statement object.
 Boolean getUsePreparedStatement()
          Getter for property usePreparedStatement.
 void rollback()
          Rollback the changes executed against the persistent store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

closeStatement

public void closeStatement(Statement statement)
                    throws SQLException
Closes the statement and removes it from the internal collection.

Parameters:
statement - the Statement object to be closed.
Throws:
SQLException - if any database error occurs.

getStatement

public Statement getStatement()
                       throws SQLException
Returns a Statement object. This object will be added to an internal collection and will be closed when the DataSource is closed. It is a good idea to invoke the closeStatement() method when done with the statement.

Returns:
the Statement object.
Throws:
SQLException - if any database error occurs.

executeQuery

public Collection executeQuery(String sql,
                               ClassMetaData classMetaData,
                               Criteria criteria,
                               int queryTimeout)
                        throws SQLException,
                               PostLoadFailedException,
                               DataSourceCursorRuntimeException,
                               IOException
Executes a query against the underlying data source. Returns a Collection of persistent objects. The Statement object that is internally used for executing the query, will be automatically closed, once the recordset has been completely traversed.

Parameters:
sql - The query to execute.
classMetaData - The ClassMetaData defintion to be used for molding the ResultSet into Persistent objects.
criteria - The Criteria used for the query. This will provide the values to set the various flags on the Persistent object.
queryTimeout - This will be used for setting the timeout value on the Statement object; zero means there is no limit.
Returns:
a Collection of persistent objects.
Throws:
SQLException - if any database error occurs.
PostLoadFailedException - if any error is thrown in the PostLoad trigger of the persistent object.
DataSourceCursorRuntimeException - if any error occurs while molding the row into the Persistent object.
IOException - if any error occurs in reading the data from the database.

executeUpdate

public void executeUpdate(String sql)
                   throws SQLException
Executes the sql, which should be an update/insert/delete statement. The Statement object that is internally used for executing the update, will be immediately closed.

Parameters:
sql - the sql to execute.
Throws:
SQLException - if any database error occurs.

executeUpdate

public void executeUpdate(PreparedStatement stmt)
                   throws SQLException
Execute the input PreparedStatement. The calling program is expected to close the ResultSet(s), if any, that might be returned by executing the update.

Parameters:
stmt - the PreparedStatement to execute.
Throws:
SQLException - if any database error occurs.

getPreparedStatement

public PreparedStatement getPreparedStatement(String sql)
                                       throws SQLException
Returns the PreparedStatement object for the input sql. The PreparedStatement object will be cached for the connection.

Parameters:
sql - the sql statement which needs to be precompiled.
Returns:
the PreparedStatement object.
Throws:
SQLException - if any database error occurs.

getCallableStatement

public CallableStatement getCallableStatement(String sql)
                                       throws SQLException
Returns the CallableStatement object for the input sql. The CallableStatement object will be cached for the connection.

Parameters:
sql - the sql statement.
Returns:
the CallableStatement object.
Throws:
SQLException - if any database error occurs.

commit

public void commit()
            throws SQLException
Commits all changes executed against the persistent store.

Throws:
SQLException - if any database error occurs.

rollback

public void rollback()
              throws SQLException
Rollback the changes executed against the persistent store.

Throws:
SQLException - if any database error occurs.

getHitlistSize

public Integer getHitlistSize()
Getter for property hitlistSize.

Returns:
Value of property hitlistSize.

getEngineType

public String getEngineType()
Getter for property engineType, as defined in init.xml

Returns:
Value of property engineType.

getUsePreparedStatement

public Boolean getUsePreparedStatement()
Getter for property usePreparedStatement.

Returns:
Value of property usePreparedStatement.


Copyright © 2002-2004 JAFFA Project.