kotkabeans
Class DB

java.lang.Object
  |
  +--kotkabeans.DB
Direct Known Subclasses:
PreparedDB, SaveInfo

public class DB
extends java.lang.Object

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


Field Summary
protected  int concurType
           
protected  java.util.Date connecttime
           
protected  java.lang.String createStack
           
static boolean doLog
           
protected static int driverLoaded
           
protected static int laskuri
           
protected  java.lang.String lastSQL
           
protected  Log.NamedLog logConn
           
protected  Log.NamedLog logConnMid
           
protected  Log.NamedLog logQuery
           
protected  java.sql.Connection myconn
          Stores used database connection. if null, connect()-method is called when one tries to use database-oriented methods.
protected  int scrollType
           
protected  java.sql.Statement stmt
          Used to carry out database operations.
protected  boolean transaction
          Set to true if transaction has been started.
protected  int transactionIsolationLevel
           
 
Constructor Summary
DB()
           
DB(java.lang.String cname)
           
 
Method Summary
 void abortTransaction()
          Flushes transaction-buffer without executing commands.
 void addBatch(java.lang.String sqlSentence)
           
 void beginTransaction()
          Starts collecting SQL-commands to buffer, which are executed later as a single block.
 void connect()
          Requests connection to the Kotka-database.
static int connectionCount()
           
protected  void decConn()
           
 void disconnect()
          Releases used connection.
 void elog(Log.NamedLog logger, java.lang.String method, java.lang.String sentence)
           
 void elog(java.lang.String method, java.lang.String sentence)
           
 void endTransaction()
          Executes SQL-commands from buffer created by beginTransaction()-method.
 int[] executeBatch()
           
 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.
protected  void finalize()
           
static int getID()
           
 java.sql.DatabaseMetaData getMetaData()
           
 int getTransactionIsolationLevel()
           
protected  void incConn()
           
 boolean isConnected()
           
protected  java.sql.Connection loadDriver(int connectionType)
          Loads database driver and establishes connection to database
 void log(Log.NamedLog logger, java.lang.String sentence)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
          Prepares statment with parameters marked as ?
 void setConcurType(int newType)
           
 void setScrollType(int newType)
           
 void setTransactionIsolationLevel(int level)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

laskuri

protected static int laskuri

driverLoaded

protected static int driverLoaded

connecttime

protected java.util.Date connecttime

lastSQL

protected java.lang.String lastSQL

createStack

protected java.lang.String createStack

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()

transaction

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


transactionIsolationLevel

protected int transactionIsolationLevel

scrollType

protected int scrollType

concurType

protected int concurType

logQuery

protected Log.NamedLog logQuery

logConn

protected Log.NamedLog logConn

logConnMid

protected Log.NamedLog logConnMid

doLog

public static boolean doLog
Constructor Detail

DB

public DB()

DB

public DB(java.lang.String cname)
Method Detail

incConn

protected void incConn()

decConn

protected void decConn()

isConnected

public boolean isConnected()

setScrollType

public void setScrollType(int newType)

setConcurType

public void setConcurType(int newType)

log

public void log(Log.NamedLog logger,
                java.lang.String sentence)

elog

public void elog(java.lang.String method,
                 java.lang.String sentence)

elog

public void elog(Log.NamedLog logger,
                 java.lang.String method,
                 java.lang.String sentence)

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.lang.Exception
Prepares statment with parameters marked as ? Example: select * from person where personid = ?

Returns:
prepared statement based on sql input
java.lang.Exception

loadDriver

protected java.sql.Connection loadDriver(int connectionType)
                                  throws java.lang.Exception
Loads database driver and establishes connection to database

Parameters:
connectionType - 1 = Connection with PoolMan 2 = Connection without PoolMan 3 = Connection with JDBC-ODBC Bridge
Returns:
established connection to database
java.lang.Exception

connect

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

Throws:
java.lang.Exception

disconnect

public void disconnect()
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
Throws:
java.lang.Exception

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
Returns:
return value from stmt.executeUpdate
Throws:
java.lang.Exception

addBatch

public void addBatch(java.lang.String sqlSentence)
              throws java.lang.Exception
java.lang.Exception

executeBatch

public int[] executeBatch()
                   throws java.lang.Exception
java.lang.Exception

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.

Throws:
java.lang.Exception

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.

Throws:
java.lang.Exception
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.

Throws:
java.lang.Exception
See Also:
beginTransaction()

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.lang.Exception
java.lang.Exception

getTransactionIsolationLevel

public int getTransactionIsolationLevel()
                                 throws java.lang.Exception
java.lang.Exception

setTransactionIsolationLevel

public void setTransactionIsolationLevel(int level)
                                  throws java.lang.Exception
java.lang.Exception

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object

connectionCount

public static int connectionCount()

getID

public static int getID()