|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.ifeth.sehr.lib.DAOJdbc
This is a data access object (DAO) for accessing the SEHR databases by standard JDBC/SQL without using he iBatis layer.
This DAO object implements some often used sql methods and seals them to a
single call command. To use this layer first establish a FBDataSource object.
After inittialization of this object you can define PreparedStatements or
just plain SQL queries to be executed.
Note: This DAO can also use pooled connections for the datasource. To
activate a pooled connection use
. Pooled
connections are handy to get more control i.e. on RAS connections!
setPooledConnections(boolean)
Field Summary |
Fields inherited from interface org.ifeth.sehr.lib.DAOJdbcInterface |
CON_CANCLOSE, CON_CLOSEDENIED, CON_COMMITREQUIRED, STS_ACTIVE, STS_CLOSED, STS_NOTFOUND, STS_SQLERROR |
Constructor Summary | |
DAOJdbc()
Parameterless constructor. |
|
DAOJdbc(java.sql.Connection con)
Constructor for a single connection DAO object to use it with an already establish connction handle. |
|
DAOJdbc(SEHRDataSource fbds)
Constructor with given FBDataSource object. |
Method Summary | |
void |
addPreparedStatement(java.lang.String psname,
java.lang.String sql)
Add a named and init prepared statement for a single connection (id 0). |
void |
addPreparedStatement(java.lang.String psname,
java.lang.String sql,
int cidx)
Add a named and init prepared statement for a given connection. |
void |
canClose(boolean allow)
Allow or disallow closing of connection #0 (single connection). |
int |
checkConnection()
Check connection. |
int |
checkConnection(int idx)
Check connection. |
void |
close()
Use this method to close the single connection. |
java.sql.Connection |
connect()
This method established a single connection to the given datasource on instantiation of this object. |
int |
connectToPool()
This method established a new connection using the pool. |
int |
countConnections()
Get number of current handled connections |
boolean |
executePrepStmnt(java.sql.PreparedStatement stmnt)
Execute a prepared statement as SQL query. |
boolean |
executeQuery(java.lang.String sql)
Execute a plain SQL query for single connection. |
boolean |
executeQuery(java.lang.String sql,
int conidx)
Execute a plain SQL query using given connection. |
void |
forceClosePooledConnections()
Use this method with care! |
void |
freeConnection(int cidx)
Use this method to put a connection back to the pool |
java.sql.Connection |
getConnection()
get connection handle for a single connection |
java.sql.Connection |
getConnection(int cidx)
get connection handle for a given connection by 'index' |
java.sql.PreparedStatement |
getPreparedStatement(java.lang.String psname)
Retrieve a named statement for single connection from hash to use it by executePrepStmnt(PreparedStatement) |
java.sql.PreparedStatement |
getPreparedStatement(java.lang.String psname,
int idx)
Retrieve a named statement for given connection by id to use it by executePrepStmnt(PreparedStatement) |
java.sql.ResultSet |
getResultSet()
Get ResultSet of executed query. |
static void |
main(java.lang.String[] args)
For testing and study purposes... |
void |
setConnection(java.sql.Connection con)
Set a connection handle (The fbds is not required then) |
void |
setPooledConnections(boolean b)
Method to activate or deactivate pooled connections. |
void |
setSEHRDataSource(SEHRDataSource fbds)
Set the FBDataSource handle for which a connection can be initialized. |
void |
setStatus(int cidx,
int statuscode)
Set status to handle connection. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DAOJdbc()
Parameterless constructor. Set the SEHRDataSource by
setSEHRDataSource(SEHRDataSource)
and check the
returncode if a connection is available.
public DAOJdbc(SEHRDataSource fbds)
public DAOJdbc(java.sql.Connection con)
Method Detail |
public java.sql.Connection connect() throws java.sql.SQLException
java.sql.SQLException
public int connectToPool() throws java.sql.SQLException
Note: Use setPooledConnections(boolean)
first to
initiate a pooled connection.
java.sql.SQLException
public void setPooledConnections(boolean b) throws java.sql.SQLException
To keep data integrity on open transactions there is a small workaraound to
be shure we can deactive our pooled cons
Note: To force closing first use 'forceClosePooledConnections()'
first (at your own risc!!) then call this method.
java.sql.SQLException
public void forceClosePooledConnections()
public void close() throws java.sql.SQLException
Use freeConnection(int)
to close a pooled connection.
java.sql.SQLException
public void freeConnection(int cidx) throws java.sql.SQLException
java.sql.SQLException
public void canClose(boolean allow)
This is a helper method to indicate if a connection is in use or not, e.g. for a period of time, and an application is allowed to close RAS connections.
public void addPreparedStatement(java.lang.String psname, java.lang.String sql) throws java.sql.SQLException
java.sql.SQLException
addPreparedStatement(String, String, int)
public void addPreparedStatement(java.lang.String psname, java.lang.String sql, int cidx) throws java.sql.SQLException
Use PreparedStatements for frequently used SQL queries. These statements
are first prepared by the engine and then stored as objects. To assign
parameters just extract the statement from hash by
getPreparedStatement(String, int)
, assign the parameter
and call method executePrepStmnt(PreparedStatement)
java.sql.SQLException
public java.sql.PreparedStatement getPreparedStatement(java.lang.String psname) throws java.lang.Exception
executePrepStmnt(PreparedStatement)
java.lang.Exception
public java.sql.PreparedStatement getPreparedStatement(java.lang.String psname, int idx) throws java.lang.Exception
executePrepStmnt(PreparedStatement)
java.lang.Exception
public boolean executePrepStmnt(java.sql.PreparedStatement stmnt) throws java.lang.Exception
If a recordset is available the method returns 'true'. To access the
resultset use getResultSet()
.
java.lang.Exception
public boolean executeQuery(java.lang.String sql) throws java.lang.Exception
java.lang.Exception
public boolean executeQuery(java.lang.String sql, int conidx) throws java.lang.Exception
If a recordset is available the method returns 'true'. To access the
resultset use getResultSet()
.
java.lang.Exception
public void setStatus(int cidx, int statuscode) throws java.sql.SQLException
Statuscodes (use DAOJdbcInterface
):
0 = can close 1 = don't close/not allowed 2 = commit required (manupulated records) (if using autocommit this code has no effect)
java.sql.SQLException
public java.sql.ResultSet getResultSet()
public void setConnection(java.sql.Connection con)
public java.sql.Connection getConnection()
public java.sql.Connection getConnection(int cidx)
public int countConnections()
public int checkConnection()
checkConnection(int)
public int checkConnection(int idx)
Use this together with a timer/thread to check connection periodically.
Statuscodes:
-1 = SQL Exception(broken?) 0 = ok 1 = closed 2 = none found for id (already closed/pool out of sync?)
public void setSEHRDataSource(SEHRDataSource fbds) throws java.lang.Exception
fbds
- FBDataSource object
java.lang.Exception
public static void main(java.lang.String[] args)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |