The basic idea of this question is the following. I execute some query
List<Class2> class2entities = ObjectifyService.ofy()
.load()
.type(Class2.class)
.filter(?,?)
.list();
In what way can I execute another query based on class2entities ?
Actually I'm developing GAE application based on Objectify. I use the following entities
Problem:
@Entity
public class Problem {
@Id public String problemname;
public Problem (String name) {
problemname = name;
}
public Problem () {
problemname = "nullProblem";
}
}
Tuple:
@Entity
public class Tuple {
@Parent Ref<Problem> theProblem;
@Index public String tuple_id;
@Id public Long id;
public Tuple()
{
String s="empty operator";
}
public Tuple(String sid, Problem problem)
{
tuple_id = sid;
try {
theProblem = Ref.create(problem);
}
catch (java.lang.NullPointerException e)
{
System.out.println(e.toString() + " tuple in datastore was not created because of Problem is empty" );
}
}
}
Attribute:
@Entity
public class Attribute {
@Parent com.googlecode.objectify.Ref<Problem> theProblem;
@Id public Long id;
public String attributeName;
@Index public String attributeFieldName;
@Index public Date date;
/**
* Simple constructor just sets the date
**/
public Attribute() {
date = new Date();
}
/**
* A connivence constructor
**/
public Attribute(Problem problem, String attributeName) {
this();
if( problem != null ) {
theProblem = Ref.create(problem); // Creating the Ancestor key
} else {
theProblem = Ref.create(new Problem("nullProblem"));
}
this.attributeName = attributeName;
}
/**
* Takes all important fields
**/
public Attribute(Problem problem, String attributeName, String var_attributeFieldName) {
this(problem, attributeName);
attributeFieldName = var_attributeFieldName;
}
}
CategorizedData:
@Entity
public class CategorizedData {
@Load public Ref<Attribute> theAttribute;
@Id Long id;
@Parent public Key<Tuple> theTuple;
public String attributeValue;
@Index public Date date;
/**
* getter and setter for theAttribute
**/
public Attribute getAttribute() { return theAttribute.get(); }
public void setAttribute(Attribute attribute) { theAttribute = Ref.create(attribute); }
/**
* Simple constructor just sets the date
**/
public CategorizedData() {
date = new Date();
}
/**
* A connivence constructor
**/
public CategorizedData(String tupleId, String attribute_field_name, String var_attributeValue) {
this();
Attribute attribute = ofy().load().type(Attribute.class).filter("attributeFieldName", attribute_field_name).first().now();
Tuple tuple = ofy().load().type(Tuple.class).filter("tuple_id",tupleId).first().now();
if( tupleId != null ) {
theTuple = Key.create(Tuple.class, tuple.id); // Creating the Ancestor key
} else {
theTuple = Key.create(Tuple.class, (new Tuple()).id);
}
if( attribute != null ) {
theAttribute = Ref.create(attribute); // Creating the Ancestor ref
} else {
theAttribute = Ref.create(new Attribute());
}
this.attributeValue = var_attributeValue;
}
}
Now I'd like to get all Tuple entities for given Problem and to get all entities of CategorizedData with theAttribute field with given AttributeFieldName.
I need to do something like
Key<Problem> theProblem = Key.create(Problem.class, problemName);
// Run an ancestor query
List<Tuple> tuples = ObjectifyService.ofy()
.load()
.type(Tuple.class)
.ancestor(theProblem)
.list();
and then I need to get entities of CategorizedData within this list tuples. What should I do? Is it possible to use for Objectify queries not all datastore but the result of previous query? Please help me...