How to Access a Cache From an Oracle CQL Statement

Configuring Caching 12-33 3. In the EPN assembly file, update the configuration of the cache in the EPN assembly file to declare the event type of its values; use the value-type attribute of the wlevs:cache element. For example: wlevs:caching-system id=caching-system-id ... wlevs:cache id=cache-id name=alternative-cache-name value-type=Company wlevs:caching-system ref=caching-system-id wlevs:cache The value-type attribute specifies the type for the values contained in the cache. This must be a valid type name in the event type repository. This attribute is required only if the cache is referenced in an EPL query. This is because the query processor needs to know the type of events in the cache. 4. In the EPN assembly file, update the configuration of the processor that executes the EPL query that references a cache, adding a wlevs:cache-source child element that references the cache. For example: wlevs:channel id=stream-id wlevs:processor id=processor-id wlevs:cache-source ref=cache-id wlevs:source ref=stream-id wlevs:processor In the example, the processor will have data pushed to it from the stream-id channel as usual; however, the EPL queries that execute in the processor can also pull data from the cache-id cache. When the query processor matches an event type in the FROM clause to an event type supplied by a cache, such as Company, the processor pulls instances of that event type from the cache.

12.7 Accessing a Cache From an Adapter

An adapter can also be injected with a cache using the standard Spring mechanism for referencing another bean. A cache bean implements the java.util.Map interface which is what the adapter uses to access the injected cache. First, the configuration of the adapter in the EPN assembly file must be updated with a wlevs:instance-property child element, as shown in the following example: wlevs:caching-system id=caching-system-id ... wlevs:cache id=cache-id name=alternative-cache-name wlevs:caching-system ref=caching-system-id wlevs:cache ... wlevs:adapter id=myAdapter provider=myProvider wlevs:instance-property name=map ref=cache-id wlevs:adapter In the example, the ref attribute of wlevs:instance-property references the id value of the wlevs:cache element. Oracle CEP automatically injects the cache, implemented as a java.util.Map, into the adapter. In the adapter Java source, add a setMap Map method with the code that implements whatever you want the adapter to do with the cache: package com.bea.wlevs.example; … 12-34 Oracle Complex Event Processing Developers Guide import java.util.Map; public class MyAdapter implements Runnable, Adapter, EventSource, SuspendableBean { ... public void setMap Map map {...} } 12.8 Accessing a Cache From a Business POJO A business POJO, configured as a standard Spring bean in the EPN assembly file, can be injected with a cache using the standard Spring mechanism for referencing another bean. In this way the POJO can view and manipulate the cache. A cache bean implements the java.util.Map interface which is what the business POJO uses to access the injected cache. A cache bean can also implement a vendor-specific sub-interface of java.util.Map, but for portability it is recommended that you implement Map. First, the configuration of the business POJO in the EPN assembly file must be updated with a property child element, as shown in the following example based on the Output bean of the FX example see HelloWorld Example in the Oracle Complex Event Processing Getting Started: wlevs:caching-system id=caching-system-id ... wlevs:cache id=cache-id name=alternative-cache-name wlevs:caching-system ref=caching-system-id wlevs:cache ... bean class=com.bea.wlevs.example.helloworld.HelloWorldBean property name=map ref=cache-id bean In the example, the ref attribute of the property element references the id value of the wlevs:cache element. Oracle CEP automatically injects the cache, implemented as a java.util.Map, into the business POJO bean. In the business POJO bean Java source, add a setMap Map method with the code that implements whatever you want the POJO to do with the cache: package com.bea.wlevs.example.helloworld; … import java.util.Map; public class HelloWorldBean implements EventSink { ... public void setMap Map map {...} } 12.9 Accessing a Cache From an Oracle CQL User-Defined Function In addition to standard event streams, Oracle CQL rules can also invoke the member methods of a user-defined function. These user-defined functions are implemented as standard Java classes and are declared in the component configuration file of the Oracle CQL processor, as shown in the following example: bean id=orderFunction class=orderFunction-impl-class The processor in which the relevant Oracle CQL rule runs must then be injected with the user-defined function using the wlevs:function child element, referencing the Spring bean with the ref attribute: wlevs:processor id= tradeProcessor