Monday, February 27, 2012

Bit #39 - Retrieving the current session id at the ADFBC layer

If you need to retrieve the current session identifier at the ADF Business Components layer, use the getId() method defined in the oracle.jbo.SessionContext interface. You can get the oracle.jbo.SessionContext interface by calling getCurrentSession() which is defined in the oracle.jbo.SessionContextManager interface. So, how do you get the oracle.jbo.SessionContextManager interface? Call any of the findOrCreateSessionContextManager() or getSessionContextManager() static methods in SessionImpl. Finally, you may asking why you might need the current session id at the ADFBC layer? In my case, I had to log it in the database as part of a generic session audit process during DML. Here is an example:

Example:

// in the context of ADFBC
SessionImpl.findOrCreateSessionContextManager().getCurrentSession().getId()

Notes:
Note #1: The oracle.jbo.SessionContext interface also provides a method called getType() that returns the session type. It can be any of the following: TYPE_HTTP_SESSION, TYPE_EJB_SESSION or TYPE_THREAD_SESSION.

Note #2: Here are some example session ids retrieved when calling oracle.jbo.SessionContext.getId():
  • HTTP session (original session): FGHpPKhfwJSQ5hkKChGnNyhCH10sVrvyGGL44GSz1vCpyZQbkFJX!2144650654!1330307487797_wsc30xy1y_1
  • HTTP session (same session, another browser tab): FGHpPKhfwJSQ5hkKChGnNyhCH10sVrvyGGL44GSz1vCpyZQbkFJX!2144650654!1330307487797_wsc30xy1y_5
  • ADF Model Tester: d7a748c1-0343-4f50-91d6-171cf9f8c5e5__root_frame_
  • ADF Model Tester (after File | Reload application): d7a748c1-0343-4f50-91d6-171cf9f8c5e5__root_frame_
Context:

ADF Business Components 
Related Posts Plugin for WordPress, Blogger...