Handling Other Event Properties Using a User-Defined Function

1-6 Oracle Complex Event Processing EPL Language Reference The preceding query is equivalent to the following: SELECT detail?.direction? FROM OrderEvent RETAIN ALL EVENTS The following functions are often useful in conjunction with dynamic properties: ■ The CAST function casts the value of a dynamic property or the value of an expression to a given type. See Section 4.1.7, The CAST Function. ■ The EXISTS function checks whether a dynamic property exists. It returns true if the event has a property of that name, or false if the property does not exist on that event. See Section 4.1.8, The EXISTS Function. ■ The INSTANCEOF function checks whether the value of a dynamic property or the value of an expression is of any of the given types. See Section 4.1.6, The INSTANCEOF Function.

1.2.6 Handling Other Event Properties Using a User-Defined Function

If your event uses a datatype that EPL does not support, you can create a user-defined function to evaluate that datatype in an EPL query. Consider the enum datatype that Example 1–1 shows. The event that Example 1–2 shows uses this enum datatype. EPL does not support enum datatypes. Example 1–1 Enum Datatype ProcessStatus package com.oracle.app; public enum ProcessStatus { OPEN1, CLOSED0} } Example 1–2 Event Using Enum Datatype ProcessStatus package com.oracle.app; import com.oracle.capp.ProcessStatus; public class ServiceOrder { private String serviceOrderId; private String electronicSerialNumber; private ProcessStatus status; ... } By creating the user-defined function that Example 1–3 shows and registering the function in your application assembly file as Example 1–4 shows, you can evaluate this enum datatype in an EPL query as Example 1–5 shows. Example 1–3 User-Defined Function to Evaluate Enum Datatype package com.oracle.app; import com.oracle.capp.ProcessStatus; public class CheckIfStatusClosed { public boolean executeObject[] args { ProcessStatus arg0 = ProcessStatusargs[0]; if arg0 == ProcessStatus.OPEN return Boolean.FALSE; Overview of the Event Processing Language EPL 1-7 else return Boolean.TRUE; } } Example 1–4 Registering the User-Defined Function in Application Assembly File wlevs:processor id=testProcessor wlevs:listener ref=providerCache wlevs:listener ref=outputCache wlevs:cache-source ref=testCache wlevs:function function-name=statusClosed exec-method=”execute” bean class=com.oracle.app.CheckIfStatusClosed wlevs:function wlevs:processor Example 1–5 Using the User-Defined Function to Evaluate Enum Datatype in an EPL Query query id=rule-04[CDATA[ SELECT meter.electronicSerialNumber, meter.exceptionKind FROM MeterLogEvent AS meter, ServiceOrder AS svco WHERE meter.electronicSerialNumber = svco.electronicSerialNumber and svco.serviceOrderId IS NULL OR statusClosedsvco.status ]]query For more information, see Chapter 4, EPL Reference: Functions .

1.2.7 Event Sinks