1-4 Oracle Complex Event Processing EPL Language Reference
language primitive types such as int or String. The Address object and Employee objects can themselves have properties that are nested within them, such as
a street-Name in the Address object or a name of the employee in the Employee object.
public class EmployeeEvent { public String getFirstName;
public Address getAddressString type; public Employee getSubordinateint index;
public Employee[] getAllSubordinates; }
Simple event properties require a getter-method that returns the property value. In the preceding example, the getFirstName getter method returns the firstName event
property of type String.
Indexed event properties require either one of the following getter-methods:
■
A method that takes an integer type key value and returns the property value, such as the getSubordinate method.
■
A method returns an array-type such as the getAllSubordinates getter method, which returns an array of Employee.
In an EPL statement, indexed properties are accessed via the property[index] syntax.
Mapped event properties require a getter-method that takes a String type key value and returns a property value, such as the getAddress method. In an EPL or event
pattern statement, mapped properties are accessed via the property key syntax.
Nested event properties require a getter-method that returns the nesting object. The getAddress and getSubordinate methods are mapped and indexed properties
that return a nesting object. In an EPL statement, nested properties are accessed via the property.nestedProperty syntax.
All EPL statements allow the use of indexed, mapped and nested properties or a combination of these at any place where one or more event property names are
expected. The example below shows different combinations of indexed, mapped and nested properties.
addresshome.streetName subordinate[0].name=anotherName
allSubordinates[1].name subordinate[0].addresshome.streetName
Similarly, the syntax can be used in EPL statements in all places where an event property name is expected, such as in select lists, where clauses or join criteria.
SELECT firstName, addresswork, subordinate[0].name, subordinate[1].name FROM EmployeeEvent RETAIN ALL
WHERE addresswork.streetName = Park Ave
1.2.5 Dynamic Event Properties
Dynamic or unchecked properties are event properties that need not be known at statement compilation time. Oracle CEP resolves these dynamic properties during
runtime.
The idea behind dynamic properties is that for a given underlying event representation, the properties are not necessarily known in advance. An underlying
Overview of the Event Processing Language EPL 1-5
event may have additional properties that are not known at statement compilation time, and these properties might need to be queried on using an EPL statement. The
concept is especially useful for events that represent rich, object-oriented domain models.
The syntax of dynamic properties consists of the property name and a question mark. Indexed, mapped and nested properties can also be dynamic properties. The following
table describes the types of dynamic event properties and the syntax used to identify them.
Dynamic properties always return the java.lang.Object type. Dynamic properties return a null value if the dynamic property does not exist on the events processed at
runtime.
For example, consider an OrderEvent event that provides an item property. The item property is of type Object and holds a reference to an instance of either a
Service or Product; which one is known only at runtime. Further assume that both the Service and Product classes provide a property named price. Using a
dynamic property, you can specify a query that obtains the price property from either object Service or Product, as shown in the following example:
SELECT item.price? FROM OrderEvent RETAIN ALL EVENTS
As a second example, assume that the Service class contains a serviceName property that the Product class does not contain. At runtime, the following query
returns the value of the serviceName property for Service objects; if, however, the query is run against a Product object, the query returns a null value because
Products do not contain the serviceName property:
SELECT item.serviceName? FROM OrderEvent RETAIN ALL EVENTS
Now consider the case where OrderEvent has multiple implementation classes, only some of which have a timestamp property. The following query returns the
timestamp property of those implementations of the OrderEvent interface that feature the property:
SELECT timestamp? FROM OrderEvent RETAIN ALL EVENTS
The preceding query returns a single column named timestamp? of type java.lang.Object.
When you nest dynamic properties, all properties under the dynamic property are also considered dynamic properties. In the next example, the query asks for the
direction property of the object returned by the detail dynamic property:
SELECT detail?.direction FROM OrderEvent RETAIN ALL EVENTS
Table 1–3 Syntax of Dynamic Properties
Event Property Type Syntax
Dynamic Simple
name?
Dynamic Indexed
name[index]?
Dynamic Mapped
namekey?
Dynamic Nested
name?.nestedPropertyName
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