6 Oracle Java Data Cartridge
How to use the Oracle Java Data Cartridge, an extension of Oracle Continuous Query Language (Oracle CQL). You can use Oracle CQL to write CQL code that interacts with Java classes in your Oracle Stream Explorer application is described.
This chapter describes the types, methods, fields, and constructors that the Oracle Java data cartridge exposes. You can use these types, methods, fields, and constructors in Oracle CQL queries and views as you would Oracle CQL native types.
This chapter includes the following sections:
6.1 Understanding the Oracle Java Data Cartridge
The Oracle Java data cartridge is a built-in Java cartridge that enables you to write Oracle CQL queries and views that interact with the Java classes in your Oracle Stream Explorer application.
6.1.1 Data Cartridge Name
The Oracle Java data cartridge uses the cartridge ID com.oracle.cep.cartrdiges.java
.
The Oracle Java data cartridge is the default Oracle Stream Analytics data cartridge.
For types under the default Java package name or types under the system package of java.lang
, you can reference the Java type in an Oracle CQL query unqualified by package or data cartridge name:
<query id="q1"><
Description of "Figure 6-1 Example Oracle Stream Analytics Event Processing Applications"
Table 6-1 summarizes which classes these two different applications can access depending on whether they are running in the application class space or server class space.
Table 6-1 Class Accessibility by Class Loading Policy
Class Loading Policy | Application B1 | Application B2 |
---|---|---|
Application Class Space |
|
|
Server Class Space |
|
|
In application B1, you can use any of the Java classes A, B, and C in your Oracle CQL queries:
select A …
select B …
select C …
However, in application B2, you cannot use Java classes A and B in your Oracle CQL queries. You can only use Java classes C and D:
select C …
select D …
6.1.3 Method Resolution
An Oracle CQL expression that accesses a Java method uses the following algorithm to resolve the method:
Note:
Variable arity methods are not supported. For more information, see the Java Language Specification, Third Edition, Section 12.12.2.4.
As an example, consider the following Oracle CQL expression:
attribute.methodA(10)
Where attribute
is of type mypackage.MyType
which defines the following overloaded methods:
-
methodA(int)
-
methodA(Integer)
-
methodA(Object)
-
methodA(long)
As the literal 10 is of the primitive type int
, the order of precedence is:
-
methodA(int)
-
methodA(long)
-
methodA(Integer)
-
methodA(Object)
For more information, see Class Loading.
6.1.4 Datatype Mapping
The Oracle Java data cartridge applies a fixed, asymmetrical mapping between Oracle CQL native data types and Java data types.
Table 6-2 Oracle Java Data Cartridge: Oracle CQL to Java Data Type Mapping
Oracle CQL Native Data Type | Java Data Type |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table 6-3 Oracle Java Data Cartridge: Java Data Type to Oracle CQL Mapping
Java Datatype | Oracle CQL Native Data Type |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
All other Java classes are mapped as a complex type.
For more information on these datatype mappings:
6.1.4.1 Java Data Type String and Oracle CQL Data Type CHAR
Oracle CQL data type CHAR
is mapped to java.lang.String
and java.lang.String
is mapped to Oracle CQL data type CHAR
. This means you can access java.lang.String
member fields and methods for an attribute defined as Oracle CQL CHAR
. For example, if a1
is declared as type Oracle CQL CHAR
, then you can write a query like this:
<query id="q1"><![CDATA[
select a1.substring(1,2)
></query>
6.1.4.2 Literals
You cannot access member fields and methods on literals, even Oracle CQL CHAR
literals. For example, the following query is not allowed:
<query id="q1-forbidden"><![CDATA[
select "hello".substring(1,2)
></query>
6.1.4.3 Arrays
Java arrays are converted to Oracle CQL data cartridge arrays, and Oracle CQL data cartridge arrays are converted to Java arrays. This applies to both complex types and simple types.
You can use the data cartridge TABLE
clause to access the multiple rows returned by a data cartridge function in the FROM
clause of an Oracle CQL query.
For more information, see Collections.
6.1.4.4 Collections
Typically, the Oracle Java data cartridge converts an instance that implements the java.util.Collection
interface to an Oracle CQL complex type.
An Oracle CQL query can iterate through the members of the java.util.Collection
.
You can use the data cartridge TABLE
clause to access the multiple rows returned by a data cartridge function in the FROM
clause of an Oracle CQL query.
For more information, see Arrays.
6.1.5 Oracle CQL Query Support for the Oracle Java Data Cartridge
You may use Oracle Java data cartridge types in expressions within a SELECT
clause and WHERE
clause.
You may not use Oracle Java data cartridge types in expressions within an ORDER BY
clause.
For more information, see Using the Oracle Java Data Cartridge.
6.2 Using the Oracle Java Data Cartridge
Common use-cases that highlight how you can use the Oracle Java data cartridge in your Oracle Stream Analytics applications are described.
For more information, see Oracle CQL Query Support for the Oracle Java Data Cartridge.
6.2.1 How to Query Using the Java API
This procedure describes how to use the Oracle Java data cartridge in an Oracle Stream Explorer application that uses one event type defined as a tuple (Student
) that has an event property type defined as a Java class (Address.java
).
To query with Java classes:
6.2.2 How to Query Using Exported Java Classes
This procedure describes how to use the Oracle Java data cartridge in an Oracle Stream Analytics application that uses one event type defined as a tuple (Student
) that has an event property type defined as a Java class (Address.java
). In this procedure, the Address.java class belongs to a separate Oracle Stream Analytics application. It is exported in its parent application to make it accessible to other Oracle Stream Analytics applications deployed to the same Oracle Stream Analytics server.
To query with Java classes:
6.2.3 Java Cast Function
The Java cartridge provides the Java Cast function that enables a Java extensible type to be cast to another Java extensible type, providing the latter can be assigned from the former. To use this function, you must have the Java cartridge installed.
Syntax
T cast@java(l-value, class-literal<T>)
Parameters
l-value
: A event attribute that contains the data that you want to cast. If l-value
cannot be assigned from T
, then Java Cartridge raises a RuntimeInvocationException
during the invocation of the cast function
class-literal<T>
: The name of the class to which you want to cast. For example, if you want to cast an int
to long
, then class-literal<T>
is Long.class
.
Example
Consider the following class hierarchy:
public class Parent { ... } public class Child extends Parent { ... }
The following example casts an object of type Child
.
cast@java(S.parent, Child.class)