You can override prepareSession() in your custom Application Module class to do session-specific initializations, such as invoking a stored procedure to initialize the database state for the specific user, store user information, set application-wide configuration parameters based on the user and so on. You may extend the default implementation, as is often nessesary, in order to satisfy various pre-condtions such as user authorization etc. For example, to lock a specific view (E.g. UserView) to only show records with the users own initials (CLB in my case), the following could be done:.The framework invokes prepareSession() when the Application Module is first checked-out from the Application Module pool for a new user session.
Example:
@Override
protected void prepareSession(Session session) {
super.prepareSession(session);
// do session-specific initializations
}
For example we can write the code i.e
public void prepareSession(SessionData sessionData) { super.prepareSession(sessionData); // Retrieve the J2EE user ID String authenticatedUser = getUserPrincipalName(); if ((authenticatedUser != null) && (authenticatedUser.trim().length() > 0)) { DBTransactionImpl dbTransaction = (DBTransactionImpl)getDBTransaction(); // Parameter for database procedure String pApplication = "TUHRA"; // Transaction statement with procedure call CallableStatement callableStmt = dbTransaction.createCallableStatement(("BEGIN " + "security_pkg.set_security_context(?, ?); " + "END;"), 0); try { // Register parameters and call procedure callableStmt.setString(1, authenticatedUser); callableStmt.setString(2, pApplication); callableStmt.execute(); } catch (SQLException sqlExcept) { throw new JboException(sqlExcept); } finally { try { if (callableStmt != null) { callableStmt.close(); } } catch (SQLException closeExcept) { throw new JboException(closeExcept); } } } }