4 Replies Latest reply: Sep 3, 2012 1:17 PM by myluism RSS

    Question about global context.

    myluism
      Hi.

      I have this scenario:

      1) Context set within the application:

      a) user logins and identifies basic context info: company id, etc.
      b) Context is set in a package
      b) Views are the underlying datasource for application and they are created using context info. For example:
      Create view some_view as
      select * from some_table where company_id =sys_context('access_control_ctx','company_id')

      2) This works perfectly in a dedicated / persistent connection. However if ones tries to use connection pooling, like in a Web app, say Apex , this won't work as expected.

      3) An alternative is to use global context. However i have this question:
      (a) User a logs in to application and set values for company 1.
      (b) User b logs in to application and set values for company 2.

      How does global context works in this situation?. I mean, since every user needs a different value form company_id? How can one guaranties they both will point to their respective value without having to change the application security / access control?.

      Regards, Luis ...!
        • 1. Re: Question about global context.
          JustinCave
          Specific to APEX, you can use the v function to access APEX session state information (i.e. v('APP_USER') to get the currently logged in application user).

          If you are going to use a global context, you would need a session ID (or something similar) that is stored as a part of the global context to determine which session you are interested in. The global context would have A's data with A's session ID and B's data with B's session ID and before you get the context information, you would need to specify which session ID you are asking about.

          Tom Kyte has an example of using a global context

          Justin
          • 2. Re: Question about global context.
            myluism
            Oh man, this is really great ...!

            The link is very educational....!

            So if i understood clearly, say you need to set a global context, and continuing with my example, suppose you have two companies in one database, it means you will need to set two groups of context values, one for each company. What one needs to do is to have a init procedure that sets contexts for both companies, and through the use of a session id or something map to the correct set of values. Is this correct ....?

            Regards, Luis ...:)
            • 3. Re: Question about global context.
              JustinCave
              Right. The global context would have the context for each session and you would need some session-specific identifier (i.e. a session ID) to act as a key so that you can retrieve the appropriate context values for a particular session.

              Justin
              • 4. Re: Question about global context.
                myluism
                Thanks a lot. Again.

                Very helpful ....!

                Best regards, Luis ....! :)