www.element4solution.com

e4s.db
Class E4DBConnectionDefault

java.lang.Object
  extended by e4s.util.E4Object
      extended by e4s.db.E4DBConnectionDefault
All Implemented Interfaces:
E4DBConnection_Intf
Direct Known Subclasses:
E4DBConnectionTransactional

public class E4DBConnectionDefault
extends E4Object
implements E4DBConnection_Intf

This is the main class that connects the application with the database, each statement will be executed in single statement transaction (SST) mode and commit/rollback is not possible. You can use the #E4DBConnectionDefault() function to create a new connection, using the default JDBC connection string and database (which is defined in the E4DBSettings) but if a connection was already created for this database, then this connection will be used. This is the reason, why commit/rollback won't work as they would influence all connections used. Never close this connection until your application will be terminated.

Since:
JDK 1.4
See Also:
E4DBSettings, E4DBConnectionTransactional

Field Summary
static int _DB_TYPE_DB2
          Value for getDatabaseType() when running DB2 on AS/400.
static int _DB_TYPE_MS_ACCESS
          Value for getDatabaseType() when running MS-ACCESS.
static int _DB_TYPE_MY_SQL
          Value for getDatabaseType() when running My-SQL.
static int _DB_TYPE_OTHER
          Value for getDatabaseType() when database is different than the known databases here.
static int _DB_TYPE_SQL_SERVER
          Value for getDatabaseType() when running SQL-Server.
static java.lang.String JDBCDRIVER_MS
          Common used JDBC driver for Microsoft, used for e.g.
static java.lang.String JDBCDRIVER_OPTA
          Well established JDBC driver (often used in E4S projects) for MS-SQL and other databases.
static java.lang.String JDBCDRIVER_SUN
          Common used JDBC driver for Sun Microsystems, used for e.g.
protected  java.sql.Connection m_Connection
           
protected  boolean m_Connection_pooled
           
protected static boolean m_logging_checked
           
protected static AEP_JDBC_Connection_Intf ms_aep_connection
           
protected static java.util.Hashtable ms_cached_connections
          This is a list of connections, each identified by driver, connection, user and password
protected static int ms_connection_counter
           
protected static int ms_connection_counter_max
           
protected static java.lang.String ms_JDBC_CONNECTION
           
protected static int ms_JDBC_DATABASE_TYPE
           
protected static java.lang.String ms_JDBC_DRIVER
           
 
Fields inherited from class e4s.util.E4Object
CRLF, E4S_CORE_SYSTEM_LANGUAGE, NBSP, NULLSTR, URL_ENCODING_CHARSET
 
Constructor Summary
  E4DBConnectionDefault(java.sql.Connection con, int dbtype)
           
protected E4DBConnectionDefault(java.sql.Connection con, java.lang.String monitorstring, int dbtype)
           
  E4DBConnectionDefault(E4DBConnectionDefault con)
           
protected E4DBConnectionDefault(int dbtype)
           
  E4DBConnectionDefault(java.lang.String driver_name, java.lang.String connection_name, int dbtype)
           
  E4DBConnectionDefault(java.lang.String driver_name, java.lang.String connection_name, java.lang.String userid, java.lang.String password, int dbtype)
           
 
Method Summary
static java.lang.String _getSVNVersionString()
          Get version info string from subversion.
 void close()
           
 boolean connectionIsPooled()
          Get the pooling mode for the JDBC driver.
 void finalize()
           
 java.lang.String getCatalog()
          Get the catalog.
 java.sql.Connection getConnection()
          Get the underlaying JDBC database connection.
static java.sql.Connection[] getConnectionCache()
          Get an array of connections cached.
static int getConnectionCounter()
           
 java.util.Date getCreated()
           
 java.sql.DatabaseMetaData getDatabaseMetaData()
          Get the database meta data.
 int getDatabaseType()
          Hold information about the database type.
static E4DBConnectionDefault getDefaultConnection()
           
 java.lang.String getID()
           
 java.util.Vector getIndexes(E4DBTableName tablename)
          Retrieve all index names out of the current database connection for the specified table.
static E4DBConnection_Intf getInstance()
           
static java.lang.String getJdbcConnection()
          Get the name of the JDBC connection.
