SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión





                                Application Context


                                                                       Lucas Jellema
                                                                          AMIS
                                                              KC Server Development
                                                                PL/SQL Potpourri
                                                                 20th January 2009




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Overview





    Application Context provides part of the environment
     in which a session is executing statements
           Part is system defined – context USERENV
           Part is developer controlled – CLIENTCONTEXT and user
            defined contexts
    The Application Context is the link for context meta-
     data between applications and the database
           Applications should set the proper context values before
            executing SQL and PL/SQL statements
    Application Context is sometimes a more elegant and
     better performing alternative to global package variables
           And an essential part of VPD – Virtual Private Database




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Introducing Application Context





    An Application Context is
           Named area
           With key-value pairs                                                    WebClient_Ctx
                 • Key and Value are both                         Currency_Ctx      Name    Value
                   string values
                                                                                    OrgId    14
           (Usually) part of the                                                  Locale fr_ca
            session scope                                                         Timezone +2.00
                                                                       View_Ctx
                 • Just like global package
                   variables


    Values can only be added through a PL/SQL package
    Values can be read in SQL queries and PL/SQL code
           Through the SYS_CONTEXT operator




                                                                                                    
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Application Context





    Enables application developers to define, set, and access
     application attributes by serving as a data cache
    This removes the repeated overhead of querying the
     database each time access to application
                                                  Namespace
     attributes is needed
    Two Application
     Contexts are always Attribute Value
     around:
                                                                 Attribute Value
           CLIENTCONTEXT
           USERENV
                                                                                    Attribute Value
                                                                                          Pairs




                                                                                                      
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Application Context





    Values can be read from an Application Context using
     SYS_CONTEXT, both in SQL as well as PL/SQL
        select sys_context('USERENV', 'SESSION_USER')
        from   dual

        l_user:= sys_context('USERENV', 'SESSION_USER')

           Pass in the name of the Application Context and the name of the Attribute
            you are looking for
    If you ask for an Application Context that does not
     exist, NULL is returned
    If you ask for an attribute that does not exist, ORA-
     2003 – invalid <app context> parameter is raised




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
USERENV


                ACTION                                                       ISDBA
                                                                        
                AUDITED_CURSORID                                             LANG
                                                                        
                AUTHENTICATED_IDENTITY                                       LANGUAGE
                                                                        
                AUTHENTICATION_DATA                                          MODULE
                                                                        
                AUTHENTICATION_METHOD                                        NETWORK_PROTOCOL
                                                                        
                BG_JOB_ID                                                    NLS_CALENDAR
                                                                        
                CLIENT_IDENTIFIER                                            NLS_CURRENCY
                                                                        
                CLIENT_INFO                                                  NLS_DATE_FORMAT
                                                                        
                CURRENT_BIND                                                 NLS_DATE_LANGUAGE
                                                                        
                CURRENT_SCHEMA                                               NLS_SORT
                                                                        
                CURRENT_SCHEMAID                                             NLS_TERRITORY
                                                                        
                CURRENT_SQL                                                  OS_USER
                                                                        
                CURRENT_SQL_LENGTH                                           POLICY_INVOKER
                                                                        
                DB_DOMAIN                                                    PROXY_ENTERPRISE_IDENTITY
                                                                        
                DB_NAME                                                      PROXY_GLOBAL_UID
                                                                        
                DB_UNIQUE_NAME                                               PROXY_USER
                                                                        
                ENTRYID                                                      PROXY_USERID
                                                                        
                ENTERPRISE_IDENTITY                                          SERVER_HOST
                                                                        
                FG_JOB_ID                                                    SERVICE_NAME
                                                                        
                GLOBAL_CONTEXT_MEMORY                                        SESSION_USER
                                                                        
                GLOBAL_UID                                                   SESSION_USERID
                                                                        
                HOST                                                         SESSIONID
                                                                        
                IDENTIFICATION_TYPE                                          SID
                                                                        
                INSTANCE                                                     STATEMENTID
                                                                        
                INSTANCE_NAME                                                TERMINAL
                                                                        
                IP_ADDRESS
           




                                                                                                         
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Storing values in standard context
                                                             CLIENTCONTEXT





    Values can be set in the Application Context CLIENTCONTEXT
        begin
          dbms_session.set_context
          ( 'CLIENTCONTEXT' -- Namespace
          , 'dollar_to_euro_ratio' -- Attribute
          , '0.67' -- Value
          );
        end;

           CLIENTCONTEXT needs not be set up, it is always there
           It is session bound – not accessible in other sessions, stored in UGA
    The value can be read – in the same session – using:




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Creating an application specific context





    Application Context is a named container with a set of key-value
     pairs.
           A per session instance is stored in UGA
          create context Hrm_Ctx using HrmPkg
    An Application Context is associated with a package
           Only through the package can values be set in the context
           Setting values is not tied to the transaction (no commit dependency)
    Values in the context can be used in where conditions
           These are treated as bind-parameters!
                 deptno = sys_context('Hrm_Ctx', 'dept')

                  deptno = :b1




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Distinction with global package variables





    Values from Application Context are treated as bind
     variables
           There value is established before the query is executed
    While functionally similar, the execution for these two
     queries is quite different:
          select *
          from   big_table
          where country_column = package.get_current_country
        and
          select *
          from   big_table
          where country_column =
                    sys_context('App_Ctx', 'current_country')




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Create the HRM_CTX Context




      create or replace context hrm_ctx using hrm_pkg
      create or replace package body hrm_pkg
      is
      procedure set_language (p_language in varchar2)
      is
      begin
        dbms_session.set_context
          ('HRM_CTX' , 'LANGUAGE' ,p_language);
      end set_language;

      procedure clear_context is
      begin
        dbms_session.clear_context('HRM_CTX');
      end;
      ...                         select *
                                                                             from session_context




                                                                                                    
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Create the HRM_CTX Context





                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Use cases for Application Context





    Programmable/Configurable View
    Meta Data Interface between Application and Database
           Client User Identity – and other environment settings
                 • Get rid of hard coded references to USER!
           Instrumentation
           Setting default values
    Cache for ‘expensive’ and/or ‘shared’ values
    Foundation for VPD




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Configurable View





    Generic challenge: create a view that has run-time
     parameters governing its behavior
    For example:
           View EMP_REPORT_VW
           Returns the Average Salary and Number of Employees
                 •     Per Job and Department and Year of hiring
                 •     or: Over all Employees
                 •     or: Per Job
                 •     or: Per Department and Year of Hiring
                 •     or: any other combination
           It depends on the caller which should be the case!
                 • The caller should provide ‘input parameters’ to get the desired
                   behavior from this view




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Configurable View EMP_REPORT_VW





                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Approach this challenge





    Clearly this view uses data from meta data environment
           That indicates which column(s) to group by
    The view accesses this data from an Application
     Context using SYS_CONTEXT
    Setting the data is done through a simple call to a
     package, preceding the query against the view
           Note: for client technologies that have a problem calling
            PL/SQL packages, we could create a View called
            EMP_REPORT_VW_PARAMETERS with an INSTEAD OF
            trigger that will convert an update of a parameter to a call to
            the package that controls the Application Context.




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Implementing Configurable View





                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Implementing Configurable View (2)





                                                       If group by department, then show deptno




                                                       If group by department, then group by deptno
                                                       else group by null (which has no effect)




                                                                                                      
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Calling the configurable view





                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
