Re: EOAndQualifier on child entity property
Re: EOAndQualifier on child entity property
- Subject: Re: EOAndQualifier on child entity property
- From: James Cicenia <email@hidden>
- Date: Sat, 19 Aug 2006 09:55:02 -0500
Wouldn't be just quicker and easier... unless your are dealing with
billions of records to just do this in Java
with those Pierre extensions (I haven't used them)?
I could be way off base here but in some very stream of conscious
pseudo code:
select row_id from x where x.b_row_id in(select b.row_id where b.t =
'GREEN')
select row_id from x where x.b_row_id in(select b.row_id where b.t =
'BIG')
Intersect the above results sets via NSSet to get a new NSSet: validXSet
Use another of the IN statments to get all As who have one an x in
validXSet.
i.e. Select * From A where A.id in (validXSet's x.a_row_id);
Now you might want to do the above using rawsql at first and just use
the keys...
but, first try it using good old EOs to see if the performance is
good enough.
If postgress has a INTERSECT you could probably do this all in sql.
James Cicenia
On Aug 19, 2006, at 9:00 AM, Alexander Spohr wrote:
hello again,
for those of you who still did not get the problem, here is a
thorough explanation of what yann tries to do, and why neither AND
nor IN and even not a simple OR can fix yann's problem.
entities & relations:
A <-->> X <<--> B (B has attribute tag)
1.
if you do the join and then
(B.tag = 'green' AND B.tag = 'big')
you'll end up with no A's at all. B.tag in ONE ROW can be either
'green' OR 'big' but it can not be both.
2.
if you do the join and then
(B.tag = 'Green' OR B.tag = 'Big')
you'll get ALL A's that are either 'green' OR 'big' and the ones
that are 'green' AND 'big'. the first group (green or big, but not
both) is not wanted in the result.
3.
an IN is nothing but a shortened OR so it won't work, just like 2.
instead you have to do this, as Art was already writing:
select A.all
from A,X,B
where (A-X join and X-B join) AND (B.tag='green' OR B.tag='big')
GROUP BY A.pk
HAVING count(A.pk) = 2
that will only return those A's who connect to a green and a big B.
i extended the postgres-adaptor to allow this with a normal fetchspec.
you just drop some additional qualifiers and attributenames into
the hints.
remember that you can only group by what you have in the result-set.
yann would do something like this:
// create fetchspec and hints
EOFetchSpecification aFetchSpec = new EOFetchSpecification("A",
baseQualifier(), anOrderArray);
NSMutableDictionary aHintDict = new NSMutableDictionary();
// pick the attributes to group by
NSArray someAttributeNames = new NSArray(new String[]
{ "A_uniqueAttribute" })
aHintDict.setObjectForKey(someAttributeNames,
PostgresqlExpression.GROUP_ATTRIBUTES_KEY);
// build the having-qualifier
EOKeyValueQualifier aHavingQualifier = new EOKeyValueQualifier
("A_uniqueAttribute", EOQualifier.QualifierOperatorEqual, new
Integer(2));
aHintDict.setObjectForKey(aHavingQualifier,
PostgresqlExpression.HAVING_QUALIFIER_KEY);
// set it all and fire
aFetchSpec.setHints(aHintDict);
aFetchSpec.setFetchLimit(1000);
NSArray anArray = anEdCon.objectsWithFetchSpecification(aFetchSpec);
and you might as well add some EOSortOrderings.
unfotunately he soes not use postgres, so i can't help him any
further.
if there is some source for the mysql-adaptor i might dive into it
and apply my modifications to it - if that’s possible at all.
have fun,
atze
ps. i wonder why nobody else seems to need this? i use it at least
for all statistics i run in my apps.
Am 19.08.2006 um 01:05 schrieb Chuck Hill:
I can see any problems in the code. My three suggestions:
1. Check your model to ensure that all of attributes have names
and column names
2. Try using another one like InSetQualifier. Not sure if that
will work here, but I have had problems where one of these
qualifiers would not work, but expressing it a different way in a
different qualifier did work.
3. Ask Pierre if he can help. :-)
Chuck
On Aug 18, 2006, at 12:29 PM, Yann Bizeul wrote:
A safer bet is to use some extensions to WO. See Pierre
Bernards excellent qualifier extensions at
http://www.bernard-web.com/pierre/webobjects/code.html
I tried that with the following code :
public Main doFind()
{
Main nextPage = (Main)pageWithName("Main");
NSArray tags = NSArray.componentsSeparatedByString(tag," ");
NSMutableArray tagsQualifiers = new NSMutableArray();
int i;
for (i=0;i<tags.count();i++)
{
EOQualifier q = EOQualifier.qualifierWithQualifierFormat("tag = %
@",new NSArray(tags.objectAtIndex(i)));
tagsQualifiers.addObject(new ExistsInRelationshipQualifier
("tags",q));
}
EOAndQualifier tagsQualifier = new EOAndQualifier(tagsQualifiers);
EOFetchSpecification f = new EOFetchSpecification
("Location",tagsQualifier,null);
nextPage.searchResults = session().defaultEditingContext
().objectsWithFetchSpecification(f);
return nextPage;
}
All I get is the following exception :
[2006-08-18 21:25:15 CEST] <WorkerThread0>
java.lang.NullPointerException
at
com.webobjects.eoaccess.EOSQLExpression._aliasForRelationshipPath
(EOSQLExpression.java:324)
at
com.webobjects.eoaccess.EOSQLExpression._aliasForRelatedAttributeRel
ationshipPath(EOSQLExpression.java:259)
at
com.houdah.webobjects.eoaccess.qualifiers.ExistsInRelationshipQualif
ierSupport.sqlStringForSQLExpression
(ExistsInRelationshipQualifierSupport.java:100)
at com.webobjects.eoaccess.EOQualifierSQLGeneration
$Support._sqlStringForSQLExpression(EOQualifierSQLGeneration.java:
151)
at
com.webobjects.eoaccess.EOSQLExpression.sqlStringForArrayOfQualifier
s(EOSQLExpression.java:1562)
at
com.webobjects.eoaccess.EOSQLExpression.sqlStringForConjoinedQualifi
ers(EOSQLExpression.java:1597)
at com.webobjects.eoaccess.EOQualifierSQLGeneration
$_AndQualifierSupport.sqlStringForSQLExpression
(EOQualifierSQLGeneration.java:512)
at com.webobjects.eoaccess.EOQualifierSQLGeneration
$Support._sqlStringForSQLExpression(EOQualifierSQLGeneration.java:
151)
at
com.webobjects.eoaccess.EOSQLExpression.sqlStringForArrayOfQualifier
s(EOSQLExpression.java:1562)
at
com.webobjects.eoaccess.EOSQLExpression.sqlStringForConjoinedQualifi
ers(EOSQLExpression.java:1597)
at com.webobjects.eoaccess.EOQualifierSQLGeneration
$_AndQualifierSupport.sqlStringForSQLExpression
(EOQualifierSQLGeneration.java:512)
at com.webobjects.eoaccess.EOQualifierSQLGeneration
$Support._sqlStringForSQLExpression(EOQualifierSQLGeneration.java:
151)
at
com.webobjects.eoaccess.EOSQLExpression.prepareSelectExpressionWithA
ttributes(EOSQLExpression.java:1024)
at
com.webobjects.jdbcadaptor.JDBCExpression.prepareSelectExpressionWit
hAttributes(JDBCExpression.java:273)
at
com.webobjects.eoaccess.EOSQLExpressionFactory.selectStatementForAtt
ributes(EOSQLExpressionFactory.java:226)
at com.webobjects.jdbcadaptor.JDBCChannel.selectAttributes
(JDBCChannel.java:178)
at
com.webobjects.eoaccess.EODatabaseChannel._selectWithFetchSpecificat
ionEditingContext(EODatabaseChannel.java:878)
at
com.webobjects.eoaccess.EODatabaseChannel.selectObjectsWithFetchSpec
ification(EODatabaseChannel.java:215)
at
com.webobjects.eoaccess.EODatabaseContext._objectsWithFetchSpecifica
tionEditingContext(EODatabaseContext.java:3205)
at
com.webobjects.eoaccess.EODatabaseContext.objectsWithFetchSpecificat
ion(EODatabaseContext.java:3346)
at
com.webobjects.eocontrol.EOObjectStoreCoordinator.objectsWithFetchSp
ecification(EOObjectStoreCoordinator.java:539)
at
com.webobjects.eocontrol.EOEditingContext.objectsWithFetchSpecificat
ion(EOEditingContext.java:4114)
at
com.webobjects.eocontrol.EOEditingContext.objectsWithFetchSpecificat
ion(EOEditingContext.java:4500)
at FindRightComponent.doFind(FindRightComponent.java:36)
Yann Bizeul • yann at tynsoe.org
Cocoa Developer
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve
specific problems. http://www.global-village.net/products/
practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40freeport.de
This email sent to email@hidden
Freeport & Soliversum
Alexander Spohr
email@hidden
www.freeport.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40jimijon.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden