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.

Author:
Jean-Paul Vetterli

Constructor Summary
JDBCDatabaseMethods()
           
 
Method Summary
 PreparedStatement close(PreparedStatement stmt)
          Close the prepared statement.
 ch.agent.crnickl.api.DBObjectId executeAndGetNewId(PreparedStatement stmt)
          Execute a prepared statement of the "insertion" type and return the generated id.
protected  int getId(ch.agent.crnickl.api.DBObject dBObject)
          Return the internal ID of a database object.
 int getId(ch.agent.crnickl.api.Surrogate surrogate)
          Extract the internal ID of a database object from its surrogate.
 int getIdOrZero(ch.agent.crnickl.api.DBObject dBObject)
          Return the internal ID of a database object or 0 if the object is null or is in construction.
 ch.agent.crnickl.api.Surrogate makeSurrogate(ch.agent.crnickl.api.Database db, ch.agent.crnickl.api.DBObjectType dot, int id)
          Create a surrogate for a database object.
 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, checkIntegrity, 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

getIdOrZero

public int getIdOrZero(ch.agent.crnickl.api.DBObject dBObject)
Return the internal ID of a database object or 0 if the object is null or is in construction. The internal ID is not exposed to clients.

This method is for use inside the JDBC implementation and its argument must have a DBObjectId implemented by JDBCObjectId.

Parameters:
dBObject - a database object or null
Returns:
a non negative integer

getId

protected int getId(ch.agent.crnickl.api.DBObject dBObject)
Return the internal ID of a database object. The internal ID is not exposed to clients.

This method is for use inside the JDBC implementation and its argument must have a DBObjectId implemented by JDBCObjectId.

Parameters:
dBObject - a database object
Returns:
a positive integer

getId

public int getId(ch.agent.crnickl.api.Surrogate surrogate)
Extract the internal ID of a database object from its surrogate. The internal ID is not exposed to clients.

This method is for use inside the JDBC implementation and its argument must have a DBObjectId implemented by JDBCObjectId.

Parameters:
surrogate - the surrogate of a database object
Returns:
a positive integer

makeSurrogate

public ch.agent.crnickl.api.Surrogate makeSurrogate(ch.agent.crnickl.api.Database db,
                                                    ch.agent.crnickl.api.DBObjectType dot,
                                                    int id)
Create a surrogate for a database object.

Parameters:
db - the database of the object
dot - the type of the object
id - the internal ID of the database object
Returns:
a surrogate

executeAndGetNewId

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

Parameters:
stmt - a prepared statement
Returns:
a generated id
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 © 2013. All Rights Reserved.