Reading String Array from cache in CQL - Complex Event Processing

Hi,
I am trying to read data from local cahce in CQL
Got two attributes in local CacheObject i.e myKey , String[] array
In the Loader
i am setting map.put(cacheObject.getMyKey,cacheObject);
In CQL trying to read the cache data
My CQL query looks like::
select
inputChannel.myKey ,
MyCache.array as array
from inputChannel [now],MyCache
where inputChannel.myKey = MyCache.myKey
The channel after this processor maps to OutputEvent Bean.
Which has setter getter for this myKey , String[] array.
But in the OutputLogBean i am getting the value of this array as null.
Can anyone tell me does that CQL supports reading String[] object, if yes does it require any configuration 

Hi,
In CQL we cannot process of String[] data type.
I think it reads and writes only primitive data types and there respective wrapper class.
And as far i know it will also not process user defined objects.
Regards,
XXX 

In 11gR1 (and 11gR1 PS1), the following approach should help meet this requirement -
1) In the event-type associated with MyCache, the datatype of "MyCache.array" should be "java.lang.Object". You can continue to store String[] in the cache.
2) Now consider your query
select
inputChannel.myKey ,
MyCache.array as array
from inputChannel [now],MyCache
where inputChannel.myKey = MyCache.myKey
3) The attribute in "OutputEvent" corresponding to "array" (in the query's select list) should also have datatype "java.lang.Object"
4) In the "OutputLogBean" (I assume this is the bean that is downstream to the processor with the query), cast the "array" attribite to String[] (or any other user Java class that you would expect) and then continue with rest of your processing.
In the upcoming release, there will be more native support for Java classes and arrays.

Related

How to properly create complex OCI objects (for Annotation Text)

I am upgrading a tool that will upload text objects to a table with a ST_ANNOTATION_TEXT field. The app is a C++ app and I need to instantiate a ST_ANNOTATION_TEXT (using OCIObjectNew??). I actually have 2 questions. First, does anyone have an example of how to accomplish this? I seem to be unable to correctly create the annotation text type in C++ to be able to append to (calling OCICollAppend). Second, since ST_ANNOTATION_TEXT is a complex type (contains an array of annotation text elements), do I need to call OCIObjectNew on not only the main ST_ANNOTATION_TEXT type but also for the ST_ANNOTATIONTEXTELEMENT_ARRAY, ST_ANNOT_TEXTELEMENT_ARRAY, and the ST_ANNOTATIONTEXTELEMENT?
I can't seem to find in info on this so hopefully someone else has been through this. 
user3068343 wrote:
I am upgrading a tool that will upload text objects to a table with a ST_ANNOTATION_TEXT field. The app is a C++ app and I need to instantiate a ST_ANNOTATION_TEXT (using OCIObjectNew??).Note that this is the forum for the C++ OCCI API, while OCIObjectNew is part of the C OCI API which has its own forum Oracle Call Interface (OCI) (OCI can be used in C or C++ indeed).
user3068343 wrote:
First, does anyone have an example of how to accomplish this? I seem to be unable to correctly create the annotation text type in C++ to be able to append to (calling OCICollAppend).You could have a look ar md\demo\examples in your server install, which has Oracle Spatial example also using objects.
user3068343 wrote:
Second, since ST_ANNOTATION_TEXT is a complex type (contains an array of annotation text elements), do I need to call OCIObjectNew on not only the main ST_ANNOTATION_TEXT type but also for the ST_ANNOTATIONTEXTELEMENT_ARRAY, ST_ANNOT_TEXTELEMENT_ARRAY, and the ST_ANNOTATIONTEXTELEMENT? There are three ways that I know of, two of which I've used:
1) Create all the objects by hand. You must have the OTT (or hand) generated structs for the object types, lookup the TDO for the type, OCIObjectNew it, etc... Even then there are two variations: a) you allocate the object's top-level struct yourself (SDO_GEOMETRY in my case) in C++, but then you take responsibility of allocating / deallocating the sub-objects yourself (via OCIObjectNew). b) You let Oracle allocate the object using OCIObjectNew, in which case I believe it also allocates nested objects (in my SDO_GEOMETRY example, instantiates two empty VARRAYs for the elements and ordinates). I've used (a), and it appears to work ;-)
2) Use a SQL statement using object constructors in SQL, just as you would in SQL*Plus or PL/SQL, using bind variables when you reach primitive members you can bind simply. See how the sdo_geometry and its two nested varrays are created in SQL, and filled in with bind values below (in double quotes since that's the statement text in C++).
        "INSERT INTO vset_tab$blk (\n"
        "    OBJ_ID,\n"
        "    BLK_ID,\n"
        "    BLK_EXTENT,\n"
...
        ") values (\n"
        "    :1, :2,"
        "    sdo_geometry(\n"
        "        2003, null, null,\n"
        "        sdo_elem_info_array(1, 1003, 3),\n"
        "        sdo_ordinate_array(:3, :4, :5, :6)\n"
        "    ),\n"
...
        ")"3) A variant of (1) is to use OCIObjectGetAttr and OCIObjectSetAttr instead of manipulating the structs directly. I've never used it, but that's what http://orclib.sourceforge.net/ uses.
