goldengate.common.database
Class DbSession

java.lang.Object
  extended by goldengate.common.database.DbSession

public class DbSession
extends Object

Class to handle session with the SGBD

Author:
Frederic Bregier

Field Summary
 DbAdmin admin
          DbAdmin referent object
 boolean autoCommit
          Is this session using AutoCommit (true by default)
 Connection conn
          The internal connection
 long internalId
          Internal Id
 boolean isDisconnected
          To be used when a local Channel is over
 boolean isReadOnly
          Is this connection Read Only
 int nbThread
          Number of threads using this connection
 
Constructor Summary
DbSession(Connection connext, boolean isReadOnly)
          Create a session and connect the current object to the connect object given as parameter.
DbSession(DbAdmin admin, boolean isReadOnly)
          Create a session and connect the current object to the server using the DbAdmin object.
DbSession(DbAdmin admin, boolean isReadOnly, boolean autoCommit)
          Create a session and connect the current object to the server using the DbAdmin object.
DbSession(String server, String user, String passwd, boolean isReadOnly)
          Create a session and connect the current object to the server using the string with the form for mysql for instance jdbc:type://[host:port],[failoverhost:port] ...
DbSession(String server, String user, String passwd, boolean isReadOnly, boolean autoCommit)
          Create a session and connect the current object to the server using the string with the form for mysql for instance jdbc:type://[host:port],[failoverhost:port] ...
 
Method Summary
 void addLongTermPreparedStatement(DbPreparedStatement longterm)
          Add a Long Term PreparedStatement
 void checkConnection()
          Check the connection to the Database and try to reopen it if possible
 boolean checkConnectionNoException()
           
 void commit()
          Commit everything
 void disconnect()
          Close the connection
 void endUseConnection()
          To be called when a client will stop to use this DbSession (once by client)
static void error(SQLException ex)
          Print the error from SQLException
 DbAdmin getAdmin()
           
 void recreateLongTermPreparedStatements()
          Due to a reconnection, recreate all associated long term PreparedStatements
 void releaseSavepoint(Savepoint savepoint)
          Release the savepoint
 void removeLongTermPreparedStatements()
          Remove all Long Term PreparedStatements (closing connection)
 void removeLongTermPreparedStatements(DbPreparedStatement longterm)
          Remove one Long Term PreparedStatement
 void rollback(Savepoint savepoint)
          Rollback from the savepoint or the last set if null
 Savepoint savepoint()
          Make a savepoint
 void setAdmin(DbAdmin admin)
           
 void setAutoCommit(boolean autoCommit)
          Change the autocommit feature
 void useConnection()
          To be called when a client will start to use this DbSession (once by client)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

admin

public DbAdmin admin
DbAdmin referent object


conn

public Connection conn
The internal connection


isReadOnly

public boolean isReadOnly
Is this connection Read Only


autoCommit

public boolean autoCommit
Is this session using AutoCommit (true by default)


internalId

public long internalId
Internal Id


nbThread

public int nbThread
Number of threads using this connection


isDisconnected

public boolean isDisconnected
To be used when a local Channel is over

Constructor Detail

DbSession

public DbSession(Connection connext,
                 boolean isReadOnly)
          throws GoldenGateDatabaseNoConnectionException
Create a session and connect the current object to the connect object given as parameter. The database access use auto commit. If the initialize is not call before, call it with the default value.

Parameters:
connext -
isReadOnly -
Throws:
GoldenGateDatabaseNoConnectionException

DbSession

public DbSession(String server,
                 String user,
                 String passwd,
                 boolean isReadOnly)
          throws GoldenGateDatabaseNoConnectionException
Create a session and connect the current object to the server using the string with the form for mysql for instance jdbc:type://[host:port],[failoverhost:port] .../[database][?propertyName1][ =propertyValue1][&propertyName2][=propertyValue2]... By default (if server = null) : "jdbc:mysql://localhost/r66 user=r66 password=r66" The database access use auto commit. If the initialize is not call before, call it with the default value.

Parameters:
server -
user -
passwd -
isReadOnly -
Throws:
GoldenGateDatabaseSqlException
GoldenGateDatabaseNoConnectionException

DbSession

public DbSession(DbAdmin admin,
                 boolean isReadOnly)
          throws GoldenGateDatabaseNoConnectionException
Create a session and connect the current object to the server using the DbAdmin object. The database access use auto commit. If the initialize is not call before, call it with the default value.

