I didn't entirely understand your question, but here are my guesses as
to what you were asking ...
First off, Cayenne returns as many objects as the query matches (in a
List). If you are fetching a unique object, only one will be returned,
of course (a List with one object).
Here are some fetching examples. Assume the Employee object has a
"lastName" field and a "department" relationship.
Example 1: Fetch all Employee objects
DataContext dataContext = DataContext.createDataContext();
SelectQuery query = new SelectQuery(Employee.class);
List employees = dataContext.performQuery(query);
Example 2: Fetch all Employees whose last name is "Smith"
DataContext dataContext = DataContext.createDataContext();
// You'd most likely use a parameter substitution map for "Smith" in the
following expression ...
Expression expression = Expression.fromString("lastName = 'Smith'");
SelectQuery query = new SelectQuery(Employee.class, expression);
List employees = dataContext.performQuery(query);
Example 3: Fetch all Employees whose last name begins with "S"
DataContext dataContext = DataContext.createDataContext();
Expression expression = Expression.fromString("lastName like 'S%'");
SelectQuery query = new SelectQuery(Employee.class, expression);
List employees = dataContext.performQuery(query);
Example 4: Fetch all Employees in the Engineering department (follows
relationships using the "dot" notation)
DataContext dataContext = DataContext.createDataContext();
Expression expression = Expression.fromString("department.name =
$department");
Map parameters = new HashMap();
parameters.put("department", "Engineering");
SelectQuery query = new SelectQuery(Employee.class,
expression.expWithParameters(parameters));
List employees = dataContext.performQuery(query);
Hope that helps. Please note that I typed all those without any
testing, too. :-)
/dev/mrg
-----Original Message-----
From: lsteele [mailto:lsteel..inet.net.au]
Sent: Monday, August 30, 2004 6:59 PM
To: cayenne-use..bjectstyle.org
Subject: How Cayenne works ??
This is a bit of a newbie question but I have done lots of
reading in the docs and cannot really come up with an answer.
I am currently converting an early development tapestry app over
to use cayenne and so far I like what I see. Eventually (after
submitting it as a uni project) I will open the code so it might be
useful for others.
I seem to be having trouble visualising how Cayenne brings back
a group of objects from a query or how the when it brings back a group
of objects linkages are maintained between the objects.
The problem I need to pass an object to the am running into is
that the contrib:Table. I pass a single object and then assign
get methods to the coloumns in the table. In SQL I just a
create a new object and pass this.
What is the best way to do something like this in Cayenne. ??
I have used the modeller to set up my objects similarly to the
examples that I see in the docs .. but this still only brings back the
single object.
Is there a way to do a query on an object with links to other
objects and bring back a collection of single objects that contrains
data from that query ?
Are there any more complex examples for doing things like this
?? Has anyone seen examples for doing something like this in Tapestry
??
Thanks,
Lindsay
This archive was generated by hypermail 2.0.0 : Tue Aug 31 2004 - 10:34:33 EDT