de.topicmapslab.majortom.database.jdbc.core
Class SessionImpl

java.lang.Object
  extended by de.topicmapslab.majortom.database.jdbc.core.SessionImpl
All Implemented Interfaces:
ISession
Direct Known Subclasses:
RDBMSSession

public abstract class SessionImpl
extends java.lang.Object
implements ISession

Author:
Sven Krosse

Field Summary
private  boolean autoCommit
           
private  org.apache.commons.dbcp.BasicDataSource bds
           
private  java.sql.Connection connection
           
private  IConnectionProvider connectionProvider
           
private  IQueryProcessor processor
           
 
Constructor Summary
SessionImpl(T connectionProvider, java.lang.String url, java.lang.String user, java.lang.String password)
          Constructor
 
Method Summary
 void close()
          Closing the current session instance
 void commit()
          Commit all changes of this session
protected abstract
<T extends IQueryProcessor>
T
createProcessor(java.sql.Connection connection)
          Internal method to create a processor instance for the given connection
 java.sql.Connection getConnection()
          Access to the internal connection
 IConnectionProvider getConnectionProvider()
          Returns the parent connection provider
<T extends IQueryProcessor>
T
getProcessor()
          Returns the internal query processor instance, which should be used to execute queries.
 JdbcTopicMapStore getTopicMapStore()
          Returns the topic map store instance
protected  boolean isAlive()
          Internal method to check if the connection is still alive
 boolean isAutoCommit()
          Checks if the session automatically commits all changes
protected  java.sql.Connection openConnection()
          Internal method to open a connection to the defined database
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

processor

private IQueryProcessor processor

connection

private java.sql.Connection connection

connectionProvider

private final IConnectionProvider connectionProvider

autoCommit

private final boolean autoCommit

bds

private org.apache.commons.dbcp.BasicDataSource bds
Constructor Detail

SessionImpl

public SessionImpl(T connectionProvider,
                   java.lang.String url,
                   java.lang.String user,
                   java.lang.String password)
Constructor

Parameters:
connectionProvider - the parent connection provider
url - the URL
user - the user
password - the password
Method Detail

getProcessor

public <T extends IQueryProcessor> T getProcessor()
                                       throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Returns the internal query processor instance, which should be used to execute queries.

Specified by:
getProcessor in interface ISession
Returns:
the query processor
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if the connection is not established

createProcessor

protected abstract <T extends IQueryProcessor> T createProcessor(java.sql.Connection connection)
                                                      throws de.topicmapslab.majortom.model.exception.TopicMapStoreException
Internal method to create a processor instance for the given connection

Type Parameters:
T - the type of processor
Parameters:
connection - the connection
Returns:
the created processor
Throws:
de.topicmapslab.majortom.model.exception.TopicMapStoreException - thrown if operation fails

close

public void close()
           throws java.sql.SQLException
Closing the current session instance

Specified by:
close in interface ISession
Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Commit all changes of this session

Specified by:
commit in interface ISession
Throws:
java.sql.SQLException - thrown if commit failed

isAlive

protected boolean isAlive()
                   throws java.sql.SQLException
Internal method to check if the connection is still alive

Returns:
true if the connection is alive false otherwise
Throws:
java.sql.SQLException

openConnection

protected java.sql.Connection openConnection()
                                      throws java.sql.SQLException
Internal method to open a connection to the defined database

Returns:
the connection
Throws:
java.sql.SQLException - thrown if connection cannot be established

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Access to the internal connection

Specified by:
getConnection in interface ISession
Returns:
the connection
Throws:
java.sql.SQLException - thrown if connection cannot be established

getTopicMapStore

public JdbcTopicMapStore getTopicMapStore()
Returns the topic map store instance

Specified by:
getTopicMapStore in interface ISession
Returns:
the topic map store

getConnectionProvider

public IConnectionProvider getConnectionProvider()
Returns the parent connection provider

Specified by:
getConnectionProvider in interface ISession
Returns:
the connectionProvider the connection provider

isAutoCommit

public boolean isAutoCommit()
Checks if the session automatically commits all changes

Specified by:
isAutoCommit in interface ISession
Returns:
true if the session commits automatically, false otherwise.