18 Configuring Applications With Data Cartridges

This chapter describes how to configure the Oracle JDBC cartridge and Oracle Spatial cartridge, which extend Oracle Continuous Query Language (CQL), for use with Oracle Event Processing.

This chapter includes the following sections:

For more information on data cartridges, see "Introduction to Data Cartridges" in the Oracle Fusion Middleware CQL Language Reference for Oracle Event Processing.

18.1 Understanding Data Cartridge Application Context

Depending on the data cartridge implementation, you may be able to define an application context that the Oracle Event Processing server propagates to an instance of the data cartridge and the complex objects it provides.

You may configure an application context for the following data cartridges:

For more information on data cartridges, see "Introduction to Data Cartridges" in the Oracle Fusion Middleware CQL Language Reference for Oracle Event Processing.

18.2 How to Configure Oracle Spatial Application Context

You define an application context for an instance of Oracle Spatial using element spatial:context in your Oracle Event Processing application's Event Processing Network (EPN) assembly file.

All constructors and methods from com.oracle.cartridge.spatial.Geometry and Oracle Spatial functions are aware of spatial:context. For example, the SRID is automatically set from the value in the Oracle Spatial application context.

For more information, see:

To configure Oracle Spatial application context:

  1. Open the EPN editor in the Oracle Event Processing IDE for Eclipse.

    See Section 7.1, "Opening the EPN Editor".

  2. Import the package com.oracle.cep.cartridge.spatial into your Oracle Event Processing application's MANIFEST.MF file.

    For more information, see Section 5.7.5, "How to Import a Package".

  3. Right-click any component and select Go to Assembly Source.

  4. Edit the EPN file to add the required namespace and schema location entries as Example 18-1 shows:

    Example 18-1 EPN Assembly File: Oracle Spatial Namespace and Schema Location

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:osgi="http://www.springframework.org/schema/osgi"
           xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
           xmlns:spatial="http://www.oracle.com/ns/ocep/spatial/"
           xsi:schemaLocation="
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/osgi
      http://www.springframework.org/schema/osgi/spring-osgi.xsd
      http://www.bea.com/ns/wlevs/spring
      http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_6.xsd"
      http://www.oracle.com/ns/ocep/spatial
      http://www.oracle.com/ns/ocep/spatial/ocep-spatial.xsd">
    
  5. Edit the EPN file to add a spatial:context element as Example 18-2 shows.

    Example 18-2 spatial:context Element in EPN Assembly File

    <spatial:context id="SpatialGRS80" />
    
  6. Assign a value to the id attribute that is unique in this EPN.

    This is the name you will use to reference this application context in subsequent Oracle CQL queries. In Example 18-2, the id is SpatialGRS80.

    Note:

    The id value must not equal the Oracle Spatial name spatial. For more information, see "Data Cartridge Name" in the Oracle Fusion Middleware CQL Language Reference for Oracle Event Processing.
  7. Configure the other attributes of the spatial:context element to suit your application requirements.

    Table 18-1 lists the attributes of the spatial:context element.

    Table 18-1 spatial:context Element Attributes

    Attribute Description

    anyinteract-tolerance

    The default tolerance for contain or inside operator.

    Default: 0.0000005

    rof

    Defines the Reciprocal Of Flattening (ROF) parameter used for buffering and projection.

    Default: 298.257223563

    sma

    Defines the Semi-Major Axis (SMA) parameter used for buffering and projection.

    Default: 6378137.0

    srid

    SRID integer. Valid values are:

    • CARTESIAN: for cartesian coordinate system.

    • LAT_LNG_WGS84_SRID: for WGS84 coordinate system.

    • An integer value from the Oracle Spatial SDO_COORD_SYS table COORD_SYS_ID column.

    Default : LAT_LNG_WGS84_SRID

    tolerance

    The minimum distance to be ignored in geometric operations including buffering.

    Default: 0.000000001


    Example 18-3 shows how to create a spatial context named SpatialGRS80 in an EPN assembly file using the Geodetic Reference System 1980 (GRS80) coordinate system (srid="4269").

    Example 18-3 spatial:context Element in EPN Assembly File

    <spatial:context id="SpatialGRS80" srid="4269" sma="63787.0" rof="298.25722101" />
    
  8. Create Oracle CQL queries that reference this application context by name.

    Example 18-4 shows how to reference a spatial:context in an Oracle CQL query. In this case, the query uses link name SpatialGRS80 (defined in Example 18-2) to propagate this application context to the Oracle Spatial. The spatial:context attribute settings of SpatialGRS80 are applied to the createPoint method call. Because the application context defines the SRID, you do not need to pass that argument into the createPoint method.

    Example 18-4 Referencing spatial:context in an Oracle CQL Query

    <view  id=”createPoint”>
        select com.oracle.cep.cartridge.spatial.Geometry.createPoint@SpatialGRS80(lng, lat, 0d)
        from CustomerPos[NOW]
    </view>
    

    For more information, see "Using Oracle Spatial" in the Oracle Fusion Middleware CQL Language Reference for Oracle Event Processing.

