org.velocityweb.context
Class AppContext

java.lang.Object
  extended byorg.velocityweb.context.AppContext
Direct Known Subclasses:
BatchJobAppContext, WebAppContext

public abstract class AppContext
extends java.lang.Object

application context, use this to replace need of ThreadLocal. contains resources used for each web request, or each single background timer task. Resources in it including: JDBC connection(will passed to DAO), resource bundle(will passed to web process layer), transaction layer(support design pattern named as TRANSACTION_PER_REQUEST).

Author:
Jacklondon Chen

Constructor Summary
AppContext(java.lang.Object dataSource, int transactionIsolation, java.util.ResourceBundle resourceBundle, Controller controller)
          contructor
 
Method Summary
protected  void closeConnection()
          class JDBC connection
 void commitAndClose()
          commit and close JDBC connection, normally after a success operation.
 long getBeginTime()
          get start time of web request/background task
 java.sql.Connection getConnection()
          get JDBC Connection, each AppContext object contains one Connection
 Controller getController()
          get controller
 java.util.ResourceBundle getResourceBundle()
          get resource bundle
 int getTransactionIsolation()
          get transaction isolation level
 void rollbackAndClose()
          roll back and close JDBC connection, normally after a failure operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AppContext

public AppContext(java.lang.Object dataSource,
                  int transactionIsolation,
                  java.util.ResourceBundle resourceBundle,
                  Controller controller)
contructor

Parameters:
dataSource - data source, use ConnectionPoolDataSource will be better
transactionIsolation - transaction isolation level
resourceBundle - resource bundle
Method Detail

getConnection

public java.sql.Connection getConnection()
get JDBC Connection, each AppContext object contains one Connection

Returns:
JDBC Connection

getBeginTime

public long getBeginTime()
get start time of web request/background task


closeConnection

protected void closeConnection()
class JDBC connection

Throws:
java.sql.SQLException

commitAndClose

public void commitAndClose()
                    throws java.sql.SQLException
commit and close JDBC connection, normally after a success operation. This method should only be called by controller, for example , sub-class of ControllerServlet.

Throws:
java.sql.SQLException

rollbackAndClose

public void rollbackAndClose()
roll back and close JDBC connection, normally after a failure operation. This method should only be called by controller, for example , sub-class of ControllerServlet.

Throws:
java.sql.SQLException
java.sql.SQLException

getResourceBundle

public java.util.ResourceBundle getResourceBundle()
get resource bundle

Returns:
resource bundle

getTransactionIsolation

public int getTransactionIsolation()
get transaction isolation level


getController

public Controller getController()
get controller

Returns:
controller instance