Home Help Center

Implement Chain Query by Self-Referential Interfaces

huangzhtaohuangzhtao Member Iven HuangOrganization: bitProject: use ice to construct a frame work for financial
Hello everyone,
I want to implement a "chain query" function, in some query objects: query.filter("condition1").filter("condition2").orderBy("Attribute1").
I found "Self-Referential Interfaces" in the documentation may help me, and I define .ice like this:

interface Query{
idempotent Query* filter(string condition);
idempotent Query* orderBy(string attribute);
}

When going into coding the servant, I don't know how to return Query*(or the proxy to the Query interface).
Am I doing the right way? Can anybody help me?

Best regards!

Comments

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    You can use the Ice::ObjectAdapter::createProxy method to create the proxy and then cast it to a Query proxy, for example:
    //Java 
    public QueryPrx filter(String str, Ice.Current current)
    {
         this.filterFields.add(str);
         return QueryPrxHelper.uncheckedCast(current.adapter.createProxy(current.id));
    }
    

    Note however that each filter/orderBy call will end up making a remote Ice invocation... which can be costly. A better approach might be to create those Query objects locally and once created pass it over to the server for execution.

    Cheers,
    Benoit.
Sign In or Register to comment.