PDA

Click to See Complete Forum and Search --> : Object reference to number


shunt
May 26th, 2008, 07:13 AM
Hi all,

I am new to Java and need some assistance. I am using java stored procedures in Oracle and need to convert an object reference in java to a number so that I can pass it back to Oracle for later use. I remember in vb6 there was a function to do this and I was hoping that Java would also have a similar ability....

Thanks

leinad31
May 27th, 2008, 07:45 PM
I'm a bit confused on the "later use" part... what if the object no longer exists? As to passing Java objects to Oracle, you have to break it up into relevant PL/SQL data types. When your already in the stored Java code that's when you can pass Java objects around internally in the database.

Please explain again what you are trying to accomplish.

shunt
May 28th, 2008, 03:51 AM
Ok, I will try and give a better explanation....

As of Oracle 817, Oracle made available a PL/SQL package for XML manipulation (dbms_xmldom). The implementation behind this PL/SQL package was done in Java. Now, using their PL/SQL package, you are able to create an XMLDocument object. This object is actually a java object, but a "pointer" is returned to the calling PL/SQL procedure for use in subsequent calls.

create or replace procedure mycustomproc as

l_doc dbms_xmldom.DOMDocument;

begin

l_doc := dbms_xmldom.newDOMDocument();
dbms_xmldom.freeDocument(l_doc);

end mycustomproc;


The dbms_xmldom.DOMDocument type is defined by Oracle as

type DOMDocument is record(id raw(12));


The l_doc variable is therefore a pointer to an instanciated java object. As seen in the example, this can be used in subsequent calls to the package.

I want to create the same effect using my own custom java object. Problem is, I don't know how to get the raw id that refers to the object.... Any ideas?:confused:

leinad31
May 28th, 2008, 07:13 PM
Try returning the hash code... internally the java maintains collection using hash code to retrieve instances... that is why you need to call freeDocument to remove the instance from the collection.

shunt
May 29th, 2008, 05:11 AM
Thanks.. I am now using a private static hashtable to store references to the objects and am returning the hash code back to pl/sql. Doesn't seem like the most elegant solution to me, but it is working just fine for now. I am just hoping that there won't be issues with multiple threads using the library. Time will tell....

leinad31
Jun 2nd, 2008, 09:10 PM
You can use JMeter to simulate multiple users and plot performance.

shunt
Jun 3rd, 2008, 06:27 AM
Hmm... looks promising... will investigate