The Java Importer enables you to work with both class (static) and instance
methods of objects. Using the new
functions in the generated PL/SQL
packages, you can create instances of Java classes and obtain references to
those instances. Once you have a reference to an object returned from the new
operation it is possible to perform operations on that specific object instance
while it is still valid.
myclass
Java object.
PROCEDURE foo IS
obj ORA_JAVA.JOBJECT;
...
BEGIN
obj := myclass.new;
...
-- do some work on the obj object
...
END;
When you wish to invoke a method on a specific object that you have previously created, you pass the reference to the instance of the object to the instance methods in the PL/SQL package that corresponds with the Java class of the object. The desired method will be executed on the specific object instance you pass in as a parameter to the PL/SQL function or stored procedure.
PL/SQL functions and procedures that represent instance methods always take
an initial parameter of type ORA_JAVA.JOBJECT
that represents the
actual object instance that methods should be executed on.
PL/SQL functions and procedures that represent class methods do not require an instance object as a parameter.
The Java String
class contains a number of class methods that
perform conversion of primitive Java types into a String
representation.
These methods do not operate on a specific instance of a String
object but work generally on the String
class. An example of this
is the valueOf
method that returns a String
representation
from a scalar value.
The String
class also contains instance methods that operate on
a specific instance of a String
object. An example of this is the
length
method that returns the length of a specific String
object. The following code sample displays a portion of the Java String
class.
public final class String
{
. . .
public static String valueOf(int i);
. . .
public int length();
. . .
}
Given the Java String
class definition, the PL/SQL Generator creates
the following PL/SQL functions for these Java methods in the String
class:
PACKAGE STRING_ is
FUNCTION valueOf(a0 NUMBER) RETURN VARCHAR2;
. . .
FUNCTION length(obj ORA_JAVA.JOBJECT) RETURN NUMBER;
END;
The valueOf PL/SQL function represents a
Java class method and, as such, it does not require a parameter of type ORA_JAVA
.JOBJECT
to indicate the specific object instance on which it should invoke the valueOf
method.
On the other hand, the length
PL/SQL function represents an instance
method. This requires that it be passed a reference to the actual instance of
the String
object on which that the length
method
should be invoked.