I hope this helps. --DD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
ddevienne:
Thanks for responding. I actually have been using your first suggestion by creating the objects by hand. I am still having an issue where the sub objects are still NULL.
I have another question regarding your response:
++a) you allocate the object's top-level struct yourself (SDO_GEOMETRY in my case) in C+++
Above you suggest creating the objects top-level struct myself. How do you create that top level object? I have been using OCIObjectNew on that object as well as its sub objects? Is that how you are creating the top-level object?
Thanks again 
user3068343 wrote:
I am still having an issue where the sub objects are still NULL.Actually I was mistaken. I must have confused getting an Object from OCIObjectNew with using one of its constructor method in a statement.
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28395/oci18nav004.htm#sthref3438 clearly state the object will have NULL attributes, unless the OCI_ATTR_OBJECT_NEWNOTNULL flag is set on the environment handle.
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28395/oci11obj.htm#i446308 further tells you what the default value for the object members will be.
An older 9i doc http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96594/adobjadv.htm#1008774 also warns about resetting the indicator struct member when you update a member of the object.
user3068343 wrote:
++a) you allocate the object's top-level struct yourself (SDO_GEOMETRY in my case) in C+++
Above you suggest creating the objects top-level struct myself. How do you create that top level object? I have been using OCIObjectNew on that object as well as its sub objects? Is that how you are creating the top-level object?This technique works only on binds, as objects you get back from defines are always allocated from the object cache. I create the top-level object directly on the stack... This is something I discovered worked, but is not documented, so you're probably on safer ground using OCIObjectNew instead.
BTW, the reason I can't easily post OCI example code is that my code uses wrappers around the objects that hides most of the OCI:
Geometry Geometry::make_point(OCIEnv* envhp, OCIError* errhp, float x, float y) {
    Geometry point_geom(envhp, errhp);
    point_geom.set_null(false);
    point_geom.gtype() = 2001;
    PointRef point = point_geom.point();
    point.set_null(false);
    point.x() = x;
    point.y() = y;
    return point_geom;
}The above creates an 2D point-type SDO_GEOMETRY hidden inside the Geometry class, itself deriving from a GeometryRef class. The latter wraps a C++ API on top of the struct pointers for a SDO_GEOMETRY/SDO_GEOMETRY_ind, while Geometry actually composes the OTT generated value/indicator structs by value, and passes addresses to its nested structs to GeometryRef (its parent class). So GeometryRef can manipulate an object irrelevant of where it was allocated, the stack or the object cache. The Geometry class is a value class, but it's useful for binds only, and like I said uses a behavior which appears to work but is not explicitly documented.
Unless you have nested objects by reference, nested objects are composed by value in the OTT-generated structs, so the space for all nested objects is already allocated after the first OCIObjectNew. But the members themselves are not initialized, and thus marked as null in the indicator struct.
In the code above, my Geometry instance is fully allocated (on the stack), but fully uninitialized (the indicator is by default set to all nulls). I first set the atomic flag to non-null, then get the Ref wrapper around its nested SDOPOINT_TYPE to also set it to non-null, and fill in the x/y member (via another NumberRef wrapper, which knows about the member and the indicator for that member, and sets it as non-null when assigned to). Notice how how I return the instance by copy: My point geometry instance doesn't have a pointer-aliasing issue here, only because its two OCIColl* are null. In the general case, you can't copy my value wrappers without making a true deep copy... But I'm getting into the weeds here.
The important point is that OCIObjectNew doesn't init the nested objects unlike what I stated earlier. Sorry for misleading you on that. --DD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      �

Document context