The client is always right





    What time is it
           or at least what is the client’s timezone
    What locale is it
           which language/regional settings apply
    Where is it located
           what is the geographical location
    Who is it
           web user’s identity <> any database user
    Note: The database can only serve!
           Following the client’s lead




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
USER <> CLIENT_IDENTIFIER




                                                                                           Client
    Many – and ever more –
     applications make use of
     light-weight users
                                                                                                         LDAP
           That do not correspond                                 J(2)EE Application Server
            to database users
                                                                             Web
    These applications will                                                 Application

     inform the database
     through setting the Client
     Identifier about the user
    Referring to USER is (ever                                                    APPLICATION_
     more) meaningless!                                                            SCHEMA
                                                                                                    USERENV




                                                                                                                
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Set Client Identifier with Light Weight User




    In Java using Oracle JDBC Driver
          conn.setClientIdentifier(quot;john.doequot;)

    In PL/SQL
          DBMS_SESSION.SET_IDENTIFIER( 'john.doe');

    Or use a logon trigger to derive the client identifier
          CREATE OR REPLACE TRIGGER logon_trigger
          AFTER LOGON ON DATABASE
          DECLARE
           uid VARCHAR2(64);
          BEGIN
            SELECT ora_login_user ||':'
                   ||SYS_CONTEXT('USERENV', 'OS_USER')
            INTO uid
            FROM dual;
            dbms_session.set_identifier(uid);
          END logon_trigger;




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Set Client Identifier with Light Weight User





    In the database – SQL or PL/SQL – the current client
     identifier can be read like this:
          SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER')


    The Client Identifier is also available in V$SESSION
          SELECT sid, client_identifier, service_name
          FROM   v_$session;
     as well as V$SQLAREA
    DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE
     allows for tracing all activity of a CLIENT_IDENTIIER
     aka light-weight user
           Note: Oracle standard auditing does not use
            CLIENT_IDENTIFIER




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
A properly instrumented application...



    Should tell the database
           Who is the actual user for whom it is running
           Which Module requests database actions & for what purpose
           (optionally) Additional information about the client
          begin
            dbms_application_info.set_module
            ( module_name => 'MODULE_NAME'
            , action_name => 'What is the module doing'
            ); -- sets columns Module&Action in V$SESSION view
            dbms_application_info.set_client_info
            ( client_info => 'extra info e.g. Task Context'
            ); -- no longer than 64 chars, sets column Client
               -- Info in the V$SESSION view
            dbms_session.set_identifier('id for real user');
            -- sets v$session view column CLIENT_IDENTIFIER
          end;




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Guideline: provide application with
                                                         Instrumentation API





    Define an API (PL/SQL procedure) that applications can
     call to provide all instrumentation information
           This API will take care of
            setting the proper values
                                       J(2)EE Application Server
            in Application Context
            and through                      Web
                                             Application
            dbms_application_info
           Requires but a single call


                                                                             INSTRUMENTATION_API

                                                                          dbms_
                                                                                            dbms_
                                                                        application_
                                                                                            session
                                                                            info




                                                                                                      
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Retrieving the ‘instrumented values’



   select           sys_context('USERENV','sid') sid
   ,                sys_context('USERENV','module') module
   ,                sys_context('USERENV','action') action
   ,                sys_context('USERENV','client_identifier')
                    client_identifier
   ,                sys_context('USERENV','client_info') client_info
   from             dual
   /
   select           sid
   ,                module
   ,                client_identifier
   ,                client_info
   ,                action
   from             v$session
   /




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Default values for audit columns



    The default value of a column can be specified using a
     reference to an application context:
          CREATE TABLE IMPORTANT_RECORDS
          ( ...
          , USER_CREATED VARCHAR2(100) DEFAULT
                  SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER')

    That can be a reference to a user defined context too:
          CREATE TABLE IMPORTANT_RECORDS
          ( ...
          , PRICE VARCHAR2(100) DEFAULT
                  SYS_CONTEXT('ORDER_APP','CURRENT_PRICE')
           Note: you can refer to default in UPDATE statement
            UPDATE IMPORTANT_RECORDS
            SET    PRICE = DEFAULT
            WHERE ...




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Create Context as Globally Accessible





         Accessible throughout the entire instance:
                 Every session can retrieve values
                 Stored in SGA (instead of UGA)
                       • A big difference compared to package variables!!
                 For global settings, cross application parameters
                       • For example once-per-day calculated or retrieved (from web
                         services?) values that remain available throughout the day




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Globally Accessible





                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Globally Accessible: Accessing Values





                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Application Context values associated
                                       with Client Identifier





    Application Context can be private (tied to a session) or
     globally accessible (across all sessions)
    Third option: attributes associated with Client Identifier:
           only sessions with the same Client Identifier can access an
            those attributes of such a context


             dbms_session.set_context
             ( namespace=> 'HRM_CTX'
             , attribute => 'my_org_id'
             , value=> '67'
             , client_id =>
                   sys_context('USERENV','CLIENT_IDENTIFIER')
             );




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Application Context associated with
                                                Client Identifier





    Retrieving session specific values is handled by the
     database automatically, using the CLIENT_IDENTIFIER
           SYS_CONTEXT('HRM_CTX', 'my_ord_id')

           If HRM_CTX has a value associated with the client identifier,
            it is returned; otherwise the non associated value is returned
    To remove all values tied to a specific client_identifier
     from an application context:
      ... –- still package hrm_pkg managing HRM_CTX
      procedure clear_context is
      begin
        dbms_session.clear_context('HRM_CTX'
        , sys_context('USERENV','CLIENT_IDENTIFIER')                                 );
      end;




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
Summary




    An Application Context is a named in-memory set of
     key-value pairs
    Application Context value references in SQL queries
     are processed like bind parameters
    A Context is by default associated with a single session
           Alternatively a context can be global (cross session) or
            associated with a Client Identifier
    Application Context is used for
               Exposing System and Session attributes (USERENV)
          
               Configurable Views
          
               Application to Database meta data interface
          
               Global cross-session shared in memory cache
          
               Virtual Private Database
          




                                                                                               
Application Context
Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009

Más contenido relacionado

La actualidad más candente

Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
Guo Albert
 

La actualidad más candente (20)

Spring jdbc
Spring jdbcSpring jdbc
Spring jdbc
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Domain Driven Design Ch7
Domain Driven Design Ch7Domain Driven Design Ch7
Domain Driven Design Ch7
 
Oracle Enterprise Manager
Oracle Enterprise ManagerOracle Enterprise Manager
Oracle Enterprise Manager
 
MS SQL SERVER: SSIS and data mining
MS SQL SERVER: SSIS and data miningMS SQL SERVER: SSIS and data mining
MS SQL SERVER: SSIS and data mining
 
tow nodes Oracle 12c RAC on virtualbox
tow nodes Oracle 12c RAC on virtualboxtow nodes Oracle 12c RAC on virtualbox
tow nodes Oracle 12c RAC on virtualbox
 
Rapid Home Provisioning
Rapid Home ProvisioningRapid Home Provisioning
Rapid Home Provisioning
 
9장 도메인 주도 설계
9장 도메인 주도 설계9장 도메인 주도 설계
9장 도메인 주도 설계
 
Spring Security
Spring SecuritySpring Security
Spring Security
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootUnderstanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring Boot
 
What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...
What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...
What Is Spring Framework In Java | Spring Framework Tutorial For Beginners Wi...
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Java EE Security API - JSR375: Getting Started
Java EE Security API - JSR375: Getting Started Java EE Security API - JSR375: Getting Started
Java EE Security API - JSR375: Getting Started
 
Spring Framework - Data Access
Spring Framework - Data AccessSpring Framework - Data Access
Spring Framework - Data Access
 
Securing Java EE apps using WildFly Elytron
Securing Java EE apps using WildFly ElytronSecuring Java EE apps using WildFly Elytron
Securing Java EE apps using WildFly Elytron
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Integrating the new Layer-Based SVG Engine
Integrating the new Layer-Based SVG EngineIntegrating the new Layer-Based SVG Engine
Integrating the new Layer-Based SVG Engine
 

Similar a Introducing Application Context - from the PL/SQL Potpourri

Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001
jucaab
 
SQL Server SQL Server
SQL Server SQL ServerSQL Server SQL Server
SQL Server SQL Server
webhostingguy
 
SQL Server SQL Server
SQL Server SQL ServerSQL Server SQL Server
SQL Server SQL Server
webhostingguy
 
durga_resume
durga_resumedurga_resume
durga_resume
durga p
 
SPS Belgium 2012 - End to End Security for SharePoint Farms - Michael Noel
SPS Belgium 2012 - End to End Security for SharePoint Farms - Michael NoelSPS Belgium 2012 - End to End Security for SharePoint Farms - Michael Noel
SPS Belgium 2012 - End to End Security for SharePoint Farms - Michael Noel
Michael Noel
 
Patterns & Practices of Microservices
Patterns & Practices of MicroservicesPatterns & Practices of Microservices
Patterns & Practices of Microservices
Wesley Reisz
 
Jfokus 2012: PaaSing a Java EE Application
Jfokus 2012: PaaSing a Java EE ApplicationJfokus 2012: PaaSing a Java EE Application
Jfokus 2012: PaaSing a Java EE Application
Arun Gupta
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
Carles Farré
 
Expendables E-AppStore
Expendables E-AppStoreExpendables E-AppStore
Expendables E-AppStore
lobalint
 

Similar a Introducing Application Context - from the PL/SQL Potpourri (20)

Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001Ebs dba con4696_pdf_4696_0001
Ebs dba con4696_pdf_4696_0001
 
Sql Performance Tuning with ASH &amp; AWR: Real World Use Cases
Sql Performance Tuning with ASH &amp; AWR: Real World Use CasesSql Performance Tuning with ASH &amp; AWR: Real World Use Cases
Sql Performance Tuning with ASH &amp; AWR: Real World Use Cases
 
SQL Server SQL Server
SQL Server SQL ServerSQL Server SQL Server
SQL Server SQL Server
 
SQL Server SQL Server
SQL Server SQL ServerSQL Server SQL Server
SQL Server SQL Server
 
The Very Very Latest in Database Development - Oracle Open World 2012
The Very Very Latest in Database Development - Oracle Open World 2012The Very Very Latest in Database Development - Oracle Open World 2012
The Very Very Latest in Database Development - Oracle Open World 2012
 
The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...
The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...
The Very Very Latest In Database Development - Lucas Jellema - Oracle OpenWor...
 
Novell Identity Manager Tips, Tricks and Best Practices
Novell Identity Manager Tips, Tricks and Best PracticesNovell Identity Manager Tips, Tricks and Best Practices
Novell Identity Manager Tips, Tricks and Best Practices
 
SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...
SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...
SEASPC 2011 - SharePoint Security in an Insecure World: Understanding the Fiv...
 
SharePoint Security in an Insecure World - AUSPC 2012
SharePoint Security in an Insecure World - AUSPC 2012SharePoint Security in an Insecure World - AUSPC 2012
SharePoint Security in an Insecure World - AUSPC 2012
 
durga_resume
durga_resumedurga_resume
durga_resume
 
SPS Belgium 2012 - End to End Security for SharePoint Farms - Michael Noel
SPS Belgium 2012 - End to End Security for SharePoint Farms - Michael NoelSPS Belgium 2012 - End to End Security for SharePoint Farms - Michael Noel
SPS Belgium 2012 - End to End Security for SharePoint Farms - Michael Noel
 
PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012
 
GIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE ApplicationGIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE Application
 
Patterns & Practices of Microservices
Patterns & Practices of MicroservicesPatterns & Practices of Microservices
Patterns & Practices of Microservices
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
 
Jfokus 2012: PaaSing a Java EE Application
Jfokus 2012: PaaSing a Java EE ApplicationJfokus 2012: PaaSing a Java EE Application
Jfokus 2012: PaaSing a Java EE Application
 
New em12c kscope
New em12c kscopeNew em12c kscope
New em12c kscope
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
 
Sql Server - Apresentação
Sql Server - ApresentaçãoSql Server - Apresentação
Sql Server - Apresentação
 
Expendables E-AppStore
Expendables E-AppStoreExpendables E-AppStore
Expendables E-AppStore
 

Más de Lucas Jellema

Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
Lucas Jellema
 
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
Lucas Jellema
 
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Lucas Jellema
 
Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...
Lucas Jellema
 
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
Lucas Jellema
 
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Lucas Jellema
 
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Lucas Jellema
 

Más de Lucas Jellema (20)

Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
 
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
 
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
 
Apache Superset - open source data exploration and visualization (Conclusion ...
Apache Superset - open source data exploration and visualization (Conclusion ...Apache Superset - open source data exploration and visualization (Conclusion ...
Apache Superset - open source data exploration and visualization (Conclusion ...
 
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
 
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
 
Op je vingers tellen... tot 1000!
Op je vingers tellen... tot 1000!Op je vingers tellen... tot 1000!
Op je vingers tellen... tot 1000!
 
IoT - from prototype to enterprise platform (DigitalXchange 2022)
IoT - from prototype to enterprise platform (DigitalXchange 2022)IoT - from prototype to enterprise platform (DigitalXchange 2022)
IoT - from prototype to enterprise platform (DigitalXchange 2022)
 
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
 
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
 
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
 
Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...
 
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
 
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
 
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
 
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
 
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
 
Tech Talks 101 - DevOps (jan 2022)
Tech Talks 101 - DevOps (jan 2022)Tech Talks 101 - DevOps (jan 2022)
Tech Talks 101 - DevOps (jan 2022)
 
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
 
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

Introducing Application Context - from the PL/SQL Potpourri

  • 1.  Application Context Lucas Jellema AMIS KC Server Development PL/SQL Potpourri 20th January 2009  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 2. Overview   Application Context provides part of the environment in which a session is executing statements  Part is system defined – context USERENV  Part is developer controlled – CLIENTCONTEXT and user defined contexts  The Application Context is the link for context meta- data between applications and the database  Applications should set the proper context values before executing SQL and PL/SQL statements  Application Context is sometimes a more elegant and better performing alternative to global package variables  And an essential part of VPD – Virtual Private Database  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 3. Introducing Application Context   An Application Context is  Named area  With key-value pairs WebClient_Ctx • Key and Value are both Currency_Ctx Name Value string values OrgId 14  (Usually) part of the Locale fr_ca session scope Timezone +2.00 View_Ctx • Just like global package variables  Values can only be added through a PL/SQL package  Values can be read in SQL queries and PL/SQL code  Through the SYS_CONTEXT operator  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 4. Application Context   Enables application developers to define, set, and access application attributes by serving as a data cache  This removes the repeated overhead of querying the database each time access to application Namespace attributes is needed  Two Application Contexts are always Attribute Value around: Attribute Value  CLIENTCONTEXT  USERENV Attribute Value Pairs  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 5. Application Context   Values can be read from an Application Context using SYS_CONTEXT, both in SQL as well as PL/SQL select sys_context('USERENV', 'SESSION_USER') from dual l_user:= sys_context('USERENV', 'SESSION_USER')  Pass in the name of the Application Context and the name of the Attribute you are looking for  If you ask for an Application Context that does not exist, NULL is returned  If you ask for an attribute that does not exist, ORA- 2003 – invalid <app context> parameter is raised  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 6. USERENV  ACTION ISDBA   AUDITED_CURSORID LANG   AUTHENTICATED_IDENTITY LANGUAGE   AUTHENTICATION_DATA MODULE   AUTHENTICATION_METHOD NETWORK_PROTOCOL   BG_JOB_ID NLS_CALENDAR   CLIENT_IDENTIFIER NLS_CURRENCY   CLIENT_INFO NLS_DATE_FORMAT   CURRENT_BIND NLS_DATE_LANGUAGE   CURRENT_SCHEMA NLS_SORT   CURRENT_SCHEMAID NLS_TERRITORY   CURRENT_SQL OS_USER   CURRENT_SQL_LENGTH POLICY_INVOKER   DB_DOMAIN PROXY_ENTERPRISE_IDENTITY   DB_NAME PROXY_GLOBAL_UID   DB_UNIQUE_NAME PROXY_USER   ENTRYID PROXY_USERID   ENTERPRISE_IDENTITY SERVER_HOST   FG_JOB_ID SERVICE_NAME   GLOBAL_CONTEXT_MEMORY SESSION_USER   GLOBAL_UID SESSION_USERID   HOST SESSIONID   IDENTIFICATION_TYPE SID   INSTANCE STATEMENTID   INSTANCE_NAME TERMINAL   IP_ADDRESS   Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 7. Storing values in standard context CLIENTCONTEXT   Values can be set in the Application Context CLIENTCONTEXT begin dbms_session.set_context ( 'CLIENTCONTEXT' -- Namespace , 'dollar_to_euro_ratio' -- Attribute , '0.67' -- Value ); end;  CLIENTCONTEXT needs not be set up, it is always there  It is session bound – not accessible in other sessions, stored in UGA  The value can be read – in the same session – using:  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 8. Creating an application specific context   Application Context is a named container with a set of key-value pairs.  A per session instance is stored in UGA create context Hrm_Ctx using HrmPkg  An Application Context is associated with a package  Only through the package can values be set in the context  Setting values is not tied to the transaction (no commit dependency)  Values in the context can be used in where conditions  These are treated as bind-parameters! deptno = sys_context('Hrm_Ctx', 'dept') deptno = :b1  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 9. Distinction with global package variables   Values from Application Context are treated as bind variables  There value is established before the query is executed  While functionally similar, the execution for these two queries is quite different: select * from big_table where country_column = package.get_current_country and select * from big_table where country_column = sys_context('App_Ctx', 'current_country')  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 10. Create the HRM_CTX Context  create or replace context hrm_ctx using hrm_pkg create or replace package body hrm_pkg is procedure set_language (p_language in varchar2) is begin dbms_session.set_context ('HRM_CTX' , 'LANGUAGE' ,p_language); end set_language; procedure clear_context is begin dbms_session.clear_context('HRM_CTX'); end; ... select * from session_context  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 11. Create the HRM_CTX Context   Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 12. Use cases for Application Context   Programmable/Configurable View  Meta Data Interface between Application and Database  Client User Identity – and other environment settings • Get rid of hard coded references to USER!  Instrumentation  Setting default values  Cache for ‘expensive’ and/or ‘shared’ values  Foundation for VPD  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 13. Configurable View   Generic challenge: create a view that has run-time parameters governing its behavior  For example:  View EMP_REPORT_VW  Returns the Average Salary and Number of Employees • Per Job and Department and Year of hiring • or: Over all Employees • or: Per Job • or: Per Department and Year of Hiring • or: any other combination  It depends on the caller which should be the case! • The caller should provide ‘input parameters’ to get the desired behavior from this view  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 15. Approach this challenge   Clearly this view uses data from meta data environment  That indicates which column(s) to group by  The view accesses this data from an Application Context using SYS_CONTEXT  Setting the data is done through a simple call to a package, preceding the query against the view  Note: for client technologies that have a problem calling PL/SQL packages, we could create a View called EMP_REPORT_VW_PARAMETERS with an INSTEAD OF trigger that will convert an update of a parameter to a call to the package that controls the Application Context.  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 17. Implementing Configurable View (2)  If group by department, then show deptno If group by department, then group by deptno else group by null (which has no effect)  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 18. Calling the configurable view   Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 19. The client is always right   What time is it  or at least what is the client’s timezone  What locale is it  which language/regional settings apply  Where is it located  what is the geographical location  Who is it  web user’s identity <> any database user  Note: The database can only serve!  Following the client’s lead  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 20. USER <> CLIENT_IDENTIFIER  Client  Many – and ever more – applications make use of light-weight users LDAP  That do not correspond J(2)EE Application Server to database users Web  These applications will Application inform the database through setting the Client Identifier about the user  Referring to USER is (ever APPLICATION_ more) meaningless! SCHEMA USERENV  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 21. Set Client Identifier with Light Weight User   In Java using Oracle JDBC Driver conn.setClientIdentifier(quot;john.doequot;)  In PL/SQL DBMS_SESSION.SET_IDENTIFIER( 'john.doe');  Or use a logon trigger to derive the client identifier CREATE OR REPLACE TRIGGER logon_trigger AFTER LOGON ON DATABASE DECLARE uid VARCHAR2(64); BEGIN SELECT ora_login_user ||':' ||SYS_CONTEXT('USERENV', 'OS_USER') INTO uid FROM dual; dbms_session.set_identifier(uid); END logon_trigger;  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 22. Set Client Identifier with Light Weight User   In the database – SQL or PL/SQL – the current client identifier can be read like this: SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER')  The Client Identifier is also available in V$SESSION SELECT sid, client_identifier, service_name FROM v_$session; as well as V$SQLAREA  DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE allows for tracing all activity of a CLIENT_IDENTIIER aka light-weight user  Note: Oracle standard auditing does not use CLIENT_IDENTIFIER  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 23. A properly instrumented application...   Should tell the database  Who is the actual user for whom it is running  Which Module requests database actions & for what purpose  (optionally) Additional information about the client begin dbms_application_info.set_module ( module_name => 'MODULE_NAME' , action_name => 'What is the module doing' ); -- sets columns Module&Action in V$SESSION view dbms_application_info.set_client_info ( client_info => 'extra info e.g. Task Context' ); -- no longer than 64 chars, sets column Client -- Info in the V$SESSION view dbms_session.set_identifier('id for real user'); -- sets v$session view column CLIENT_IDENTIFIER end;  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 24. Guideline: provide application with Instrumentation API   Define an API (PL/SQL procedure) that applications can call to provide all instrumentation information  This API will take care of setting the proper values J(2)EE Application Server in Application Context and through Web Application dbms_application_info  Requires but a single call INSTRUMENTATION_API dbms_ dbms_ application_ session info  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 25. Retrieving the ‘instrumented values’  select sys_context('USERENV','sid') sid , sys_context('USERENV','module') module , sys_context('USERENV','action') action , sys_context('USERENV','client_identifier') client_identifier , sys_context('USERENV','client_info') client_info from dual / select sid , module , client_identifier , client_info , action from v$session /  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 26. Default values for audit columns   The default value of a column can be specified using a reference to an application context: CREATE TABLE IMPORTANT_RECORDS ( ... , USER_CREATED VARCHAR2(100) DEFAULT SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER')  That can be a reference to a user defined context too: CREATE TABLE IMPORTANT_RECORDS ( ... , PRICE VARCHAR2(100) DEFAULT SYS_CONTEXT('ORDER_APP','CURRENT_PRICE')  Note: you can refer to default in UPDATE statement UPDATE IMPORTANT_RECORDS SET PRICE = DEFAULT WHERE ...  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 27. Create Context as Globally Accessible   Accessible throughout the entire instance:  Every session can retrieve values  Stored in SGA (instead of UGA) • A big difference compared to package variables!!  For global settings, cross application parameters • For example once-per-day calculated or retrieved (from web services?) values that remain available throughout the day  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 29. Globally Accessible: Accessing Values   Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 30. Application Context values associated with Client Identifier   Application Context can be private (tied to a session) or globally accessible (across all sessions)  Third option: attributes associated with Client Identifier:  only sessions with the same Client Identifier can access an those attributes of such a context dbms_session.set_context ( namespace=> 'HRM_CTX' , attribute => 'my_org_id' , value=> '67' , client_id => sys_context('USERENV','CLIENT_IDENTIFIER') );  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 31. Application Context associated with Client Identifier   Retrieving session specific values is handled by the database automatically, using the CLIENT_IDENTIFIER SYS_CONTEXT('HRM_CTX', 'my_ord_id')  If HRM_CTX has a value associated with the client identifier, it is returned; otherwise the non associated value is returned  To remove all values tied to a specific client_identifier from an application context: ... –- still package hrm_pkg managing HRM_CTX procedure clear_context is begin dbms_session.clear_context('HRM_CTX' , sys_context('USERENV','CLIENT_IDENTIFIER') ); end;  Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009
  • 32. Summary   An Application Context is a named in-memory set of key-value pairs  Application Context value references in SQL queries are processed like bind parameters  A Context is by default associated with a single session  Alternatively a context can be global (cross session) or associated with a Client Identifier  Application Context is used for Exposing System and Session attributes (USERENV)  Configurable Views  Application to Database meta data interface  Global cross-session shared in memory cache  Virtual Private Database   Application Context Lucas Jellema, KC Server Development – PL/SQL Potpourri, 20th Januariy2009