18.3 How to Configure Oracle JDBC Data Cartridge Application Context

You define an application context for an instance of an Oracle JDBC data cartridge using:

  • A jdbc:jdbc-context element in the EPN assembly file.

  • A jc:jdbc-ctx element in the component configuration file.

    The jc:jdbc-ctx element:

    • references one and only one jdbc:jdbc-context

    • references one and only one data-source

    • defines one or more SQL functions

Note:

You must provide alias names for every SELECT list column in the SQL function.

For more information see, "Understanding the Oracle JDBC Data Cartridge" in the Oracle Fusion Middleware CQL Language Reference for Oracle Event Processing.

To configure Oracle JDBC data cartridge application context:

  1. Open the EPN editor in the Oracle Event Processing IDE for Eclipse.

    See Section 7.1, "Opening the EPN Editor".

  2. Right-click any component and select Go to Assembly Source.

  3. Edit the EPN file to add the required namespace and schema location entries as Example 18-5 shows:

    Example 18-5 EPN Assembly File: Oracle JDBC Data Cartridge Namespace and Schema Location

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:osgi="http://www.springframework.org/schema/osgi"
           xmlns:wlevs="http://www.bea.com/ns/wlevs/spring"
           xmlns:jdbc="http://www.oracle.com/ns/ocep/jdbc/"
           xsi:schemaLocation="
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/osgi
      http://www.springframework.org/schema/osgi/spring-osgi.xsd
      http://www.bea.com/ns/wlevs/spring
      http://www.bea.com/ns/wlevs/spring/spring-wlevs-v11_1_1_6.xsd"
      http://www.oracle.com/ns/ocep/jdbc
      http://www.oracle.com/ns/ocep/jdbc/ocep-jdbc.xsd">
    
  4. Edit the EPN file to add a jdbc:jdbc-context element as Example 18-6 shows.

    Example 18-6 jdbc:jdbc-context Element in EPN Assembly File: id

    <jdbc:jdbc-context id="JdbcCartridgeOne"/>
    
  5. Assign a value to the id attribute that is unique in this EPN.

    This is the name you will use to reference this application context in subsequent Oracle CQL queries. In Example 18-6, the id is JdbcCartridgeOne.

    Note:

    The id value must not equal the Oracle JDBC data cartridge name jdbc. For more information, see "Data Cartridge Name" in the Oracle Fusion Middleware CQL Language Reference for Oracle Event Processing.
  6. Right-click the desired processor and select Go to Configuration Source.

  7. Edit the component configuration file to add the required namespace entries as Example 18-7 shows:

    Example 18-7 Component Configuration File: Oracle JDBC Data Cartridge Namespace

    <?xml version="1.0" encoding="UTF-8"?>
    <wlevs:config
        xmlns:wlevs="http://www.bea.com/ns/wlevs/config/application"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:jc="http://www.oracle.com/ns/ocep/config/jdbc
        xsi:schemaLocation="
            http://www.oracle.com/ns/ocep/config/jdbc
            http://www.oracle.com/ns/ocep/config/jdbc/ocep_jdbc_context.xsd">
    
  8. Edit the component configuration file to add a jc:jdbc-ctx element as Example 18-8 shows.

    Example 18-8 jc:jdbc-ctx Element in Component Configuration File

    <jc:jdbc-ctx>
    </jc:jdbc-ctx>
    
  9. Add a name child element whose value is the name of the Oracle JDBC application context you defined in the EPN assembly file as Example 18-9 shows.

    Example 18-9 jc:jdbc-ctx Element in Component Configuration File: name

    <jc:jdbc-ctx>
        <name>JdbcCartridgeOne</name>
    </jc:jdbc-ctx>
    
  10. Add a data-source child element whose value is the name of a datasource defined in the Oracle Event Processing server config.xml file.

    For more information, see:

    Example 18-10 shows how to specify the datasource named StockDS.

    Example 18-10 jc:jdbc-ctx Element in Component Configuration File: data-source

    <jc:jdbc-ctx>
        <name>JdbcCartridgeOne</name> 
        <data-source>StockDS</data-source>
    </jc:jdbc-ctx>
    
  11. Create one or more SQL functions using the function child element as Example 18-11 shows.

    Example 18-11 jc:jdbc-ctx Element in Component Configuration File: function

    <jc:jdbc-ctx>
        <name>JdbcCartridgeOne</name> 
        <data-source>StockDS</data-source>
        <function name="getDetailsByOrderIdName">
            <param name="inpOrderId" type="int" />
            <param name="inpName" type="char" />
            <return-component-type>
                com.oracle.cep.example.jdbc_cartridge.RetEvent
            </return-component-type>
            <sql><![CDATA[
                SELECT
                    Employee.empName as employeeName,
                    Employee.empEmail as employeeEmail,
                    OrderDetails.description as description
                FROM
                     PlacedOrders, OrderDetails , Employee
                WHERE
                    PlacedOrders.empId = Employee.empId AND
                    PlacedOrders.orderId = OrderDetails.orderId AND
                    Employee.empName = :inpName AND
                    PlacedOrders.orderId = :inpOrderId
            ]]></sql>
        </function>
    </jc:jdbc-ctx>
    

    Note:

    You must provide alias names for every SELECT list column in the SQL query.

    For more information, see "Defining SQL Statements" in the Oracle Fusion Middleware CQL Language Reference for Oracle Event Processing.

  12. Create Oracle CQL queries that invoke the SQL functions using the Oracle JDBC data cartridge application context.

    Example 18-12 shows how to reference a jdbc:jdbc-context in an Oracle CQL query. In this case, the query uses link name JdbcCartridgeOne (defined in Example 18-11) to propagate this application context to the Oracle JDBC data cartridge. The Oracle CQL query in Example 18-12 invokes the function getDetailsByOrderIdName defined by Oracle JDBC data cartridge context JdbcCartridgeOne.

    Example 18-12 Referencing JDBC Application Context in an Oracle CQL Query

    <processor>
            <name>Proc</name>
            <rules>
                <query id="q1"><![CDATA[
                    RStream(
                       select
                         currentOrder.orderId,
                         details.orderInfo.employeeName,
                         details.orderInfo.employeeemail,
                         details.orderInfo.description
                       from
                         OrderArrival[now] as currentOrder,
                         TABLE(getDetailsByOrderIdName@JdbcCartridgeOne(
                                   currentOrder.orderId, currentOrder.empName
                               ) as orderInfo
                         ) as details
                    )
                ]]></query>
            </rules>
    </processor>
    

    For more information see, "Defining Oracle CQL Queries With the Oracle JDBC Data Cartridge" in the Oracle Fusion Middleware CQL Language Reference for Oracle Event Processing.