Parameters:
admin -
isReadOnly -
Throws:
GoldenGateDatabaseSqlException
GoldenGateDatabaseNoConnectionException

DbSession

public DbSession(String server,
                 String user,
                 String passwd,
                 boolean isReadOnly,
                 boolean autoCommit)
          throws GoldenGateDatabaseNoConnectionException
Create a session and connect the current object to the server using the string with the form for mysql for instance jdbc:type://[host:port],[failoverhost:port] .../[database][?propertyName1][ =propertyValue1][&propertyName2][=propertyValue2]... By default (if server = null) : "jdbc:mysql://localhost/r66 user=r66 password=r66" If the initialize is not call before, call it with the default value.

Parameters:
server -
user -
passwd -
isReadOnly -
autoCommit -
Throws:
GoldenGateDatabaseSqlException
GoldenGateDatabaseNoConnectionException

DbSession

public DbSession(DbAdmin admin,
                 boolean isReadOnly,
                 boolean autoCommit)
          throws GoldenGateDatabaseNoConnectionException
Create a session and connect the current object to the server using the DbAdmin object. If the initialize is not call before, call it with the default value.

Parameters:
admin -
isReadOnly -
autoCommit -
Throws:
GoldenGateDatabaseSqlException
GoldenGateDatabaseNoConnectionException
Method Detail

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws GoldenGateDatabaseNoConnectionException
Change the autocommit feature

Parameters:
autoCommit -
Throws:
GoldenGateDatabaseNoConnectionException

getAdmin

public DbAdmin getAdmin()
Returns:
the admin

setAdmin

public void setAdmin(DbAdmin admin)
Parameters:
admin - the admin to set

error

public static void error(SQLException ex)
Print the error from SQLException

Parameters:
ex -

useConnection

public void useConnection()
To be called when a client will start to use this DbSession (once by client)


endUseConnection

public void endUseConnection()
To be called when a client will stop to use this DbSession (once by client)


disconnect

public void disconnect()
Close the connection


checkConnection

public void checkConnection()
                     throws GoldenGateDatabaseNoConnectionException
Check the connection to the Database and try to reopen it if possible

Throws:
GoldenGateDatabaseNoConnectionException

checkConnectionNoException

public boolean checkConnectionNoException()
Returns:
True if the connection was successfully reconnected

addLongTermPreparedStatement

public void addLongTermPreparedStatement(DbPreparedStatement longterm)
Add a Long Term PreparedStatement

Parameters:
longterm -

recreateLongTermPreparedStatements

public void recreateLongTermPreparedStatements()
                                        throws GoldenGateDatabaseNoConnectionException,
                                               GoldenGateDatabaseSqlException
Due to a reconnection, recreate all associated long term PreparedStatements

Throws:
GoldenGateDatabaseNoConnectionException
GoldenGateDatabaseSqlException

removeLongTermPreparedStatements

public void removeLongTermPreparedStatements()
Remove all Long Term PreparedStatements (closing connection)


removeLongTermPreparedStatements

public void removeLongTermPreparedStatements(DbPreparedStatement longterm)
Remove one Long Term PreparedStatement

Parameters:
longterm -

commit

public void commit()
            throws GoldenGateDatabaseSqlException,
                   GoldenGateDatabaseNoConnectionException
Commit everything

Throws:
GoldenGateDatabaseSqlException
GoldenGateDatabaseNoConnectionException

rollback

public void rollback(Savepoint savepoint)
              throws GoldenGateDatabaseNoConnectionException,
                     GoldenGateDatabaseSqlException
Rollback from the savepoint or the last set if null

Parameters:
savepoint -
Throws:
GoldenGateDatabaseNoConnectionException
GoldenGateDatabaseSqlException

savepoint

public Savepoint savepoint()
                    throws GoldenGateDatabaseNoConnectionException,
                           GoldenGateDatabaseSqlException
Make a savepoint

Returns:
the new savepoint
Throws:
GoldenGateDatabaseNoConnectionException
GoldenGateDatabaseSqlException

releaseSavepoint

public void releaseSavepoint(Savepoint savepoint)
                      throws GoldenGateDatabaseNoConnectionException,
                             GoldenGateDatabaseSqlException
Release the savepoint

Parameters:
savepoint -
Throws:
GoldenGateDatabaseNoConnectionException
GoldenGateDatabaseSqlException


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.