static java.lang.String getJdbcDriver()
           
 E4DBStatement getStatement()
          Create a new JDBC/SQL Statement.
 java.util.Vector getTables()
          Retrieve all tables out of the current database connection.
 java.util.Vector getViews()
          Retrieve all tables out of the current database connection.
protected  void init(java.lang.String driver_name, java.lang.String connection_name, java.lang.String userid, java.lang.String password, boolean transaction)
           
protected  void initLogging()
           
protected  void initMONITOR(java.lang.String flag)
           
protected  void initPool(java.lang.String driver_name, java.lang.String connection_name, java.lang.String userid, java.lang.String password, boolean transaction)
           
protected  void initShared(java.lang.String driver_name, java.lang.String connection_name, java.lang.String userid, java.lang.String password, boolean transaction)
           
 boolean istabledefined(E4DBTableName check_tablename)
          Check for existance of a table
static void resetConnectionCache()
           
static void setAEP(AEP_JDBC_Connection_Intf aep_connection)
          Set the object to trigger the connection.
 void setConnection(java.sql.Connection con)
          Set the underlaying JDBC database connection, not recommended.
 void setConnection(E4DBConnectionDefault con)
          Set the underlaying JDBC database connection, not recommended.
 void setDatabaseType(int dbtype)
          Defines information about the database type.
static void setJdbcConnection(java.lang.String connection)
          Set the name of the JDBC connection.
static void setJdbcDatabaseType(int dbtype)
           
static void setJdbcDriver(java.lang.String driver)
           
 java.lang.String toString()
           
 
Methods inherited from class e4s.util.E4Object
Calendar, CName, CName, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelApp, E4LabelNone, E4LabelNone, E4LabelNone, E4LabelNone, E4LabelSys, E4LabelSys, e4sCopyright, e4sVersion, encode, encode, encode, encodeHtml, encodeHtml, encodeHtml, encodeURL, encodeURL, encodeURL, getLINE, getTRACE, getTRACE, getTRACE, getTRACE, getTRACE, getTRACE, getTraceMemory, HtmlEncode, HtmlEncode, HtmlEncode, isdecimal, isdigit, isnotok, isnotok, isnumeric, isok, isok, isok, isok, lastCallingFunction, lastCallingFunction, lastCallingFunction, lastCallingFunction, lastCallingStack, mkdirs, null2nbsp, null2nbsp, null2nbsp, ok, ok, ok, ok, outPrintln, setLogFile4Trace, setTraceMemory, STACKTRACE, toDebug, toDouble, toFloat, toFloat, TRACE_CALLS, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, TRACE, wait
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Connection

protected volatile java.sql.Connection m_Connection

m_Connection_pooled

protected boolean m_Connection_pooled

ms_connection_counter

protected static int ms_connection_counter

ms_connection_counter_max

protected static int ms_connection_counter_max

ms_aep_connection

protected static AEP_JDBC_Connection_Intf ms_aep_connection

ms_cached_connections

protected static java.util.Hashtable ms_cached_connections
This is a list of connections, each identified by driver, connection, user and password


m_logging_checked

protected static boolean m_logging_checked

_DB_TYPE_SQL_SERVER

public static int _DB_TYPE_SQL_SERVER
Value for getDatabaseType() when running SQL-Server.

See Also:
getDatabaseType(), setDatabaseType(int)

_DB_TYPE_MY_SQL

public static int _DB_TYPE_MY_SQL
Value for getDatabaseType() when running My-SQL.

See Also:
getDatabaseType(), setDatabaseType(int)

_DB_TYPE_MS_ACCESS

public static int _DB_TYPE_MS_ACCESS
Value for getDatabaseType() when running MS-ACCESS.

See Also:
getDatabaseType(), setDatabaseType(int)

_DB_TYPE_DB2

public static int _DB_TYPE_DB2
Value for getDatabaseType() when running DB2 on AS/400.

See Also:
getDatabaseType(), setDatabaseType(int)

_DB_TYPE_OTHER

public static int _DB_TYPE_OTHER
Value for getDatabaseType() when database is different than the known databases here.

See Also:
getDatabaseType(), setDatabaseType(int)

JDBCDRIVER_MS

