Calling a method that returns an object Array

Hello.
During a JNICALL , I wish to call a method which returns an object array.
ie my java class has a method of the form
public MyObject[] getSomeObjects(String aString){
MyObject[] theObjects=new MyObject[10];
return theObjects
Is there an equivalent to (env)->CallObjectMethod(...
which returns a jobjectArray instead of a jobject, and if not could somebody suggest a way around this.
Thanks,
Neil

I believe an array oj jobjects is also a jobject. You can then cast it to another class.

Similar Messages

  • Calling a method that returns values in a map - using JSTL

    Hi I have a method within an object that returns a List for a particular category
    public List<String> getFieldsInCategory(String categoryName){
        return _categoryFieldsMap.get(categoryName); //This is a map that returns a list                                                             
      }Trying to call the above function in jsp, the object is available as "document",
    how do i pass a key to the above function to return a List.
       <c:forEach items="${document.fieldsInCategory('ABSTRACT')}" var="temp">How do i get the list by passing a string key to my method,
    please let me know how to go about this.
    Thanks

    JSTL can not directly call methods that take parameters.
    All it can do is access javabean properties - ie via the revealed get/set methods.
    You can fudge it by having a seperate variable to set:
    Map  _categoryFieldsMap;
    String category = null;
    public void setCategory(String category){
      this.category = category;
    public String getCategory(String category){
      return category;
    public List<String> getFieldsInCategory(){
        return _categoryFieldsMap.get(categoryName); //This is a map that returns a list                          
      }You would then do it like this in your JSP:
    <c:set target="document.category" value="ABSTRACT"/>
    <c:forEach items="${document.fieldsInCategory}" var="temp">
    ...The other alternative is to return the entire map to the page.
    EL accesses maps quite handily.
    so given a method that returns the map:
    public Map getCategoryFieldsMap(){
    return _categoryFieldsMap;
    then the expression: ${document.categoryFieldsMap.ABSTRACT} returns what you are after.
    Hope this helps,
    evnafets

  • How to code a method that returns string for class object

    I have a class named Address.
    public class Addresss{   
    private String street;   
    private String city;            // instance variables  
    private String zipcode;}I have been asked to write a method that returns a string for Address object. I dont understand how to create address object.Can anyone pls help me understand.
    do I have to write (for creating object)
    Address addressObject  = new Address(); ( coding method that returns a string for address object) ---> I really dont understand this part.

    looks almost right. The problem is that your method name AddressBookEntry does not match the name of your class AddressBook and therefore is not a constructor.
    Furthermore, you probably need to make a distinction between a single entry into the address book which consists of a single name and a single address, (which is just what you have done) and an address book itself which is probably a list of AddressBookEntries
    So for your code I would change the class that you called "AddressBook" to "AddressBookEntry" and have a third class that represents the collection of AddressBookEntries.
    Now to be honest, I don't know why you keep the name split apart from the street address portion of the address. I would be more inclined to keep the name as a field of the address itself, but it's your code, you carve it up the way you like.

  • Web Service Method that returns an ArrayList

    Hi guys,
    I have to create a web service method that returns an ArrayList, but it's not working. My problem is:
    With the "@XmlSeeAlso" annotation, my client prints the result, but the ArryaList is not from java.util, it's from org.me.calculator so I can't use it.
    If I remove this annotation, I get no result, with this error message on Tomcat 6:
    [javax.xml.bind.JAXBException: class java.util.ArrayList nor any of its super class is known to this context.]
    I'm a newbie, and trying to understand web services (I read some posts here, but didn't get the point, from its answers), but this problem I just can't figure out how to solve....
    WEb Service
    package org.me.calculator;
    import java.io.Serializable;
    import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebService;
    import java.util.*;
    import java.util.ArrayList;
    import javax.xml.bind.annotation.XmlSeeAlso;
    * @author eduardo.domanski
    @WebService()
    @XmlSeeAlso({java.util.ArrayList.class}) // With this, I can see the result on client, but, the ArrayList is an org.me.calculator.ArrayList class.... Strange...
    public class CalculatorWS {
        @WebMethod(operationName = "valores")
        public ArrayList valores(@WebParam(name = "a") int a,
                           @WebParam(name = "b") int b) {
            ArrayList teste = new ArrayList();
            ArrayList a1 = new ArrayList();
            a1.add(a);
            a1.add(b);
            ArrayList a2 = new ArrayList();
            a2.add(a+b);
            a2.add(a-b);
            teste.add(a1);
            teste.add(a2);
            return  teste; 
    }CLient
    package org.me.calculator.client;
    import java.io.*;
    import java.net.*;
    import java.util.ArrayList;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ClientServlet extends HttpServlet {
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ClientServlet</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ClientServlet at " + request.getContextPath() + "</h1>");
            try { // Call Web Service Operation
                org.me.calculator.CalculatorWSService service = new org.me.calculator.CalculatorWSService();
                org.me.calculator.CalculatorWS port = service.getCalculatorWSPort();
                // TODO initialize WS operation arguments here
                int i = 8;
                int j = -6;
                // TODO process result here
                ArrayList result = (ArrayList) port.valores(i, j);
                out.println("Result = " + result);
            } catch (Exception ex) {
                System.out.println(ex);
            // TODO handle custom exceptions here
            out.println("</body>");
            out.println("</html>");
            out.close();
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
    }THank you all,
    Eduardo
    Edited by: EduardoDomanski on Apr 23, 2008 4:40 AM

    I forgot to say that, when I try to return an ArrayList of an object, for example, ClassA, which is on the package org.me.classes, on my Server App, the ArrayList is returned, but the objects are from type org.me.calculator.ClassA. It should be from org.me.classes.ClassA, right?
    This package also exists on my client App, to use the object, but as the returned type is from another package, I can't even cast it. I tried some annotations @Xml... but it failed.
    Packages
    ServerApp
    org.me.calculator
    CalcWS.java
    org.me.classes
    ClassA.java
    Client App
    org.me.classes
    ClassA.java
    The return from my method should be an ArrayList of org.me.classes.ClassA, but when I print it, on client, it's from org.me.calculator.ClassA.
    Does anybody knows, or had the same problem?
    Thanks,
    Eduardo

  • Returning an Object Array

    I am unable to figure out the way in which I can return an object
    array from a cpp file to java. Is there any obvious error which you can spot in
    my CPP file?
    When I try to return a single object in the native function,
    it works fine but when I try to extend it and return an array of the object, it
    throws an error.
    Please find below the details
    h1. Java Class
    public class Flight {
    public String ID;
    public class InterfaceClass {
    private native Flight[] GetFlights();
    public static void main(String[] args)
    Flight[] objFlight = new
    InterfaceClass().GetFlights();
    System.+out+.println(objFlight[0].ID);
    static {
    System.+loadLibrary+("main");
    h1. CPP File
    JNIEXPORT jobjectArray JNICALL Java_InterfaceClass_GetFlights(JNIEnv env, jobject obj)
    //1. ACCESSING THE FLIGHT CLASS
    jclass cls_Flight = env->FindClass("LFlight;");
    //2. CONSTRUCTOR FOR FLIGHT CLASS
    jmethodID mid_Flight = env->GetMethodID(cls_Flight,"<init>", "()V");
    //3. CREATING AN OBJECT OF THE FLIGHT CLASS
    jobject objFlight = env->NewObject(cls_Flight, mid_Flight);
    //4. ACCESSING THE FLIGHT's "ID" FIELD
    jfieldID fid_ID = env->GetFieldID(cls_Flight, "ID","Ljava/lang/String;");
    //5. SETTING THE VALUE TO THE FLIGHT's "ID" FIELD
    env->SetObjectField(objFlight,fid_ID, env->NewStringUTF("ABC"));
    //6. ACCESSING THE FLIGHT ARRAY CLASS
    jclass cls_Flight_Array = env->FindClass("[LFlight;");
    if(cls_Flight_Array == NULL)
    printf("Error-1");
    //7. CREATING A NEW FLIGHT ARRAY OF SIZE 1 jobjectArray arrFlightArray = env->NewObjectArray(1,cls_Flight_Array,NULL);
    if(arrFlightArray == NULL)
    printf("Error-2");
    //8. INSERTING A FLIGHT BJECT TO THE ARRAY
    env->SetObjectArrayElement(arrFlightArray,0,objFlight);
    return arrFlightArray;
    h1. Error
    # A fatal error has been detected by the Java Runtime Environment:
    # EXCEPTION_ACCESS_VIOLATION
    (0xc0000005) at pc=0x6d9068d8, pid=1804, tid=3836
    # JRE version: 6.0_18-b07
    # Java VM: Java HotSpot(TM) Client VM (16.0-b13 mixed mode, sharing
    windows-x86
    # Problematic frame:
    # V [jvm.dll+0x1068d8]
    # An error report file with more information is saved as:
    # C:\Users\Amrish\Workspace\JNI Test\bin\hs_err_pid1804.log
    # If you would like to submit a bug report, please visit:
    http://java.sun.com/webapps/bugreport/crash.jsp
    C:\Users\Amrish\Workspace\JNI Test\bin>java -Djava.library.path=.
    InterfaceClass
    Exception in thread "main" java.lang.ArrayStoreException
    at
    InterfaceClass.GetFlights(Native Method)
    at
    InterfaceClass.main(InterfaceClass.java:6)
    C:\Users\Amrish\Workspace\JNI Test\bin>java -Djava.library.path=.
    InterfaceClass
    Exception in thread "main" java.lang.ArrayStoreException
    at
    InterfaceClass.GetFlights(Native Method)
    at
    InterfaceClass.main(InterfaceClass.java:6)
    Edited by: amrish_deep on Mar 18, 2010 7:40 PM
    Edited by: amrish_deep on Mar 18, 2010 7:40 PM

    //6. ACCESSING THE FLIGHT ARRAY CLASS
    jclass cls_Flight_Array = env->FindClass("[LFlight;");The argument to NewObjectArray is the +element+ class of the array you're about to create, not the +array+ class itself.

  • How to call the method of a Business Object?

    Hi,
    Can someone guide me how to call the method of a business object?
    For example, I want to use the method SalesDocument.Copy of the Business Object VBAK. How can I do that? If you are familiar with any similar scenario please help.
    Regards,
    Renjith Michael.

    Hi
    double click on the copy  and
    go to abap tab
    there u can get functionmodule name
    u can call that
    Rewards if helpful

  • Best practices for Reusable methods that access DBTransaction object

    Hi All,
    In our application, there are reusable methods that has DBTransaction object as parameter, eg :
    public static String postingToGL(DBTransaction dbTran, String pProceName, Number pDocId)
    This method could be called both from : Entity Object or Application Module (AM).
    I have two options about where to implement it :
    (1) put it in a Utils / helper class, so that I can call it both from Entity class and AM. But I have to pass DBTransaction object as parameter (I am not convenient with this)
    or...
    (2) put it in Entity object base class, but the problem is what if application module also nede to call that method ?
    WHat is the best practice in this situation ?
    Thank you,
    xtanto

    Hi,
    what about putting it into an AM base class ? I don't know what you worries are for passing the DBTransaction around.
    Frank

  • Calling parent method from within child object

    Hello,
    A quick question! Is it possible to call a method in a parent object from within a child object.By child object I mean an object that was instantiated within the parent object.
    Thanks.

    A quick question! Is it possible to call a method in a
    parent object from within a child object.By child
    object I mean an object that was instantiated within
    the parent object.Since you are using ambiguous terminology, it would be much better if you provided a small sample of your code to avoid confusion. I am guessing that you are actually talking about an inner class when you say child class.
    If that is correct, then you can do something like this:
    class Parent {
      void foo() {}
      void bar() {}
      class Child {
        void foo() {}
        void test() {
          bar(); // No conflicts, just call the Parent method
          Parent.this.foo(); // Use explicit qualification to avoid conflicts.

  • EL - How do you call a method that requires a parameter

    How do you call a method that requires a parameter
    In scriplet code here is what I am trying to do
    <%= car.getDefaultColor(car.getCarType()) %>
    How do I do this in EL
    Here is my guess (it generates the Exception described below)
    ${car.defaultColor(car.carType)}
    Here is the Exception I am getting:
    javax.servlet.ServletException: <h3>Validation error messages from tag library c</h3>tag = 'out' / attribute = 'value': An error occurred while parsing custom action attribute "value" with value "${car.defaultColor(car.carType)}": Encountered "(", expected one of ["}", ".", ">", "gt", "<", "lt", "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-", "*", "/", "div", "%", "mod", "and", "&&", "or", "||"]
    Any Ideas?
    P.S. If it matters to you, I am using JSTL 1.0 and the code snippets above are actually within the value attribute of a <c:out value="" /> statement.

    How do you call a method that requires a parameter
    In scriplet code here is what I am trying to do
    <%= car.getDefaultColor(car.getCarType()) %>
    How do I do this in ELYou don't. EL is very strict in method signatures. All get methods must be public Type getProperty(void); And all set methods must be public void setProperty(Type t);
    So you will have to re-work your Bean so it does not need an argument to the get method (getDefaultColor()). Since you are calling another method out of car, you might re-write the getDefaultColor method as such:
      public Object getDefaultColor() {
        CarType ct = this.getCarType();
        //then do other stuff
      }If that isn't suitable, then provide a helper method that is used to set the current car type and then call the getDefaultColor:
      private CarType curCarType;
      public void setCurrentCarType(CarType ct) { curCarType = ct; }
      public Object getDefaultColor() {
        if (curCarType == null) throw new IllegalStateException("CarType must be set before getting color");
        //normal work using curCarType
    <c:set target="${car}" property="currentCarType" value="${car.carType}"/>
    <c:out value="${car.defaultColor}"/>It is better to do as little of the data manipulation (setting up the car type) in the JSP as possible, so the first option is better than the second. Also better then the second would be to set the current car type in a servlet or data access object (or wherever) from which your retreive the car to begin with. Manipulatig it in the JSP itself should be your last resort (to keep as much business logic out of the JSP as possible).
    Here is my guess (it generates the Exception
    described below)
    ${car.defaultColor(car.carType)}
    Here is the Exception I am getting:
    javax.servlet.ServletException: <h3>Validation error
    messages from tag library c</h3>tag = 'out' /
    attribute = 'value': An error occurred while parsing
    custom action attribute "value" with value
    "${car.defaultColor(car.carType)}": Encountered "(",
    expected one of ["}", ".", ">", "gt", "<", "lt",
    "==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[",
    "+", "-", "*", "/", "div", "%", "mod", "and", "&&",
    "or", "||"]
    Any Ideas?
    P.S. If it matters to you, I am using JSTL 1.0 and
    the code snippets above are actually within the value
    attribute of a <c:out value="" /> statement.

  • Methods that return more than one object.

    Hello everyone,
    I don't know if this has ever been proposed or if there's an actual solution to this in any programming language. I just think it would be very interesting and would like to see it someday.
    This is the thing: why isn't it possible for a method to return more than one object. They can receive as many parameters as wanted (I don't know if there's a limit), but they can return only 1 object. So, if you need to return more than one, you have to use an auxiliary class...
    public class Person {
       private String name;
       private String lastName;
       public Person(String name, String lastName) {
          this.name = name;
          this.lastName= lastName;
       public String getName() {
           return name;
       public String getLastName() {
           return lastName;
    }So if you want to get the name of somebody you have to do this, assuming "person" is an instance of the object Person:
    String name = person.getName();And you need a whole new method (getLastName) for getting the person's last name:
    String lastName = person.getLastName();Anyway, what if we were able to have just one method that would return both. My idea is as follows:
    public class Person {
       private String name;
       private String lastName;
       public Person(String name, String lastName) {
          this.name = name;
          this.lastName= lastName;
       public String name, String lastName getName() {
           return this.name as name;
           return this.lastName as lastName;
    }And you would be able to do something like:
    String name = person.getName().name;and for the last name you would use the same method:
    String lastName = person.getName().lastName;It may not seem like a big deal in this example, but as things get more complicated simplicity becomes very useful.
    Imagine for example that you were trying to get information from a database with a very complex query. If you only need to return 1 column you have no problem, since your object can be an array of Strings (or whatever type is necessary). But if you need to retrieve all columns, you have three options:
    - Create 1 method per column --> Not so good idea since you're duplicating code (the query).
    - Create and auxiliary object to store the information --> Maybe you won't ever use that class again. So, too much code.
    - Concatenate the results and then parse them where you get them. --> Too much work.
    What do you think of my idea? Very simple, very straight-forward.
    I think it should be native to the language and Java seems like a great option to implement it in the future.
    Please leave your comments.
    Juan Carlos García Naranjo

    It's pretty simple. In OO, a method should do one thing. If that thing is to produce an object that contains multiple values as part of its state, and that object makes sense as an entity in its own right in the problem domain--as opposed to just being a way to wrap up multiple values that the programmer finds it convenient to return together--then great, define the class as such and return an instance. But if you're returning multiple values that have nothing to do with each other outside of the fact that it's convenient to return them together, then your method is probably doing too much and should be refactored.
    As for the "if it increases productivity, why not add it?" argument, there are lots of things that would "increase productivity" or have some benefit or other, but it's not worth having them in the language because the value they add is so small as to no be worth the increase in complexity, risk, etc. MI of implementation is one great example of something that a lot of people want because it's convenient, but that has real, valid utility only in very rare cases. This feature is another one--at least in the domain that Java is targetting, AFAICT.

  • Calling a method from a UICommand Object

    How do I call an action method from a UICommand object?
    I create a HtmlCommandLink in my backing bean, and I think I should be setting the action, but with what? The method takes a MethodBinding but I can't find much detail on how to get that. I just want to call a method like linkAction1_action() in the example below, but you cannot pass a method.
    public class Page1 extends AbstractPageBean {
      private HtmlPanelGroup panel = new HtmlPanelGroup();
      public HtmlPanelGroup getPanel() {
        return panel;
      public void setPanel(HtmlPanelGroup panel) {
        this.panel = panel;
      public Page1() {
        HtmlCommandLink link = new HtmlCommandLink();
        link.setAction(/* what do I put here */);
        this.panel.getChildren().add(link);
      public String linkAction1_action() {
        return "GoBack";
    }

    OK. A couple days later and I am able to answer my
    own question. Anyway, I will lay it out there for
    anyone interested. This worked for me...
    public class Page1 extends AbstractPageBean {
    private HtmlPanelGroup panel = new HtmlPanelGroup();
    public HtmlPanelGroup getPanel() {
    return panel;
    public void setPanel(HtmlPanelGroup panel) {
    this.panel = panel;
    public Page1() {
    HtmlCommandLink link = new HtmlCommandLink();
    link.setAction(
    FacesContext.getCurrentInstance()
    .getApplication()
    .createMethodBinding("#{Page1.linkAction1_action}",
    new Class[0]));
    this.panel.getChildren().add(link);
    public String linkAction1_action() {
    return "GoBack";
    Since you're setting the action from within the Page1 object, why don't you create a method binding manually? This will be much more performant that using the application to create and EL-based binding.
    Try:
    link.setAction(new MethodBinding()
          public Object invoke(FacesContext facesContext, Object[] objects) throws EvaluationException, MethodNotFoundException
            return linkAction1_action();
          public Class getType(FacesContext facesContext) throws MethodNotFoundException
            return String.class;
    });Note that you also avoid any naming convention - you do not require your Page1 object to be configured as a managed bean "Page1".

  • RMI server calling a method on a client object ?

    Hi All,
    I am writing a client - server application and my intention is to use RMI for comunication.
    When the client has to retrive datas from the server it's easy, but let's suppose that the server has to inform the client about some updates about the data, how can I do that?
    I do not want the client keeping calling methods on the server to see if there is something of new :(
    Is there some way to pass an OutputStream to the client, so when the server writes someting, the client reads it ? ( the client should have a thread which keeps reading)
    Or maybe I could pass a reference of a client class to the server so when the server needs to inform the client, it calls a method on this class?
    thanks, Fab

    The client can be a Remote Object to, passed as a remote reference when calling the server.
    Basically all you'll have to do is "register" the client on the serverside.
    Your serverside class would the have a:
    register(RemoteClient client) method.
    The server could the use this remote reference for callbacks.
    So, all you have to do is declare the Remote Interface for the client and implement it, and the call the servers myRemoteServer.register(this).
    If you've already implemented the server, it's a peace of cake to enhance your client.

  • Calling a method in an owning object

    I have an application that involves an object (B) that is a member (not a sub-class) of another object (A). Within the owned object (B) I want to call up a method from the owning object A. E.g I would like to do something like this:
    class A
    object B; // B is a member of A
    methodX( )
    class B
    owner.methodX( ); // invoke the methodX that is a member of object A.
    Is this possible and how can i do it?

    No, there is no implicit reference to an "owning" object. Think about the following code:
    class Parent {
      Child child
      Parent(Child child) { this.child = child; }
      void doSomething() {}
    class Child {
    class Test {
    public static void main(String[] args) {
       Child child = new Child();
       Parent p1 = new Parent(child);
       Parent p2 = new Parent(child);
    }So the two instances of Parent both have a reference to the same instance of Child. Which one is the "owner"?
    You'll have to explicitly give your "child" object a reference to the "owner" object in order to call methods on it

  • SOLVED: How can I use or call a function that returns %ROWTYPE?

    Hi
    edit: you can probably skip all this guff and go straight to the bottom...In the end this is probably just a question of how to use a function that returns a %rowtype.  Thanks.
    Currently reading Feuerstein's tome, 5th ed. I've downloaded and run the file genaa.sp, which is a code generator. Specifically, you feed it a table name and it generates code (package header and package body) that will create a cache of the specified table's contents.
    So, I ran:
    HR@XE> @"C:\Documents and Settings\Jason\My Documents\Work\SQL\OPP5.WEB.CODE\OPP5.WEB.CODE\genaa.sp"
    749  /
    Procedure created.
    HR@XE> exec genaa('EMPLOYEES');which generated a nice bunch of code, viz:
    create or replace package EMPLOYEES_cache is
        function onerow ( EMPLOYEE_ID_in IN HR.EMPLOYEES.EMPLOYEE_ID%TYPE) return HR.EMPLOYEES%ROWTYPE;
        function onerow_by_EMP_EMAIL_UK (EMAIL_in IN HR.EMPLOYEES.EMAIL%TYPE) return HR.EMPLOYEES%ROWTYPE;
        procedure test;
    end EMPLOYEES_cache;
    create or replace package body EMPLOYEES_cache is
        TYPE EMPLOYEES_aat IS TABLE OF HR.EMPLOYEES%ROWTYPE INDEX BY PLS_INTEGER;
        EMP_EMP_ID_PK_aa EMPLOYEES_aat;
        TYPE EMP_EMAIL_UK_aat IS TABLE OF HR.EMPLOYEES.EMPLOYEE_ID%TYPE INDEX BY HR.EMPLOYEES.EMAIL%TYPE;
        EMP_EMAIL_UK_aa EMP_EMAIL_UK_aat;
        function onerow ( EMPLOYEE_ID_in IN HR.EMPLOYEES.EMPLOYEE_ID%TYPE)
            return HR.EMPLOYEES%ROWTYPE is
            begin
                return EMP_EMP_ID_PK_aa (EMPLOYEE_ID_in);
            end;
        function onerow_by_EMP_EMAIL_UK (EMAIL_in IN HR.EMPLOYEES.EMAIL%TYPE)
            return HR.EMPLOYEES%ROWTYPE is
            begin
                return EMP_EMP_ID_PK_aa (EMP_EMAIL_UK_aa (EMAIL_in));
            end;
        procedure load_arrays is
            begin
                FOR rec IN (SELECT * FROM HR.EMPLOYEES)
                LOOP
                    EMP_EMP_ID_PK_aa(rec.EMPLOYEE_ID) := rec;
                    EMP_EMAIL_UK_aa(rec.EMAIL) := rec.EMPLOYEE_ID;
                end loop;
            END load_arrays;
        procedure test is
            pky_rec HR.EMPLOYEES%ROWTYPE;
            EMP_EMAIL_UK_aa_rec HR.EMPLOYEES%ROWTYPE;
            begin
                for rec in (select * from HR.EMPLOYEES) loop
                    pky_rec := onerow (rec.EMPLOYEE_ID);
                    EMP_EMAIL_UK_aa_rec := onerow_by_EMP_EMAIL_UK (rec.EMAIL);
                    if rec.EMPLOYEE_ID = EMP_EMAIL_UK_aa_rec.EMPLOYEE_ID then
                        dbms_output.put_line ('EMP_EMAIL_UK  lookup OK');
                    else
                        dbms_output.put_line ('EMP_EMAIL_UK  lookup NOT OK');
                    end if;
                end loop;
            end test;
        BEGIN
            load_arrays;
        end EMPLOYEES_cache;
    /which I have run successfully:
    HR@XE> @"C:\Documents and Settings\Jason\My Documents\Work\SQL\EMPLOYEES_CACHE.sql"
    Package created.
    Package body created.I am now trying to use the functionality within the package.
    I have figured out that the section
        BEGIN
            load_arrays;
        end EMPLOYEES_cache;
    /is the initialization section, and my understanding is that this is supposed to run when any of the package variables or functions are referenced. Is that correct?
    With that in mind, I'm trying to call the onerow() function, but it's not working:
    HR@XE> select onerow(100) from dual;
    select onerow(100) from dual
    ERROR at line 1:
    ORA-00904: "ONEROW": invalid identifier
    HR@XE> select employees_cache.onerow(100) from dual;
    select employees_cache.onerow(100) from dual
    ERROR at line 1:
    ORA-06553: PLS-801: internal error [55018]
    HR@XE> select table(employees_cache.onerow(100)) from dual;
    select table(employees_cache.onerow(100)) from dual
    ERROR at line 1:
    ORA-00936: missing expressionHe provides the code genaa.sp, and a very brief description of what it does, but doesn't tell us how to run the generated code!
    Now, I have just done some googling, and it seems that what I am trying to do isn't possible. Apparently %ROWTYPE is PL/SQL, and not understood by SQL, so you can't call onerow() from sql. Correct?
    So I try wrapping the call in an exec:
    HR@XE> exec select employees_cache.onerow(100) from dual;
    BEGIN select employees_cache.onerow(100) from dual; END;
    ERROR at line 1:
    ORA-06550: line 1, column 30:
    PLS-00382: expression is of wrong type
    ORA-06550: line 1, column 7:
    PLS-00428: an INTO clause is expected in this SELECT statement
    HR@XE> exec select table(employees_cache.onerow(100)) from dual;
    BEGIN select table(employees_cache.onerow(100)) from dual; END;
    ERROR at line 1:
    ORA-06550: line 1, column 14:
    PL/SQL: ORA-00936: missing expression
    ORA-06550: line 1, column 7:
    PL/SQL: SQL Statement ignored
    HR@XE> exec employees_cache.onerow(100)
    BEGIN employees_cache.onerow(100); END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00221: 'ONEROW' is not a procedure or is undefined
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignoredNo joy.
    Of course, now that I'm looking at it again, it seems that the way to go is indicated by the first error:
    PLS-00428: an INTO clause is expected in this SELECT statement
    So am I supposed to create a type of EMPLOYEES%ROWTYPE in a PL/SQL procedure, and the idea of this code, is that the first call to onerow() runs the initialiation code, which populates the cache, and all subsequent calls to onerow() (whether by my session or any other) will use the cache?
    I've had a stab at this, but still, no joy:
    create or replace procedure testcache is
        emp employees%rowtype;
        begin
            select employees_cache.onerow(100) from dual into emp;
            dbms_output.put_line('Emp id: ' || emp.employee_id);
        end testcache;
    show errors
    HR@XE> @testcache.sql
    Warning: Procedure created with compilation errors.
    Errors for PROCEDURE TESTCACHE:
    LINE/COL ERROR
    4/9      PL/SQL: SQL Statement ignored
    4/54     PL/SQL: ORA-00933: SQL command not properly ended
    HR@XE>Have a feeling this should be really easy. Can anybody help?
    Many thanks in advance.
    Jason
    Edited by: 942375 on 08-Feb-2013 11:45

    >
    Ha, figured it out
    >
    Hopefully you also figured out that the example is just that: a technical example of how to use certain Oracle functionality. Unfortunately it is also an example of what you should NOT do in an actual application.
    That code isn't scaleable, uses expensive PGA memory, has no limit on the amount of memory that might be used and, contrary to your belief will result in EVERY SESSION HAVING ITS OWN CACHE of exactly the same data if the session even touches that package.
    Mr. Feuerstein is an expert in SQL and PL/SQL and his books cover virtually all of the functionality available. He also does an excellent job of providing examples to illustrate how that functionality can be combined and used. But the bulk of those examples are intended solely to illustrate the 'technical' aspects of the technology. They do not necessarily reflect best practices and they often do not address performance or other issues that need to be considered when actually using those techniques in a particular application. The examples show WHAT can be done but not necessarily WHEN or even IF a given technique should be used.
    It is up to the reader to learn the advantages and disadvantages of each technicalogical piece and determine when and how to use them.
    >
    Now, I have just done some googling, and it seems that what I am trying to do isn't possible. Apparently %ROWTYPE is PL/SQL, and not understood by SQL, so you can't call onerow() from sql. Correct?
    >
    That is correct. To be used by SQL you would need to create SQL types using the CREATE TYPE syntax. Currently that syntax does not support anything similar to %ROWTYPE.
    >
    So am I supposed to create a type of EMPLOYEES%ROWTYPE in a PL/SQL procedure, and the idea of this code, is that the first call to onerow() runs the initialiation code, which populates the cache, and all subsequent calls to onerow() (whether by my session or any other) will use the cache?
    >
    NO! That is a common misconception. Each session has its own set of package variables. Any session that touches that package will cause the entire EMPLOYEES table to be queried and stored in a new associative array specifically for that session.
    That duplicates the cache for each session using the package. So while there might be some marginal benefit for a single session to cache data like that the benefit usually disappears if multiple sessions are involved.
    The main use case that I am aware of where such caching has benefit is during ETL processing of staged data when the processing of each record is too complex to be done in SQL and the records need to be BULK loaded and the data manipulated in a loop. Then using an associative array as a lookup table to quickly get a small amount of data can be effective. And if the ETL procedure is being processed in parallel (meaning different sessions) then for a small lookup array the additional memory use is tolerable.
    Mitigating against that is the fact that:
    1. Such frequently used data that you might store in the array is likely to be cached by Oracle in the buffer cache anyway
    2. Newer versions of Oracle now have more than one cache
    3. The SQL query needed to get the data from the table will use a bind variable that eliminates repeated hard parsing.
    4. The cursor and the buffer caches ARE SHARED by multiple sessions globally.
    So the short story is that there would rarely be a use case where ARRAYs like that would be preferred over accessing the data from the table.

  • Problem with web service that returns an object with a String that have som

    Hi everybody:
    I have a problem with a web service I am doing, I have made a web service that returns a collection of objects, the objects have a set of properties, there is one property that is a String,this property consists in a text fragment that could have some characters that are considered special in XML like &, <, >, " and that's why when I execute the service from a client an exception is thrown:
    {code}
    Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Could not read XML stream.. Nested exception is com.ctc.wstx.exc.WstxParsingException: Expected a text token, got START_ELEMENT.
    at [row,col {unknown-source}]: [9,646]
    org.codehaus.xfire.fault.XFireFault: Could not read XML stream.. Nested exception is com.ctc.wstx.exc.WstxParsingException: Expected a text token, got START_ELEMENT.
    at [row,col {unknown-source}]: [9,646]
    at org.codehaus.xfire.fault.XFireFault.createFault(XFireFault.java:89)
    at org.codehaus.xfire.client.Client.onReceive(Client.java:410)
    at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
    at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
    at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
    at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
    at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
    at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
    at org.codehaus.xfire.client.Client.invoke(Client.java:336)
    at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
    at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
    at $Proxy0.search(Unknown Source)
    at cu.co.cenatav.webservices.client.Client.main(Client.java:26)
    {code}
    I know that this is happening because special characters are sent by the soap message but I don't know how to solve this problem.
    How could I avoid this exception ?
    I hope you can help me.
    Regards.
    Ariel

    Hi,
    BPEL and BPEL PM do not have a good support for SOAPENC-Array: it would be very difficult to create such an array in BPEL or to receive it and manipulate it.
    The (unfortunately very intrusive) work around is to change the WSDL of the service to use a XML type defined using XML schema. This is all the more painful that JDev 9.0.4 does not have strong support for complex types.
    In general though, I would highly recommend this best practice:
    1) Start by define the WSDL contract first
    2) Then generate the server side skeleton to implement it
    3) Use BPEL as the client to this contract.
    By starting with the contract first, you make sure that 1) your interfaces are clean and coarse grained.
    2) things like java objects, sessions, etc to not leak through the interface (which would be the worst thing that could happen because it would closely link the client and the server.
    Sorry for not being more helpful. This will get radically cleaner in Oracle AS 10.1.3.
    Edwin

Maybe you are looking for

  • USB hub and internet sharing stop working after sleep

    Hi, I have a relatively new Bluestork USB hub I purchased to connect multiple USB devices I have at the same time. It used to work correctly under Leopard, but now it stops working each time the computer wakes up from sleep. I have to restart the com

  • How can I import address book contacts from 10.2 to 10.6?

    I have an uncle who recently had a computer with 10.2 that crashed.  I recovered all his files.  His new computer is now at 10.5 or 6, and will not import old contacts from 10.2.  Anyone know how I can import them?

  • Where do I download disc menu templates for Adobe Premiere Elements 10?

    Where do I download disc menu templates for Adobe Premiere Elements 10?

  • Photoshop CS3 freezes on 24" iMacs

    I've installed Photoshop CS3 on 2 new 24" iMacs.  Specs are 2.66 GHz Intel Core 2 Duo, 4 GB Ram iMacs, with Leopard and all updates to Leopard and Photoshop.  We are simply copying 3 photos, from storyboard psd files.  I then paste them 1 at a time i

  • Use iso as video in menu

    hey there, i'm getting a bluray iso from my post house. But i want to create a menu with extras and subtitles and all that stuff in Encore, is it possible to use that iso as a video inside of my menu? thanks for your help