Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question
0

SQLQuery vs Template Querys of nested Collections

Hello,

I am having an issue when querying nested collections using a SQLQuery vs a Template query. Here is a simple example that shows it. In this example, the SQLQuery returns the correct object but the Template query doesn't find the object. These are basically equivalent queries but it appears that nested collections can only be queried using SQLQuery and Template Queries only seem to work with top level attributes of an object. Is what I am seeing by design of am I missing something.

Thanks,

Rich

public class PetFeeder {

public GigaSpace gigaSpace;

public static void main(String[] args) {
    try {
        PetFeeder feeder = new PetFeeder();

        UrlSpaceConfigurer spaceConfigurer = new UrlSpaceConfigurer("jini://*/*/Pets");
        IJSpace space = spaceConfigurer.space();

        //From here -- http://www.gigaspaces.com/wiki/display/XAP8/The+GigaSpace+Interface
        feeder.gigaSpace = new GigaSpaceConfigurer(space).gigaSpace();

        Pets pets1 = new Pets();
        pets1.setMyPets(new ArrayList<Animal>());
        Dog dog1 = new Dog();
        dog1.setType("dog");
        dog1.setName("fido");
        pets1.getMyPets().add(dog1);
        Cat cat1 = new Cat();
        cat1.setType("cat");
        cat1.setName("patches");
        pets1.getMyPets().add(cat1);

        feeder.gigaSpace.write(pets1);

        Pets pets2 = new Pets();
        pets2.setMyPets(new ArrayList<Animal>());
        Dog dog2 = new Dog();
        dog2.setType("dog");
        dog2.setName("pepper");
        pets2.getMyPets().add(dog2);

        // Query SQLQuery
        SQLQuery<Pets> query = new SQLQuery(Pets.class, "myPets[*].name = 'fido'");
        Pets readPets1 = feeder.gigaSpace.read(query);
        System.out.println("SQLQuery:" + readPets1);

        // Template Query
        Pets queryPets = new Pets();
        queryPets.setMyPets(new ArrayList<Animal>());
        Dog queryDog = new Dog();
        queryDog.setName("fido");
        queryPets.getMyPets().add(queryDog);
        System.out.println("Template:" + queryPets);
        Pets readPets2 = feeder.gigaSpace.read(queryPets);
        System.out.println("Template Query:" + readPets2);

    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

}

public class Pets implements Serializable {

protected String id;
protected List<Animal> myPets;

@SpaceId(autoGenerate=true)
public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public List<Animal> getMyPets() {
    return myPets;
}

public void setMyPets(List<Animal> myPets) {
    this.myPets = myPets;
}

}

public class Animal implements Serializable {

protected String type;

public String getType() {
    return type;
}

public void setType(String type) {
    this.type = type;
}

}

public class Dog extends Animal {

protected String name;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

}

public class Cat extends Animal {

protected String name;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

}

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=3670]{quote}

asked 2011-05-26 14:14:37 -0600

rchristy gravatar image

updated 2013-08-08 09:52:00 -0600

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

As far as I know collection query supported only via SQLQuery.
We will clarify this with the product doc.
Tnx
Shay

answered 2011-05-26 17:46:38 -0600

shay hassidim gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2011-05-26 14:14:37 -0600

Seen: 141 times

Last updated: May 26 '11