ch.agent.crnickl.jdbc
Class JDBCDatabaseMethods

java.lang.Object
  extended by ch.agent.crnickl.impl.DatabaseMethodsImpl
      extended by ch.agent.crnickl.jdbc.JDBCDatabaseMethods
All Implemented Interfaces:
ch.agent.crnickl.impl.DatabaseMethods, ch.agent.crnickl.impl.PermissionChecker
Direct Known Subclasses:
AccessMethodsForAny, AccessMethodsForNumber, ReadMethodsForChroniclesAndSeries, ReadMethodsForProperty, ReadMethodsForSchema, ReadMethodsForValueType, WriteMethodsForValueType

public class JDBCDatabaseMethods
extends ch.agent.crnickl.impl.DatabaseMethodsImpl

A JDBCDatabaseMethods object provides support for prepared statements. It is meant as base class for actual access methods. All database accesses should be bracketed between one of the open and the close method.

Version:
1.0.0
Author:
Jean-Paul Vetterli

Constructor Summary
JDBCDatabaseMethods()
           
 
Method Summary
 PreparedStatement close(PreparedStatement stmt)
          Close the prepared statement.
 int executeAndGetNewId(PreparedStatement stmt)
          Execute a prepared statement of the "insertion" type and return the generated key.
 PreparedStatement open(String sql, ch.agent.crnickl.api.Database database, PreparedStatement stmt)
          Return a valid prepared statement for the SQL code specified.
 PreparedStatement open(String sql, ch.agent.crnickl.api.DBObject dBObject, PreparedStatement stmt)
          Return a valid prepared statement for the SQL code specified.
 PreparedStatement open(String sql, ch.agent.crnickl.api.Surrogate surrogate, PreparedStatement stmt)
          Return a valid prepared statement for the SQL code specified.
 
Methods inherited from class ch.agent.crnickl.impl.DatabaseMethodsImpl
check, check, check, check, getId, getId, getIdOrZero, makeSurrogate, makeSurrogate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCDatabaseMethods

public JDBCDatabaseMethods()
Method Detail

executeAndGetNewId

public int executeAndGetNewId(PreparedStatement stmt)
                       throws ch.agent.crnickl.T2DBException,
                              SQLException
Execute a prepared statement of the "insertion" type and return the generated key.

Parameters:
stmt - a prepared statement
Returns:
a generated key
Throws:
ch.agent.crnickl.T2DBException
SQLException

open

public PreparedStatement open(String sql,
                              ch.agent.crnickl.api.Database database,
                              PreparedStatement stmt)
                       throws ch.agent.crnickl.T2DBException
Return a valid prepared statement for the SQL code specified. The statement is prepared using the connection embedded in the database parameter. To avoid preparing a new statement again and again a statement can be passed as an argument. This statement will be returned if it is not null and if its connection is equal to the connection embedded in the mentioned parameter.

Parameters:
sql - a string in SQL syntax
database - a database
stmt - a prepared statement
Returns:
a prepared statement
Throws:
ch.agent.crnickl.T2DBException

open

public PreparedStatement open(String sql,
                              ch.agent.crnickl.api.DBObject dBObject,
                              PreparedStatement stmt)
                       throws ch.agent.crnickl.T2DBException
Return a valid prepared statement for the SQL code specified. The statement is prepared using the connection embedded in the dBObject parameter. To avoid preparing a new statement again and again a statement can be passed as an argument. This statement will be returned if it is not null and if its connection is equal to connection embedded in the mentioned parameter.

Parameters:
sql - a string in SQL syntax
dBObject - a database object
stmt - a prepared statement
Returns:
a prepared statement
Throws:
ch.agent.crnickl.T2DBException

open

public PreparedStatement open(String sql,
                              ch.agent.crnickl.api.Surrogate surrogate,
                              PreparedStatement stmt)
                       throws ch.agent.crnickl.T2DBException
Return a valid prepared statement for the SQL code specified. The statement is prepared using the connection embedded in the surrogate parameter. To avoid preparing a new statement again and again a statement can be passed as an argument. This statement will be returned if it is not null and if its connection is equal to connection embedded in the mentioned parameter.

Parameters:
sql - a string in SQL syntax
surrogate - a surrogate
stmt - a prepared statement
Returns:
a prepared statement
Throws:
ch.agent.crnickl.T2DBException

close

public PreparedStatement close(PreparedStatement stmt)
                        throws ch.agent.crnickl.T2DBException
Close the prepared statement. This implementation actually closes the statement and returns null. Possibly, a future implementation could decide not to close the statement and to return it to the client. For this reason it is meaningful for clients to cache the statement for reuse, with a possible positive effect on performance.

Parameters:
stmt - a prepared statement
Returns:
the prepared statement, set to null
Throws:
ch.agent.crnickl.T2DBException


Copyright © 2012. All Rights Reserved.