|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.ifeth.sehr.lib.SEHRDataSource
Simple class for accessing the firebird database from SEHR projects and to read/save local files like profiles, datastores encrypted.
To access a SEHR database there are three basic, but different ways
1) using the SQL layer iBATIS(C)
2) accessing the database by using 'java.sql' methods
3) using pooled connections
In any case the database must be connected first. This object can be
used either in SEHR server environments where the connection parameters
are available by the SEHRCfg.SEHRCfg()configuration
object or in a client environment by setting the parameters during
object initialization or by using the parameterless constructor in
conjunction with some setter methods.
Tip: If using the 2nd choice to access the database you should
use DAOJdbc.DAOJdbc(SEHRDataSource) as a layer between this
datasource connector and your application. The DAO provides some
commonly used methods for prepared statements in dependence to singleton
or pooled connections, executing prepared queries etc.;
In brief the DAO object will save time in coding instead of using
java.sql methods.
To use pooled connection do
initPooledFBDS()connectToPool()to establish a
connection and get its indexgetPooledConnection(int)to get
the connection handle for using with standard java.sql
procedures
| Constructor Summary | |
SEHRDataSource()
Initiates a parameterless object instance for database connection To initialize the access to the IntraSEC db use either or initialize
manually (e.g. on clients) by using all of the following setter
methods,
,
,
,
. |
|
SEHRDataSource(SEHRCfg cfg)
Initiates an object instance with connection parameters using the SEHR configuration object. |
|
SEHRDataSource(java.lang.String host,
int port,
java.lang.String database,
java.lang.String dblogin,
java.lang.String dbpw,
java.lang.String XMLpath)
Initiates an object instance with individual connection parameters This constructor is defined for clients, where a local file access to a SEHR configuration SEHRCfg is not available. |
|
SEHRDataSource(java.lang.String host,
java.lang.String port,
java.lang.String database,
java.lang.String dblogin,
java.lang.String dbpw)
Initiates an object instance with individual connection parameters To connect/open use connect()
|
|
SEHRDataSource(java.lang.String host,
java.lang.String sport,
java.lang.String database,
java.lang.String dblogin,
java.lang.String dbpw,
java.lang.String XMLpath)
Initiates an object instance with individual connection parameters |
|
| Method Summary | |
void |
close()
Close the firebird datasource handle of current object. |
static void |
close(SEHRDataSource fbds)
Close the firebird datasource handle of the given object. |
void |
closeAll()
Close all pooled connections |
void |
closeFBDataSource()
Deprecated. use 'close(...)' |
static void |
closeFBDataSource(SEHRDataSource fbds)
Deprecated. use 'close(...)' |
java.sql.Connection |
connect()
Make a connection for the current firebird database source object assuming the parameters are already invoked by this object instance. |
static java.sql.Connection |
connect(SEHRDataSource fbds)
Make a connection for the given firebird database source object assuming the parameters are already invoked by the given 'fbds' object instance. |
java.sql.Connection |
connectFBDataSource()
Deprecated. use 'connect()' |
static java.sql.Connection |
connectFBDataSource(SEHRDataSource fbds)
Deprecated. use 'connect()' |
java.sql.Connection |
connectFBDataSource(SEHRDataSource fbds,
java.lang.String host,
java.lang.String port,
java.lang.String database,
java.lang.String dblogin,
java.lang.String dbpw)
Deprecated. use 'connect()' |
java.sql.Connection |
connectFBDataSource(java.lang.String host,
java.lang.String port,
java.lang.String database,
java.lang.String dblogin,
java.lang.String dbpw)
Deprecated. use 'connect()' |
int |
connectToPool()
Create a new pooled connection for current firebird database source object. * Note: Use closePooledConnection(int conidx)! |
int |
countExpectedPooledConnections()
Get number of currently pooled connections handled by object |
int |
countPooledConnections()
Get number of currently pooled connections by FB engine |
static byte[] |
getBytesFromFile(java.io.File file)
Method to get contents of a file as bytes. |
java.lang.String |
getDBHost()
For general usage: get host of db access |
java.util.List |
getGenerator()
|
java.util.List |
getGenerator(java.lang.String genid)
|
java.sql.Connection |
getHFBConnection()
Return the connection handle for the current datasource object. |
java.sql.Connection |
getHFBConnection(SEHRDataSource sds)
Return the connection handle for given firebird datasource object |
java.sql.Connection |
getPooledConnection(int idx)
Get an already established connection from pool given by index. |
java.lang.String |
getRandomID()
Get a random digest ID |
com.ibatis.sqlmap.client.SqlMapClient |
getSqlmap()
Get the initialized SQL mapping object of connected datasource This is the recommended object for accessng the database by its SQL objects; see example in main(String[])
|
void |
init()
Initialize SEHR environment for db connections by setting the configuration object The configuration holds some more informations like the XML mappings. |
void |
init(java.lang.String sehrcfgfile)
Initialize SEHR environment |
org.firebirdsql.jdbc.FBWrappingDataSource |
initPooledFBDS()
Init a pooled data connection |
boolean |
isPooledConnection()
Get status if a pooled datasource already in use |
static void |
main(java.lang.String[] args)
For testing purposes only... |
static java.lang.Object |
readBLOBField(SEHRCfg sehrcfg,
java.lang.String table,
java.lang.String field,
java.lang.String pkfield,
int recid)
|
static java.lang.Object |
readDataObjectFile(java.io.File f,
DesEncrypter cipher)
Reads/Loads an object from file |
void |
setCfg(SEHRCfg cfg)
Set cfg object to use for datasource initialization |
void |
setDataBase(java.lang.String dataBase)
For client usage: set database including path_to_db_file |
void |
setDBHost(java.lang.String host)
For client usage: set port of firebird engine |
void |
setDBLogin(java.lang.String login)
For client usage: set database login name |
void |
setDBPort(int port)
For client usage: set port of firebird engine |
void |
setDBPw(java.lang.String pw)
For client usage: set database login password |
void |
setSqlMap(com.ibatis.sqlmap.client.SqlMapClient sqlmap)
Set SQL mapping object. |
java.lang.String |
showProcedures()
|
static java.lang.String |
showProcedures(SEHRDataSource fbds)
|
java.lang.String |
showTables()
|
java.lang.String |
showTables(boolean showfields)
|
static java.lang.String |
showTables(SEHRDataSource fbds)
|
static java.lang.String |
showTables(SEHRDataSource fbds,
boolean showfields)
|
java.lang.String |
toString()
|
static boolean |
writeBLOBRecord(SEHRCfg sehrcfg,
java.lang.String table,
java.lang.String field,
java.lang.String pkfield,
int recid,
java.lang.Object o)
|
static boolean |
writeDataObjectFile(java.io.File file,
java.lang.Object o,
DesEncrypter cipher)
Writes an object to file |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public SEHRDataSource()
To initialize the access to the IntraSEC db use either
or initialize
manually (e.g. on clients) by using all of the following setter
methodsSEHRDataSource.init(SEHRCfg cfg)
,
SEHRDataSource.setDatabase(String),
SEHRDataSource.setDBHost(String),
SEHRDataSource.setDBPort(int),
SEHRDataSource.setDBLogin(String).SEHRDataSource.setDBPw(String)
Optional:
if using
iBatis.
SEHRDataSource.setSqlMap(SqlMapClient)
public SEHRDataSource(SEHRCfg cfg)
Note: This is the recommended way on applications running on
SEHR servers like for WEB, AXIS(SOAP). To connect/open use
connect()
public SEHRDataSource(java.lang.String host,
int port,
java.lang.String database,
java.lang.String dblogin,
java.lang.String dbpw,
java.lang.String XMLpath)
This constructor is defined for clients, where a local file access to
a SEHR configuration SEHRCfg is not available. So there are
two other ways for the client to handle the parameters for a
connection:
connect()
host - port - database - dblogin - dbpw - XMLpath - by using 'iBatis' this is the path to the SQL-XML files
public SEHRDataSource(java.lang.String host,
java.lang.String sport,
java.lang.String database,
java.lang.String dblogin,
java.lang.String dbpw,
java.lang.String XMLpath)
SEHRDataSource(String, int, String, String,
String, String)
public SEHRDataSource(java.lang.String host,
java.lang.String port,
java.lang.String database,
java.lang.String dblogin,
java.lang.String dbpw)
To connect/open use connect()
host - port - database - dblogin - dbpw - (deprecated) If we're using the db layer 'iBatis' we need XML
resources :)| Method Detail |
public void init()
The configuration holds some more informations like the XML mappings.
public void init(java.lang.String sehrcfgfile)
setCfg(SEHRCfg)public org.firebirdsql.jdbc.FBWrappingDataSource initPooledFBDS()
public java.sql.Connection connectFBDataSource()
public java.sql.Connection connectFBDataSource(java.lang.String host,
java.lang.String port,
java.lang.String database,
java.lang.String dblogin,
java.lang.String dbpw)
public java.sql.Connection connectFBDataSource(SEHRDataSource fbds,
java.lang.String host,
java.lang.String port,
java.lang.String database,
java.lang.String dblogin,
java.lang.String dbpw)
public static java.sql.Connection connectFBDataSource(SEHRDataSource fbds)
public java.sql.Connection connect()
public static java.sql.Connection connect(SEHRDataSource fbds)
This is the method finally called to connect
fbds -
public void closeFBDataSource()
throws java.sql.SQLException
java.sql.SQLException
public static void closeFBDataSource(SEHRDataSource fbds)
throws java.sql.SQLException
java.sql.SQLException
public void close()
throws java.sql.SQLException
java.sql.SQLException
public static void close(SEHRDataSource fbds)
throws java.sql.SQLException
fbds - FBDataSource object
java.sql.SQLException
public int connectToPool()
throws java.sql.SQLException
Note: Use closePooledConnection(int conidx)! Pooled
connections do have large benefits in c/s connections but there are
also some traps. One of these traps is the number and the maximum of
pooled concurrent connections. To get an overview of the number of
real connections use countPooledConnections().
To get the number of managed connections use
countExpectedPooledConnections().
To close all connections at once use closeAll()
To get established connection use
getPooledConnection(int idx)
java.sql.SQLExceptionpublic java.sql.Connection getPooledConnection(int idx)
To keep the integrity of prepared statements the pool is indexed. So you may init a connection, assign statements to it and use exactly the indexed connection to get your statementents back.
public void closeAll()
public int countPooledConnections()
public int countExpectedPooledConnections()
public boolean isPooledConnection()
public java.lang.String getRandomID()
public com.ibatis.sqlmap.client.SqlMapClient getSqlmap()
This is the recommended object for accessng the database by its SQL
objects; see example in main(String[])
public void setSqlMap(com.ibatis.sqlmap.client.SqlMapClient sqlmap)
public void setCfg(SEHRCfg cfg)
public void setDBPort(int port)
public java.lang.String getDBHost()
public void setDBHost(java.lang.String host)
public void setDataBase(java.lang.String dataBase)
public void setDBLogin(java.lang.String login)
public void setDBPw(java.lang.String pw)
public java.sql.Connection getHFBConnection()
public java.sql.Connection getHFBConnection(SEHRDataSource sds)
public static byte[] getBytesFromFile(java.io.File file)
throws java.io.IOException
This method is used to prepare an object to store as a BLOB
java.io.IOException
public static boolean writeDataObjectFile(java.io.File file,
java.lang.Object o,
DesEncrypter cipher)
public static java.lang.Object readDataObjectFile(java.io.File f,
DesEncrypter cipher)
public static java.lang.Object readBLOBField(SEHRCfg sehrcfg,
java.lang.String table,
java.lang.String field,
java.lang.String pkfield,
int recid)
public static boolean writeBLOBRecord(SEHRCfg sehrcfg,
java.lang.String table,
java.lang.String field,
java.lang.String pkfield,
int recid,
java.lang.Object o)
public java.lang.String toString()
public java.lang.String showTables()
public java.lang.String showTables(boolean showfields)
public static java.lang.String showTables(SEHRDataSource fbds)
public static java.lang.String showTables(SEHRDataSource fbds,
boolean showfields)
public java.lang.String showProcedures()
public static java.lang.String showProcedures(SEHRDataSource fbds)
public java.util.List getGenerator()
public java.util.List getGenerator(java.lang.String genid)
public static void main(java.lang.String[] args)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||