kotkabeans
Class DB

java.lang.Object
  |
  +--kotkabeans.DB
Direct Known Subclasses:
AddUserToCourse, UserToGroup

public class DB
extends java.lang.Object

provides a connection to the Kotka database to the other beans.


Field Summary
protected  java.text.DateFormat df
          Field is used to format timestamp output to log-file.
protected  java.sql.Connection myconn
          Stores used database connection.
protected  java.sql.Statement stmt
          Used to carry out database operations.
protected  boolean transaction
          Set to true if transaction has been started.
 
Constructor Summary
DB()
           
 
Method Summary
 void abortTransaction()
          Flushes transaction-buffer without executing commands.
 void beginTransaction()
          Starts collecting SQL-commands to buffer, which are executed later as a single block.
 void connect()
          Requests connection to the Kotka-database.
 void disconnect()
          Releases used connection.
 void endTransaction()
          Executes SQL-commands from buffer created by beginTransaction()-method.
 java.sql.ResultSet executeQuery(java.lang.String sqlSentence)
          Executes SQL-query and establishes connection if needed.
 int executeUpdate(java.lang.String sqlSentence)
          Executes SQL-update and registeres it to the log file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myconn

protected java.sql.Connection myconn
Stores used database connection. if null, connect()-method is called when one tries to use database-oriented methods.
See Also:
connect()

stmt

protected java.sql.Statement stmt
Used to carry out database operations. Initialized during connect()-method.
See Also:
connect()

df

protected java.text.DateFormat df
Field is used to format timestamp output to log-file.

transaction

protected boolean transaction
Set to true if transaction has been started. Othervise false
Constructor Detail

DB

public DB()
Method Detail

connect

public void connect()
             throws java.lang.Exception
Requests connection to the Kotka-database. Connections are handled by Poolman. Sets internal variables.

disconnect

public void disconnect()
                throws java.lang.Exception
Releases used connection.

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sqlSentence)
                                throws java.lang.Exception
Executes SQL-query and establishes connection if needed.
Parameters:
sqlSentence - SQL-query to execute
Returns:
ResultSet containing matching lines

executeUpdate

public int executeUpdate(java.lang.String sqlSentence)
                  throws java.lang.Exception
Executes SQL-update and registeres it to the log file. New connection is requested if no one exists allready.
Parameters:
sqlSentence - SQL-update to execute

beginTransaction

public void beginTransaction()
                      throws java.lang.Exception
Starts collecting SQL-commands to buffer, which are executed later as a single block. Method does nothing if there is allready an active transaction.

endTransaction

public void endTransaction()
                    throws java.lang.Exception
Executes SQL-commands from buffer created by beginTransaction()-method. If there is no active transaction, method does nothing.
See Also:
beginTransaction()

abortTransaction

public void abortTransaction()
                      throws java.lang.Exception
Flushes transaction-buffer without executing commands. If there is no active transaction, method does nothing.
See Also:
beginTransaction()