public static final java.lang.String JDBCDRIVER_MS
Common used JDBC driver for Microsoft, used for e.g. MS-ACCESS databases when running the local Java VM in the browser (client).

See Also:
Constant Field Values

JDBCDRIVER_SUN

public static final java.lang.String JDBCDRIVER_SUN
Common used JDBC driver for Sun Microsystems, used for e.g. MS-ACCESS databases when running the local Sun-Java plugin in the browser (client).

See Also:
Constant Field Values

JDBCDRIVER_OPTA

public static final java.lang.String JDBCDRIVER_OPTA
Well established JDBC driver (often used in E4S projects) for MS-SQL and other databases. Refer to http://www.inetsoftware.de for more details.

See Also:
Constant Field Values

ms_JDBC_DRIVER

protected static java.lang.String ms_JDBC_DRIVER

ms_JDBC_CONNECTION

protected static java.lang.String ms_JDBC_CONNECTION

ms_JDBC_DATABASE_TYPE

protected static int ms_JDBC_DATABASE_TYPE
Constructor Detail

E4DBConnectionDefault

protected E4DBConnectionDefault(int dbtype)

E4DBConnectionDefault

public E4DBConnectionDefault(java.sql.Connection con,
                             int dbtype)

E4DBConnectionDefault

protected E4DBConnectionDefault(java.sql.Connection con,
                                java.lang.String monitorstring,
                                int dbtype)

E4DBConnectionDefault

public E4DBConnectionDefault(E4DBConnectionDefault con)

E4DBConnectionDefault

public E4DBConnectionDefault(java.lang.String driver_name,
                             java.lang.String connection_name,
                             java.lang.String userid,
                             java.lang.String password,
                             int dbtype)
                      throws E4DBException
Throws:
E4DBException

E4DBConnectionDefault

public E4DBConnectionDefault(java.lang.String driver_name,
                             java.lang.String connection_name,
                             int dbtype)
                      throws E4DBException
Throws:
E4DBException
Method Detail

initMONITOR

protected void initMONITOR(java.lang.String flag)

getInstance

public static E4DBConnection_Intf getInstance()
                                       throws E4DBException
Throws:
E4DBException

getDefaultConnection

public static E4DBConnectionDefault getDefaultConnection()
                                                  throws E4DBException
Throws:
E4DBException

init

protected void init(java.lang.String driver_name,
                    java.lang.String connection_name,
                    java.lang.String userid,
                    java.lang.String password,
                    boolean transaction)
             throws E4DBException
Throws:
E4DBException

initShared

protected void initShared(java.lang.String driver_name,
                          java.lang.String connection_name,
                          java.lang.String userid,
                          java.lang.String password,
                          boolean transaction)
                   throws E4DBException
Throws:
E4DBException

initPool

protected void initPool(java.lang.String driver_name,
                        java.lang.String connection_name,
                        java.lang.String userid,
                        java.lang.String password,
                        boolean transaction)
                 throws E4DBException
Throws:
E4DBException

initLogging

protected void initLogging()

getStatement

public E4DBStatement getStatement()
                           throws E4DBException
Create a new JDBC/SQL Statement.

Specified by:
getStatement in interface E4DBConnection_Intf
Returns:
the new created Statement, associated with this current connection.
Throws:
E4DBException

getDatabaseMetaData

public java.sql.DatabaseMetaData getDatabaseMetaData()
                                              throws E4DBException
Get the database meta data.

Specified by:
getDatabaseMetaData in interface E4DBConnection_Intf
Returns:
the metadata information
Throws:
E4DBException

getIndexes

public java.util.Vector getIndexes(E4DBTableName tablename)
                            throws E4DBException
Retrieve all index names out of the current database connection for the specified table.

Specified by:
getIndexes in interface E4DBConnection_Intf
Parameters:
tablename - the table to lookup
Returns:
a Vector of elements of type String
Throws:
E4DBException

getTables

public java.util.Vector getTables()
                           throws E4DBException
Retrieve all tables out of the current database connection.

Specified by:
getTables in interface E4DBConnection_Intf
Returns:
a Vector of elements of type e4s.db.dict
Throws:
E4DBException
See Also:
E4DBTableName, istabledefined(e4s.db.E4DBTableName)

getViews

public java.util.Vector getViews()
                          throws E4DBException