Is term "context" exists in BDB XML in a way of representing current position in document (I guess in XSLT way) so query can be written using relative path?
Example:
//e1[position()=3]/e2
now context on e2
./e3[#a=5]
now get e3 that have #a=5 and it is a child of e2 selected before 
Hi Philippe,
There are differences between the meaning of "context" with regard to BDB XML and XQuery:
* In the case of XQuery, context is usually only important if you want to use relative
paths or if your documents use namespaces; context defines aspects of the query that aid in query navigation (i.e.: XQuery context defines things like the namespace(s) and variables used by the query, the query's focus - which changes over the course of executing the query, and the functions and collations used by the query).
* BDB XML only supports relative paths from within a predicate; the context is a physical object (XmlQueryContext), used for very limited things (compared to what is meant by the XQuery context).
XmlQueryContext is used to control only part of the XQuery context (e.g: define the namespaces to be used by the query; define any variables that might be needed for the query - different from those used by XQuery FLWOR expressions; define the return type; defining whether the query is processed "eagerly" or "lazily").
BDB XML also uses the XmlQueryContext to identify the query's focus as you
iterate over a result set.
For the problem that you pointed out, indeed, you must use the same XmlQueryContext that you used to get the results in the first step, iterate over the result set, and query using the self access reference "./" (so that you would refer nodes relative to the current node).
Regards,
Andrei Costache, Oracle 
Thanks.
I just want to make sure I got it right.
When I'll be iterating thought XmlResults, the context stored in XmlQueryContext will change and relative path would start from the XmlValue we're currently on. Is that correct? 
This is not correct - the XmlQueryContext does not change during the execution of a query. If you have an XmlValue that you wish to use as the context item of a query, you can pass it in as a parameter to the XmlQueryExpression::execute() method. This will allow you to write paths that are relative to the XmlValue.
John

Enum JPA

Hi guys,
I need persist a field value of Enum in database, it is possible?
Any idea?
Thanks in Advance 
Yes, this should just work. Just use a Basic mapping.
If you desire to choose what database values are used, you can use an ObjectTypeConverter in TopLink/EclipseLink. (see #Converter in EclipseLink).
-- James : http://www.eclipselink.org 
Hi jsutherl,
I try use #Basic annotation, but cannot save the property value.
Example:
My enum is :
public Enum Car{
BMW(0),
MERCEDES(1);
private int value;
public Car(int value){
this.value = value;
}
}
I need persist the property "value" of Enum. How can do it? 
I'm not sure I understand, perhaps include your data-model or examples instances as well. I assume you have something like a CAR column that you want to store a 0 in if the enum is BMW and a 1 in if the enum is MERCEDES.
JPA does have a #Enumerated annotation that lets you choose to store the enum name or numerical value, so this may work. Otherwise you should be able to use an ObjectTypeConverter in TopLink/EclipseLink, either through the #Converter/#Convert annotation or a DescriptorCustomizer. 
Hi Cristiano,
JPA does not support state inside enumerated type instances, just the ordinal values of the constants defined in the type (i.e returned by the ordinal() method).
If you want to store a simple integer value then you have a few options:
1. Do not explicitly set the value, just define the enum as they typically are and let the system determine the ordinal value.
2. Just store it as an integer and have an accessor method return the enum constant for the given value. there must be a constant for each value, though.
3. Use a converter, as already suggested.
-Mike 
Another comment on this. Even though JPA does not define doing this, it does actually work in TopLink, I think because even though only the ordinal value is stored in the db, when the enum constant is instantiated again at load time the constructor is used internally so the constructed value gets put back in. In other words, unless you actually need to store the value in the db because of some other reason (external access to the database, etc) then you should be okay. 
In the Employee example I am working on for EclipseLink 1.0 I make use of an enum Gender mapped to a single character in the database. I have written up a how-to on the wiki:
http://wiki.eclipse.org/EclipseLink/Examples/JPA/EnumToCode
Doug

Legal Java Stored Procedure method parameters

Hi,
I'm trying to establish whether Java arrays can be returned from Java Stored Procedures. It seems that I can only return single length (i.e. 1) arrays which is highly restrictive.
If I am creating a Java Stored Proc that will be called from pure Stored Proc land, and my JavaSP could raise a number of exceptions I'm avoiding this and instead trying to return an "error status" as a parameter that the caller can query. i.e. I want the "error status" to be an array of (3) strings including a severity, an error number, and a string containing the Java exception.
Is there a way to do this without requiring all my methods to have 3 String[] parameters, one for each part of the error status? Or is there a better way?
regards
--malcolm                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
I am trying to solve a similar problem and from the documentation and examples that I've read so far it seems that for your JavaStoredProcedure to return an array, you have to use the oracle.sql.ARRAY class as your array and your call spec would map the oracle.sql.ARRAY to a nested table.
Good luck. 
Hi,
You could consider using object types to store your exception information. In that case you will have to use JPublisher to map the sql types to java types. JPublisher enables you to specify and customize the mapping of SQL object types, object reference types, and collection types (VARRAYs or nested tables) to Java classes.
For more info on JPublisher refer : http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96658/toc.htm
For some Java Stored Procedure samples using object types refer to http://otn.oracle.com/sample_code/tech/java/jsp/oracle9ijsp.html

Name SQL Query from Workbench

Hi,
I'm having trouble passing argument to a named query in the mapping workbench.
Here is my SQL:
select step_link.* from step_link, step
where and step.child_id = step.unique_id
and step.aq_unique_id = #aqUniqueId
and when I find and execute (attempted through various routes)...
Vector arg = new Vector();
arg.add( new Double( aq.getUniqueID() ) );
Descriptor descriptor = session.getDescriptor(StepLink.class);
DescriptorQueryManager dqm = descriptor.getQueryManager();
DatabaseQuery query = dqm.getQuery("QUERY",arg);
Object object = session.executeQuery(query);
I'm getting a null as the parameter in the logged SQL which is verified in a debugger.
I'm trying to get the absolute maximum performance out of this query, hence I'm using this read only query which bypasses the cache (and other business object connections - hence the 'foreign key' which needs to be passed in as a parameter).
If I turn parameter binding on for the query I get a null pointer exception at SQLCall.translate.
I'm using Toplink 9.0.3
Thanks.
Mike
Did you bind the argument in the Mapping Workbench? I.e., you typed in the SQL, but in the "parameter" tab you need to associate the #aqUniqueId to a type.
I don't see why the TopLink code you posted shouldn't work, but for the record I usually do it this way:
DatabaseQuery query = dqm.getQuery("QUERY");
Object object = session.executeQuery(query, arg);
If that doesn't work, I might try experimenting with the types in the Mapping workbench on the parameter (Double vs double)...
- Don
Make sure the argument is defined on the query in addition to the SQL string. Also do not get the query from the descriptor query manager but use the executeQuery on session that takes the query name and the class.
i.e.
session.executeQuery("QUERY", StepLink.class, arg); 
Mike..
did you ever have any luck fixing this problem? i'm running into exactly the same thing.. if you did, please let me know what you had to do.. thanks..
Saleem. 
Does you SQL have any newlines in it? If so try removing them - I had problems with named SQL queries when I entered multi-line queries into the MW.
For example, you would change
select step_link.* from step_link, step
where and step.child_id = step.unique_id
and step.aq_unique_id = #aqUniqueId
to
select step_link.* from step_link, step where and step.child_id = step.unique_id and step.aq_unique_id = #aqUniqueId
James,
When I would use the API
session.executeQuery("QUERY", arg); ?
The executeQuery comes with two different flavors-one that takes the fully qualified class name as one of the arguments and one that does not ?
The java doc is not clear when to use what version of the API.
I have code samples that use the "after load" method to add to the Descriptor's query manager and these queries pass in the class name while building the named query and when these named queries are invoked they use the API
session.executeQuery("QUERY,arg);
Thanks,
Aswin.
Make sure the argument is defined on the query in
addition to the SQL string. Also do not get the query
from the descriptor query manager but use the
executeQuery on session that takes the query name and
the class.
i.e.
session.executeQuery("QUERY", StepLink.class, arg); 
In TopLink pre-defined (named) queries can either be defined on a Descriptor, or on a Session. Queries defined through the Mapping Workbench are always defined on a Descriptor.
To execute a named query defined on a Descriptor, you must pass the Class for the Descriptor that the query is defined on.
i.e.
session.executeQuery("findById", Employee.class, id);
To execute a named query defined on the Session, you just pass the name.
i.e.
session.executeQuery("findEmployeeById", id);
Typically named queries are only defined on the Descriptor as they normally correspond to a Class. Sometimes it is desirable to define a named query on the Session, such as raw data queries or stored procedures that do not correspond to a Descriptor or Class.

Categories

Resources