public class DBBind
extends java.beans.Beans
implements javax.sql.DataSource
Singleton object for database binding.
Modifier and Type | Class and Description |
---|---|
static class |
DBBind.Functions
Aliases for common SQL functions in different database dialects.
|
Modifier and Type | Field and Description |
---|---|
static int |
DBMS_ACCESS |
static int |
DBMS_GENERIC |
static int |
DBMS_MSSQL |
static int |
DBMS_MYSQL |
static int |
DBMS_ORACLE |
static int |
DBMS_POSTGRESQL |
static int |
DBMS_SQLITE |
Constructor and Description |
---|
DBBind()
Create DBBind.
|
DBBind(java.util.Properties oProps)
Create DBBind.
|
DBBind(java.lang.String sProfile)
Create DBBind.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close DBBind
Close connections from pool.
|
JDCConnectionPool |
connectionPool()
Get connection pool used by this database binding
|
static int |
currVal(java.sql.Connection oSQLConn,
java.lang.String sSequenceName)
Get current value for a sequence
|
static int |
currVal(JDCConnection oConn,
java.lang.String sSequenceName)
Get current value for a sequence
|
static java.lang.String |
escape(java.util.Date dt,
java.lang.String sFormat)
Format Date in ODBC escape sequence style
|
static java.lang.String |
escape(java.sql.Timestamp ts,
java.lang.String sFormat)
Format Timestamp in ODBC escape sequence style
|
static boolean |
exists(JDCConnection oConn,
java.lang.String sObjectName,
java.lang.String sObjectType)
Checks if an object exists at database
Checking is done directly against database catalog tables,
if current user does not have enought priviledges for reading
database catalog tables methos may fail or return a wrong result.
|
java.sql.Connection |
getConnection()
Get a Connection instance from connection pool
|
JDCConnection |
getConnection(java.lang.String sCaller)
Get a
JDCConnection instance from connection pool |
JDCConnection |
getConnection(java.lang.String sCaller,
boolean bReadOnly)
Get a
JDCConnection instance from connection pool |
java.sql.Connection |
getConnection(java.lang.String sUser,
java.lang.String sPasswd)
Get a Connection instance directly from the database bypassing the pool
|
java.lang.String |
getDatabaseProductName()
Get the name of Database Management System Connected
|
static java.lang.String |
getDataModelVersion(JDCConnection oConn)
Get datamodel version
|
static int |
getDataModelVersionNumber(JDCConnection oConn)
Get datamodel version number
|
DBTable |
getDBTable(java.lang.String sTable)
Get
DBTable object by name |
java.util.HashMap |
getDBTablesMap()
Get map of
DBTable objects |
int |
getLoginTimeout()
Get login timeout from java.sql.DriverManager
|
java.io.PrintWriter |
getLogWriter()
Get LogWriter from java.sql.DriverManager
|
java.util.logging.Logger |
getParentLogger()
This method is added for compatibility with Java 7 and it is not iplemented
|
java.lang.String |
getProfileName()
Get Name of profile used for initializing DBBind
Profile Name is the properties file name ("hipergate.cnf") without extension.
|
java.util.Properties |
getProperties()
Get properties from the .CNF file for this DBBind.
|
java.lang.String |
getProperty(java.lang.String sVarName)
Get a single property from the .CNF file for this DBBind.
|
java.lang.String |
getProperty(java.lang.String sVarName,
java.lang.String sDefault)
Get a single property from the .CNF file for this DBBind.
|
boolean |
getPropertyBool(java.lang.String sVarName,
boolean bDefault)
Get a boolean property from the .CNF file for this DBBind.
|
java.lang.String |
getPropertyPath(java.lang.String sVarName)
Get a property representing a file path from the .CNF file for this DBBind.
|
static DBTable |
getTable(java.lang.String sTable)
Deprecated.
Use
getDBTable instead |
static long |
getTime() |
boolean |
isWrapperFor(java.lang.Class c) |
static int |
nextVal(java.sql.Connection oSQLConn,
java.lang.String sSequenceName)
Get next value for a sequence
|
static int |
nextVal(JDCConnection oConn,
java.lang.String sSequenceName)
Get next value for a sequence
|
void |
restart()
Close and reopen the connection pool and reload the table map cache
|
void |
setLoginTimeout(int seconds)
Set login timeout for java.sql.DriverManager
|
void |
setLogWriter(java.io.PrintWriter printwrt)
Set LogWriter for java.sql.DriverManager
|
java.lang.String |
toXml()
Dump table definitions as a database independent XML file
|
java.lang.Object |
unwrap(java.lang.Class c) |
public static final int DBMS_GENERIC
public static final int DBMS_MYSQL
public static final int DBMS_POSTGRESQL
public static final int DBMS_MSSQL
public static final int DBMS_ORACLE
public static final int DBMS_ACCESS
public static final int DBMS_SQLITE
public DBBind()
Create DBBind.
Read database connection properties from hipergate.cnf.public DBBind(java.util.Properties oProps)
Create DBBind.
Read database connection properties from specified properties file.Properties
- public DBBind(java.lang.String sProfile)
Create DBBind.
Read database connection properties from specified properties file.sProfile
- Name of properties file without extension.public void close()
Close DBBind
Close connections from pool.public void restart() throws java.sql.SQLException, java.lang.ClassNotFoundException
java.sql.SQLException
java.lang.ClassNotFoundException
public JDCConnectionPool connectionPool()
public java.lang.String getDatabaseProductName() throws java.sql.SQLException
java.sql.SQLException
public java.lang.String getProfileName()
Get Name of profile used for initializing DBBind
Profile Name is the properties file name ("hipergate.cnf") without extension.public java.util.Properties getProperties()
Get properties from the .CNF file for this DBBind.
public java.lang.String getProperty(java.lang.String sVarName)
Get a single property from the .CNF file for this DBBind.
sVarName
- Property Namepublic java.lang.String getProperty(java.lang.String sVarName, java.lang.String sDefault)
Get a single property from the .CNF file for this DBBind.
sVarName
- Property NamesDefault
- Default Valuepublic boolean getPropertyBool(java.lang.String sVarName, boolean bDefault)
Get a boolean property from the .CNF file for this DBBind.
sVarName
- Property NamebDefault
- Default Valuepublic java.lang.String getPropertyPath(java.lang.String sVarName)
Get a property representing a file path from the .CNF file for this DBBind.
sVarName
- Property Namepublic static boolean exists(JDCConnection oConn, java.lang.String sObjectName, java.lang.String sObjectType) throws java.sql.SQLException, java.lang.UnsupportedOperationException
oConn
- Database connectionsObjectName
- Objeto namesObjectType
- Objeto type
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
L = Log
P = Stored procedure
PK = PRIMARY KEY constraint (type is K)
RF = Replication filter stored procedure
S = System table
TR = Trigger
U = User table
UQ = UNIQUE constraint (type is K)
V = View
X = Extended stored procedurejava.sql.SQLException
java.lang.UnsupportedOperationException
- If current database management system is not supported for this methodpublic static java.lang.String getDataModelVersion(JDCConnection oConn) throws java.sql.SQLException
oConn
- JDCConnection objectjava.sql.SQLException
public static int getDataModelVersionNumber(JDCConnection oConn) throws java.sql.SQLException
oConn
- JDCConnection objectjava.sql.SQLException
public static int currVal(JDCConnection oConn, java.lang.String sSequenceName) throws java.sql.SQLException, java.lang.UnsupportedOperationException
Get current value for a sequence
oConn
- JDCConnectionsSequenceName
- Sequence name.
In MySQL and SQL Server sequences are implemented using row locks at k_sequences table.java.sql.SQLException
java.lang.UnsupportedOperationException
- Not all databases support sequences.
On Oracle and PostgreSQL, native SEQUENCE objects are used,
on MySQL and Microsoft SQL Server the stored procedure k_sp_currval simulates sequences,
this function is not supported on other DataBase Management Systems.public static int currVal(java.sql.Connection oSQLConn, java.lang.String sSequenceName) throws java.sql.SQLException, java.lang.UnsupportedOperationException
Get current value for a sequence
oSQLConn
- Database connectionsSequenceName
- Sequence name.
In MySQL and SQL Server sequences are implemented using row locks at k_sequences table.java.sql.SQLException
java.lang.UnsupportedOperationException
- Not all databases support sequences.
On Oracle and PostgreSQL, native SEQUENCE objects are used,
on MySQL and Microsoft SQL Server the stored procedure k_sp_nextval simulates sequences,
this function is not supported on other DataBase Management Systems.public static int nextVal(JDCConnection oConn, java.lang.String sSequenceName) throws java.sql.SQLException, java.lang.UnsupportedOperationException
Get next value for a sequence
oConn
- JDCConnectionsSequenceName
- Sequence name.
In MySQL and SQL Server sequences are implemented using row locks at k_sequences table.java.sql.SQLException
java.lang.UnsupportedOperationException
- Not all databases support sequences.
On Oracle and PostgreSQL, native SEQUENCE objects are used,
on Microsoft SQL Server the stored procedure k_sp_nextval simulates sequences,
this function is not supported on other DataBase Management Systems.public static int nextVal(java.sql.Connection oSQLConn, java.lang.String sSequenceName) throws java.sql.SQLException, java.lang.UnsupportedOperationException
Get next value for a sequence
oSQLConn
- Database connectionsSequenceName
- Sequence name.
In MySQL and SQL Server sequences are implemented using row locks at k_sequences table.java.sql.SQLException
java.lang.UnsupportedOperationException
- Not all databases support sequences.
On Oracle and PostgreSQL, native SEQUENCE objects are used,
on Microsoft SQL Server the stored procedure k_sp_nextval simulates sequences,
this function is not supported on other DataBase Management Systems.public static java.lang.String escape(java.util.Date dt, java.lang.String sFormat) throws java.lang.IllegalArgumentException
dt
- Date to be formatedsFormat
- Format Type "d" or "ts" or "shortTime".
Use d for { d 'yyyy-mm-dd' }, use ts for { ts 'ts=yyyy-mm-dd hh:nn:ss' }java.lang.IllegalArgumentException
- if dt is of type java.sql.Datepublic static java.lang.String escape(java.sql.Timestamp ts, java.lang.String sFormat)
ts
- Timestamp to be formatedsFormat
- Format Type "d" or "ts" or "shortTime".
Use d for { d 'yyyy-mm-dd' }, use ts for { ts 'ts=yyyy-mm-dd hh:nn:ss' }public static DBTable getTable(java.lang.String sTable) throws java.lang.IllegalStateException
getDBTable
insteadGet DBTable
object by name
sTable
- Table namejava.lang.IllegalStateException
- DBTable objects are cached in a static HasMap,
the HashMap is loaded upon first call to a DBBind constructor. If getTable()
is called before creating any instance of DBBind an IllegalStateException
will be raised.public DBTable getDBTable(java.lang.String sTable) throws java.lang.IllegalStateException
Get DBTable
object by name
sTable
- Table namejava.lang.IllegalStateException
- DBTable objects are cached in a static HasMap,
the HashMap is loaded upon first call to a DBBind constructor.
If getDBTable() is called before creating any instance of DBBind then an
IllegalStateException will be thrown.public java.util.HashMap getDBTablesMap() throws java.lang.IllegalStateException
Get map of DBTable
objects
java.lang.IllegalStateException
- DBTable objects are cached in a static HasMap,
the HashMap is loaded upon first call to a DBBind constructor.
If getDBTablesMap() is called before creating any instance of DBBind
then an IllegalStateException will be thrown.public JDCConnection getConnection(java.lang.String sCaller) throws java.sql.SQLException
Get a JDCConnection
instance from connection pool
sCaller
- Symbolic name identifying the caller program or subroutine,
this field is used for statistical control of database accesses,
performance tunning and debugging open/close mismatch.java.sql.SQLException
public JDCConnection getConnection(java.lang.String sCaller, boolean bReadOnly) throws java.sql.SQLException
Get a JDCConnection
instance from connection pool
sCaller
- Symbolic name identifying the caller program or subroutine,
this field is used for statistical control of database accesses,
performance tunning and debugging open/close mismatch.bReadOnly
- true if connection must be put into read-only mode,
false otherwisejava.sql.SQLException
public java.sql.Connection getConnection() throws java.sql.SQLException
Get a Connection instance from connection pool
getConnection
in interface javax.sql.DataSource
sCaller
- Symbolic name identifying the caller program or subroutine,
this field is used for statistical control of database accesses,
performance tunning and debugging open/close mismatch.java.sql.SQLException
public java.sql.Connection getConnection(java.lang.String sUser, java.lang.String sPasswd) throws java.sql.SQLException
Get a Connection instance directly from the database bypassing the pool
getConnection
in interface javax.sql.DataSource
sUser
- User namesPasswd
- Passwordjava.sql.SQLException
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
getLogWriter
in interface javax.sql.CommonDataSource
java.sql.SQLException
public void setLogWriter(java.io.PrintWriter printwrt) throws java.sql.SQLException
setLogWriter
in interface javax.sql.CommonDataSource
java.sql.SQLException
public int getLoginTimeout() throws java.sql.SQLException
getLoginTimeout
in interface javax.sql.CommonDataSource
java.sql.SQLException
public void setLoginTimeout(int seconds) throws java.sql.SQLException
setLoginTimeout
in interface javax.sql.CommonDataSource
java.sql.SQLException
public boolean isWrapperFor(java.lang.Class c)
isWrapperFor
in interface java.sql.Wrapper
public java.lang.Object unwrap(java.lang.Class c)
unwrap
in interface java.sql.Wrapper
public static long getTime()
public java.util.logging.Logger getParentLogger()
getParentLogger
in interface javax.sql.CommonDataSource
public java.lang.String toXml()