ch.agent.crnickl.jdbc
Class JDBCSession

java.lang.Object
  extended by ch.agent.crnickl.jdbc.JDBCSession

public class JDBCSession
extends Object

JDBCSession is a singleton keeping track of the JDBC connection.

Version:
1.0.0
Author:
Jean-Paul Vetterli

Field Summary
static String JDBC_DB
           
static String JDBC_DRIVER
           
static String JDBC_PASSWORD
           
static String JDBC_URL
           
static String JDBC_USER
           
 
Constructor Summary
JDBCSession(ch.agent.crnickl.api.DatabaseConfiguration configuration)
          Construct a JDBC session.
 
Method Summary
 void close(boolean ignoreException)
          Close the JDBC connection if it is open.
 void commit()
          Commit the current transaction.
 Connection getConnection()
          Return the JDBC connection.
static JDBCSession getInstance()
          Return the JDBC session.
 String getURL()
          Return the URL of the session.
 String getUser()
          Return the user id of the session.
 void rollback()
          Rollback the current transaction.
static void rollbackIfAlive()
          Perform a rollback if there is a session, else do nothing.
 String toString()
          Return a string displaying the session with the URL and the user id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JDBC_DRIVER

public static final String JDBC_DRIVER
See Also:
Constant Field Values

JDBC_URL

public static final String JDBC_URL
See Also:
Constant Field Values

JDBC_DB

public static final String JDBC_DB
See Also:
Constant Field Values

JDBC_USER

public static final String JDBC_USER
See Also:
Constant Field Values

JDBC_PASSWORD

public static final String JDBC_PASSWORD
See Also:
Constant Field Values
Constructor Detail

JDBCSession

public JDBCSession(ch.agent.crnickl.api.DatabaseConfiguration configuration)
Construct a JDBC session. This constructor can be invoked only once.

Parameters:
configuration - a database configuration
Method Detail

getInstance

public static JDBCSession getInstance()
Return the JDBC session.

Returns:
the JDBC session

rollbackIfAlive

public static void rollbackIfAlive()
Perform a rollback if there is a session, else do nothing. Catch and discard any exception.


close

public void close(boolean ignoreException)
           throws ch.agent.crnickl.T2DBException
Close the JDBC connection if it is open.

Throws:
ch.agent.crnickl.T2DBException

getConnection

public Connection getConnection()
                         throws ch.agent.crnickl.T2DBException
Return the JDBC connection. If there is no connection, open one.

Returns:
a JDBC connection
Throws:
ch.agent.crnickl.T2DBException

commit

public void commit()
            throws ch.agent.crnickl.T2DBException
Commit the current transaction.

Throws:
ch.agent.crnickl.T2DBException

rollback

public void rollback()
              throws ch.agent.crnickl.T2DBException
Rollback the current transaction.

Throws:
ch.agent.crnickl.T2DBException

getURL

public String getURL()
Return the URL of the session.

Returns:
the URL

getUser

public String getUser()
Return the user id of the session.

Returns:
the user id

toString

public String toString()
Return a string displaying the session with the URL and the user id.

Overrides:
toString in class Object
Returns:
a string displaying the session


Copyright © 2012. All Rights Reserved.