Skip to main content
Previous section   Next section

Executing a Routine

Java projections can also be used to execute basic routines. For example, MyAccount contains the GETVALUE routine. The routine accepts a record ID, an attribute name, and a value number as arguments. It returns the corresponding piece of multivalue data. Here are the steps for executing this routine from Java:

  1. Create a Caché class and add a method, like the following, that wraps a call to the MVBasic routine. Note that the Caché class need not be persistent. It holds no data. It can extend %RegisteredObject.

    
    ClassMethod GetValue(ID As %String, ATTRNAME As %String, VNO As %String) 
     As %String
    {
      CALL GETVALUE(ID,ATTRNAME,VNO,VALUE)
      RETURN VALUE
    }   
    
    Copy code to clipboard
  2. Create a Java projection for the Caché class.

  3. Execute the routine from the Java code using the projection. Here is example Java code:

    
    String value = Search.GetValue(db, "3", "NAME","1");
    System.out.printf("Value: %s", value);
    
    Copy code to clipboard

    Note the following about these lines of Java code:

    • Search is the Java projection for the Caché class containing GetValue.

    • The Caché GetValue method is a Class Method, which projects to a Java static method. No instance of Search is required to execute it.

    • The db variable represents an open CacheDatabase object.

Note:

The above Caché GetValue method is in MVExample.Search, which is contained in MVExample.xml. The above Java code is contained in RunRoutine.java. Both files are in <cachesys>\Dev\tutorials\mv. Importing a File Using Studio contains step-by-step instructions for importing and installing Caché code. Executing the Java Examples contains step-by-step instructions for executing the Java code.