[Mulgara-dev] Using krule from the Java API

Paul Gearon gearon at ieee.org
Sat Jan 17 00:46:47 UTC 2009


On Thu, Jan 15, 2009 at 2:43 AM, Agustina Martinez <amgcia at gmail.com> wrote:
> Hi all,
>
> I am newbie to Mulgara. I am trying to use the Java API to access Mulgara
> from  a Web application. I stablish the connection and can make some queries
> but when I use the Krule methods, e.g. KruleLoader.newInstance, it creates
> the new instance correcly but when I try to invoque the readRules method I
> get the exception:

This API was designed for internal use only. I'd be surprised if you
can make it work.

If you want to run rules, you need to execute an ApplyRules operation
on a Connection. See:
  src/jar/query/java/org/mulgara/query/operation/ApplyRules.java

> java.lang.ClassCastException: org.mulgara.connection.SessionConnection
>     at org.mulgara.krule.KruleLoader.readRules(KruleLoader.java:224)

Have you changed the KruleLoader class? Line 224 doesn't have anything on it.

> I haven't found any documentation regarding using krule from Java

That's because you're not supposed to.  :-)

> and I
> have doubts about the opContextParam parameter, at the moment I am passing
> the connection session:
>     myLoaderInstance.readRules(connection.getSession, this.ruleModel);

No, you need an OperationContext. These come from
DatabaseSession.newOperationContext(boolean write).  The "write"
parameter indicates if the context is read only or read/write. If you
"Session" is really a "DatabaseSession", then your original code might
be fixed if you try:

myLoaderInstance.readRules(((DatabaseSession)connection.getSession()).newOperationContext(false),
this.ruleModel);

(Not that I advocate doing this)

Paul



More information about the Mulgara-dev mailing list