3

I recently read that it is possible to use Java methods in a class by using the language attribute.

I tried this:

Method JavaTest() As %String [ Language = java, WebMethod ]
{
    string tmp = "Hello World";
    return tmp;
}

The code compiles, but when the method is invoked it returns an error:

ERROR #5002: Cache error: <METHOD DOES NOT EXIST>
O.O
  • 11,077
  • 18
  • 94
  • 182

2 Answers2

2

As far as I can tell, this facility exists for when you use the %Projection.Java class to create a Java class from Cache. At any rate, if you do use a Java projection then the method does actually get projected to the Java class that is created.

Class SomePackage.JavaTest Extends %Persistent
{

Method JavaTestyTest() As %String [ Language = java, WebMethod ]
{
    string tmp = "Hello World";
    return tmp;
}
Method bleh() as %Library.String
{
    q "bleh"
}
Projection NewProjection1 As %Projection.Java(ROOTDIR = "C:\trans");

}

generates too much Java to show all of it, but it includes

public java.lang.String JavaTestyTest () {
       string tmp = "Hello World";
       return tmp;
}

and

public java.lang.String bleh () throws com.intersys.objects.CacheException {
    com.intersys.cache.Dataholder[] args = new com.intersys.cache.Dataholder[0];
    com.intersys.cache.Dataholder res=mInternal.runInstanceMethod("bleh",args,com.intersys.objects.Database.RET_PRIM);
    return res.getString();
}
psr
  • 2,870
  • 18
  • 22
  • oh, I see. Ya, I was hoping that I could just call this method like any other Object Script method without generating an external (on file system) Java object. – O.O Oct 15 '12 at 16:44
2

Actually the %Projection classes are for projecting Cache class to Java. They generate Java proxy classes which you can use in Java projects.

In order to use Java classes and methods you need the Java Gateway which is a part of Ensemble and AFAIK not of Cache.

  • There is a difference between Java Binding (use Cache classes from Java via %Projection), which is a part of Cache, and Java Gateway (call Java classes from Ensemble), which is a part of Ensemble. – SSH Oct 14 '12 at 23:53