TUHRA Logo

Oracle JDeveloper 10g for Forms & PL/SQL Developers
Sample Code

Chapter 15
Section Loading Audit Columns Using a Database Procedure and Application Context | Set the Context from the Application
Code prepareSession( )
Return to listings...


  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);
        }
      }
    }
  }