Home › Forum › Nuclos Entwicklung › Schnittstellen › Query entities
- Dieses Thema hat 5 Antworten und 2 Teilnehmer, und wurde zuletzt aktualisiert vor 13 Jahren von
Claudia Mangstl.
-
AutorBeiträge
-
5 November 2010 um 19:28 Uhr #2721
Carsten Hof
TeilnehmerHello,
I would like some clarifications about querying entities
from Java code.
In particular, say i have two entities a Person and an Address
(both normally created through the Entity Wizard).
Address has two fields: streetName and streetNumber
and Person has two fields: personName and personAddress which
is a referenz field to Address.streetNameI want to query for all Persons that live in number 50.
So my questions are:
1. Can you provide an answer to the above scenario by using
an implementation of CollectableSearchCondition? I tried to:subQuery = CollectableComparison(„Address“, „streetNo“, „50“)
query = CollectableSubCondition(„Address“, „personAddress“, subQuery)
MasterDataDelegate.getMasterData(„Person“, query)but that doesn’t work.
2. If the entity graph was deeper? Say the Address had a reference
to a Country entity and i wanted to find all Persons that live in
Germany? Which (combination of) CollectableSearchCondition would
i use?Thank you in advance
Vagelis Savvas
8 November 2010 um 15:28 Uhr #2726Claudia Mangstl
TeilnehmerHi,
1) at first sight It doesn’t seem wrong what you are doing. But the constructor you are using for CollectableComparison doesn’t exist in that way. Here is an example how this can be called from the RuleInterface:
CollectableComparison cond = org.nuclos.common.SearchConditionUtils.newMDComparison(MasterDataMetaCache.getInstance().getMetaData(„“), „“, ComparisonOperator.EQUAL, „something“);In order to have a closer look, could you please post the complete source code of this part ? What error messages do you get ?
2) Complex querys are difficult to handle only with CollectableSearchConditions, because there are amongst others no joins possible. Usually we use workarrounds by programming SQL statements or intermediary results and IN statements and so on…
Regards,
Claudia M.9 November 2010 um 15:57 Uhr #2734Carsten Hof
TeilnehmerHi Claudia,
the source code of what i try to do:
// Try 1
CollectableSearchCondition subCond = SearchConditionUtils.newComparison(
"Address",
"streetno",
ComparisonOperator.EQUAL,
"42" );CollectableSubCondition query = new CollectableSubCondition(
"Address",
"personaddress",
subCond);// run the query
MasterDataDelegate mdd = MasterDataDelegate.getInstance();
Collection res = mdd.getMasterData( "Person", query);The above gives me the error „entity field personaddress in Address does not exists.“
Obviously the problem is in how i construct the CollectableSubCondition query.
I saw the comment of the class and thought that when it says sSubEntityName
this for me is the Address entity and when it says sForeignKeyFieldName
this for me is the field of Person that points to my
sub entity, thus personaddress.Then i tried changing the query as:
// Try 2
CollectableSubCondition query = new CollectableSubCondition(
"Person",
"personaddress",
subCond);Changing Address to Person, since Person has
a field personaddress, gives the error:
„entity field streetno in Person does not exists“.
Not sure why it looks in Person to find the streetno
since my subCond connects Address with streetno, as it makes sense.Finally, after seeing your comments, i changed the subCond
using the newMDComparison rather than simply newComparison.// Try 3
CollectableSearchCondition subCond = SearchConditionUtils.newMDComparison(
MasterDataDelegate.getInstance().getMetaData("Address"),
"streetno",
ComparisonOperator.EQUAL,
"42" );This gives the same error as Try 2.
So any comments and help is more than welcomed!
Thank you,
Vagelis Savvas11 November 2010 um 19:14 Uhr #2741Claudia Mangstl
TeilnehmerHi Vagelis,
now I can say a bit more about this 🙂
Usually the CollectableSubCond is used to find datasets in subforms, which include a reference field to the parent item. But this is not what you have here.
What you have is one reference field in the person entity which ist a reference to one address.
To search for an address value you can do the search from the other site:
First find the address with the value 50 using a SearchCondition like:
CollectableComparison cond = org.nuclos.common.SearchConditionUtils.newMDComparison(org.nuclos.server.common.MasterDataMetaCache.getInstance().getMetaData("Address"), "streetNumber", ComparisonOperator.EQUAL, "50");
Collection ids = server.getMasterDataIds("Address", new org.nuclos.server.genericobject.searchcondition.CollectableSearchExpression(cond));
What you get here is the ID of the address dataset.
Now search in the person entity for this ID Value in personAddress:
CollectableComparison cond2 = org.nuclos.common.SearchConditionUtils.newMDReferenceComparison(MasterDataMetaCache.getInstance().getMetaData("Person"), "personAddress", );
Collection ids = server.getMasterDataIds("Person", new org.nuclos.server.genericobject.searchcondition.CollectableSearchExpression(cond2));
This should work.
Best regards,
Claudia M.23 November 2010 um 10:49 Uhr #2764Carsten Hof
TeilnehmerHi Claudia,
thanks a lot, this worked as you described 🙂
Nevertheless, can you give me two simple examples
(maybe based on Person and Address entities) of how
CollectableSubCondition and ReferencingCollectableSearchCondition
work? I would like to re-use them in my code whenever possible
instead of writing my own solution.Best,
Vagelis Savvas
29 November 2010 um 18:04 Uhr #2782Claudia Mangstl
TeilnehmerHi Vagelis,
in the current version these calls are not usable and cant’t be called by the RuleInterface. So I can’t give you an example. In order to clean up the RuleInterface in the future, we need to find out how to include these calles in the RuleInterface.
Regards,
Claudia -
AutorBeiträge