Re: Fetching data from a model
Re: Fetching data from a model
- Subject: Re: Fetching data from a model
- From: Hugi Thordarson <email@hidden>
- Date: Sun, 1 Oct 2017 20:12:38 +0000
Hi André
first, for the simple solution: Avoid using qualifierWithQualifierFormat. If
you want to construct an equality qualifier, use EOKeyValueQualifier instead.
new EOKeyValueQualifier( MyEntity.A_KEY, EOQualifier.QualifierOperatorEqual,
timestampA )
This will work if you're just tinkering with an old project and need to get it
working real quick.
But it's still not really optimal, it's old style. A new/current project that
incorporates Project Wonder will usually generate EOs that contain an ERXKey
for each attribute instead of just Strings (A_KEY, B_KEY etc.). ERXKey provides
you with convenience methods to construct qualifiers so using them you can do
stuff like this:
EOQualifier q = MyEntity.A.eq( timestampA ).and( MyEntity.B.eq( timestampB
).and( MyEntity.C.eq( timestampC );
So, use the first method to get up and running real quick, but use method B if
you have a current project with ERXKeys (or upgrade your project to use them if
this codebase has a future).
Cheers,
- hugi
> On 1 Oct 2017, at 19:55, André Rothe <email@hidden> wrote:
>
> Hi,
>
> I created a model with EOModeler. There are some classes in my project which
> represent the entities of my model. Now I come to the point, that I must
> fetch data from the database. In my Main component I created an EOQualifier
> which combines 4 attributes:
>
> EOQualifier eq = new EOAndQualifier(new NSArray<EOQualifier>(new
> EOQualifier[] {
> EOQualifier.qualifierWithQualifierFormat(MyEntity.A_KEY + "=%s",
> new NSArray<Object>(new Object[] { getSession().getA() })),
> EOQualifier.qualifierWithQualifierFormat(MyEntity.B_KEY + "=%s",
> new NSArray<Object>(new Object[] { getSession().getB() })),
> EOQualifier.qualifierWithQualifierFormat(MyEntity.C_KEY + "=%s",
> new NSArray<Object>(new Object[] { getSession().getC() })),
> EOQualifier.qualifierWithQualifierFormat(MyEntity.D_KEY + "<=?",
> new NSArray<Object>(new Object[] {new NSTimestamp() }))
> }));
>
> The D_KEY attribute is a timestamp, how I can define the format for such a
> column? In
> https://wiki.wocommunity.org/download/attachments/1049043/EnterpriseObjects.pdf
> I did not find any information about Timestamp attributes. Is that the right
> way to fetch data from the database? I would use the Qualifier with:
>
> EOEditingContext ec = getSession().defaultEditingContext();
> NSArray res = ec.objectsWithFetchSpecification(new
> EOFetchSpecification(StXSession.ENTITY_NAME, eq, null));
>
>
> Best regards
> Andre
> _______________________________________________
> 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
_______________________________________________
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