Retrieve all tables out of the current database connection.

Returns:
a Vector of elements of type e4s.db.dict
Throws:
E4DBException
See Also:
E4DBTableName, istabledefined(e4s.db.E4DBTableName)

istabledefined

public boolean istabledefined(E4DBTableName check_tablename)
                       throws E4DBException
Check for existance of a table

Specified by:
istabledefined in interface E4DBConnection_Intf
Parameters:
check_tablename - the table who's existance to be prooven
Returns:
true, if the table exists
Throws:
E4DBException
See Also:
E4DBTableName, getTables()

getJdbcDriver

public static java.lang.String getJdbcDriver()

setJdbcDriver

public static void setJdbcDriver(java.lang.String driver)
                          throws java.lang.Exception
Throws:
java.lang.Exception

setJdbcDatabaseType

public static void setJdbcDatabaseType(int dbtype)
                                throws java.lang.Exception
Throws:
java.lang.Exception

getJdbcConnection

public static java.lang.String getJdbcConnection()
Get the name of the JDBC connection.

See Also:
setJdbcConnection(java.lang.String), getJdbcDriver(), E4DBSettings.getJdbcConnection(boolean)

setJdbcConnection

public static void setJdbcConnection(java.lang.String connection)
Set the name of the JDBC connection. Does not store the value in the database settings E4DBSettings.

See Also:
getJdbcConnection(), setJdbcDriver(java.lang.String)

getDatabaseType

public int getDatabaseType()
Hold information about the database type.

Specified by:
getDatabaseType in interface E4DBConnection_Intf
Returns:
_DB_TYPE_SQL_SERVER, _DB_TYPE_MY_SQL, _DB_TYPE_MS_ACCESS
See Also:
_DB_TYPE_SQL_SERVER, _DB_TYPE_MY_SQL, _DB_TYPE_MS_ACCESS, setDatabaseType(int)

setDatabaseType

public void setDatabaseType(int dbtype)
Defines information about the database type.

Parameters:
dbtype - one of _DB_TYPE_SQL_SERVER, _DB_TYPE_MY_SQL, _DB_TYPE_MS_ACCESS
See Also:
_DB_TYPE_SQL_SERVER, _DB_TYPE_MY_SQL, _DB_TYPE_MS_ACCESS, getDatabaseType(), E4DBSettings.getDatabaseType()

getConnectionCounter

public static int getConnectionCounter()

getConnection

public java.sql.Connection getConnection()
Get the underlaying JDBC database connection.


setConnection

public void setConnection(java.sql.Connection con)
Set the underlaying JDBC database connection, not recommended.

See Also:
getConnection(), setConnection(e4s.db.E4DBConnectionDefault)

setConnection

public void setConnection(E4DBConnectionDefault con)
Set the underlaying JDBC database connection, not recommended.

See Also:
getConnection()

resetConnectionCache

public static void resetConnectionCache()

setAEP

public static void setAEP(AEP_JDBC_Connection_Intf aep_connection)
Set the object to trigger the connection.


getConnectionCache

public static java.sql.Connection[] getConnectionCache()
Get an array of connections cached.

Returns:
null, if no connection are cached so far.

connectionIsPooled

public boolean connectionIsPooled()
Get the pooling mode for the JDBC driver.

Specified by:
connectionIsPooled in interface E4DBConnection_Intf
See Also:
E4DBSettings.getPoolingEnabled(java.lang.String)

close

public void close()
           throws E4DBException
Specified by:
close in interface E4DBConnection_Intf
Throws:
E4DBException

finalize

public void finalize()
Overrides:
finalize in class E4Object

toString

public java.lang.String toString()
Overrides:
toString in class E4Object

getCatalog

public java.lang.String getCatalog()
                            throws E4DBException
Get the catalog.

Specified by:
getCatalog in interface E4DBConnection_Intf
Returns:
the catalog
Throws:
E4DBException

getCreated

public java.util.Date getCreated()

_getSVNVersionString

public static java.lang.String _getSVNVersionString()
Get version info string from subversion.

Returns:
the version info string.
See Also:
E4Util.getRevisionCodeFromSVN(Class)

getID

public java.lang.String getID()
Specified by:
getID in interface E4DBConnection_Intf

www.element4solution.com