docs.intersystems.com
InterSystems IRIS Data Platform 2019.2  /  Using the Native API for Java

Using the Native API for Java
Calling ObjectScript Methods and Functions
Previous section           Next section
InterSystems: The power behind what matters   
Search:  


This chapter describes a set of jdbc.IRIS methods that allow an application to call ObjectScript class methods and functions from the InterSystems IRIS™ class library.
Important:
Trailing Arguments
Trailing arguments may be omitted in argument lists, causing default values to be used for those arguments, either by passing fewer than the full number of arguments, or by passing null for trailing arguments. An exception will be thrown if a non-null argument is passed to the right of a null argument.
Class Method Calls
The following methods call a specified ObjectScript class method. They take String arguments for className and methodName, plus an Object containing 0 or more method arguments, and return the result as the indicated type:
The following code demonstrates a method call for each datatype:
  String className = "User.JavaTest";

  // calling class methods
  System.out.println("Boolean class method: " + IRIS.classMethodBoolean(className,"Boolean",false));
  System.out.println("Bytes class method: " + new String(IRIS.classMethodBytes(className,"Bytes","byteArray")));
  System.out.println("String class method: " + IRIS.classMethodString(className,"String","Java Test"));
  System.out.println("Long class method: " + IRIS.classMethodLong(className,"Long",7,8));
  System.out.println("Double class method: " + IRIS.classMethodDouble(className,"Double",7.56));
  IRIS.classMethodVoid(className,"Void",67);
  System.out.println("Void class method returned successfully.");
This example assumes that the following ObjectScript class (User.JavaTest) is compiled and available on the server:
  Class User.JavaTest
  {

    ClassMethod Void(p1 As %Integer)
    {
            Set ^p1=p1
            Quit
    }

    ClassMethod String(p1 As %String) As %String
    {
            Quit "Hello "_p1
    }

    ClassMethod Bytes(p1 As %String) As %Binary
    {
            Quit $C(65,66,67,68,69,70,71,72,73,74)
    }

    ClassMethod Long(p1 As %Integer, p2 As %Integer) As %Integer
    {
            Quit p1+p2
    }

    ClassMethod Double(p1 As %Double) As %Double
    {
            Quit p1 * 100
    }

    ClassMethod Boolean(p1 As %Boolean) As %Boolean
    {
            Quit 0
    }
  }
Function Calls
The following methods call a specified ObjectScript function. They take String arguments for functionName and routineName, plus an Object containing 0 or more function arguments, and return the result as the indicated type:
The following code demonstrates a function call for each datatype:
  String routineName = "JavaTest";

  // calling functions
  System.out.println("Boolean function: " + IRIS.functionBoolean ("Boolean",routineName,false));
  System.out.println("Bytes function: " + new String(IRIS.functionBytes ("Bytes",routineName,"byteArray")));
  System.out.println("String function: " + IRIS.functionString ("String",routineName,"Java Test"));
  System.out.println("Long function: " + IRIS.functionLong ("Long",routineName,7,8));
  System.out.println("Double function: " + IRIS.functionDouble ("Double",routineName,7.56));
  IRIS.procedure("Procedure",routineName,67);
  System.out.println("Procedure returned successfully.");
This example assumes that the following ObjectScript routine (JavaTest.mac) is compiled and available on the server:
        Procedure(p1) public {
            Set ^p1=p1
            Quit
        }

        String(p1) public {
            Quit "Hello "_p1
        }

        Bytes(p1) public {
            Quit $C(65,66,67,68,69,70,71,72,73,74)
        }

        Long(p1,p2) public {
            Quit p1+p2
        }

        Double(p1) public {
            Quit p1 * 100
        }

        Boolean(p1) public {
            Quit 0
        }


Previous section           Next section
Send us comments on this page
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-09-18 06:45:48