Assuming you are using the latest version of Cayenne, you should be able
to use the "Create Query" button in Cayenne Modeler (it's at the end,
just after "Create Relationship") to do this (make sure you have a Data
Map selected).
Use $parameter type substitution variables in the "Qualifier" field.
When using the query in your code, you'll need to pass a map of
substitution values (without the "$").
For your case, I'm guessing the "Query Root" should be set to "Ads", the
"Qualifier" to "nr = $nr", and "Query Name" to "Fetch Ads".
To call it from your code (note that I'm just typing this, haven't tried
to compile it):
SelectQuery storedQuery = (SelectQuery)
dataContext.getEntityResolver().lookupQuery("Fetch Ads");
Map parameters = new HashMap();
parameters.put("nr", "12345");
SelectQuery actualQuery = storedQuery(queryWithParameters(parameters));
List objects = dataContext.performQuery(actualQuery);
/dev/mrg
PS. I believe that by default, if you have multiple parameters defined
in your qualifier and don't supply them in the hash map, they'll be
pruned out of the query for you, which can be useful.
-----Original Message-----
From: Sako! [mailto:webobject..tcc.datos.de]
Sent: Monday, August 30, 2004 8:00 AM
To: Cayenne
Subject: Fetch Spec. like Modeler
Hello,
i would like to know if i can create a Fetch Specification in
Cayenne like in EOModeler.
i mean i want to get the Qualifier in Cayenne like this :
Ads.fspec file
-------------------------------------------------------------
{
"Fetch Ads" = {
class = EOFetchSpecification;
entityName = Ads;
fetchLimit = 0;
isDeep = YES;
qualifier = {
class = EOKeyValueQualifier;
key = nr;
selectorName = "isEqualTo:";
value = {_key = nr; class = EOQualifierVariable; };
};
refreshesRefetchedObjects = YES;
requiresAllQualifierBindingVariables = YES;
};
}
-------------------------------------------------------------
Qualifier in EOModeler
(nr= $nr)
Code in java :
EOFetchSpecification fs =
EOFetchSpecification.fetchSpecificationNamed(fetch, entity);
NSMutableDictionary bindings = new NSMutableDictionary();
bindings.setObjectForKey(specialistNr, "nr"); // specialistNr
Integer
fs = fs.fetchSpecificationWithQualifierBindings(bindings);
NSArray objects = ec.objectsWithFetchSpecification(fs); // ec
EdetingContext
if (objects.count() > 0)
{
return (EOGenericRecord) objects.objectAtIndex(0);
}
else
{
return null;
}
-------------------------------------------------------------
if possilbe please give me the url how to use that.
Regards.
Sako.
This archive was generated by hypermail 2.0.0 : Mon Aug 30 2004 - 10:16:33 EDT