Re: accessing the primarykey???
Re: accessing the primarykey???
- Subject: Re: accessing the primarykey???
- From: Lachlan Deck <email@hidden>
- Date: Thu, 15 Jul 2010 12:54:37 +1000
On 14/07/2010, at 10:53 PM, Theodore Petrosky wrote:
> What I wanted was a way to create a qualifier searching for a primaryKey... I am using the primaryKey as the jobNumber so what I ended up with is:
>
> try {
> versionQual = Version.VERSION_STATUS.dot(VersionStatus.VERSION_STATUS_TITLE).eq("Billed").and(Version.JOB.eq( (Job) EOUtilities.objectWithPrimaryKeyValue(versionListEC, "Job", Integer.parseInt(jobNumberHolder()))));
>
> } catch (EOObjectNotAvailableException na){
> noSuchJobNumber = true;
> versionQual = Version.VERSION_STATUS.dot(VersionStatus.VERSION_STATUS_TITLE).eq("Billed");
> } catch (NumberFormatException nfe) {
> noSuchJobNumber = true;
> versionQual = Version.VERSION_STATUS.dot(VersionStatus.VERSION_STATUS_TITLE).eq("Billed");
> }
>
> versionList = Version.fetchVersions(versionListEC, versionQual, null);
> theVersionListDG.setObjectArray(versionList);
> return null;
>
> where I get the primaryKey from jobNumberHolder()....
>
> it works great. I hope it is 'correct'.
Could be improved so that you do a single fetch to obtain versionList. Something along these lines...
EOEntity jobEOEntity = EOUtilities.entityNamed(ec, Job.ENTITY_NAMED);
EOQualifier jobNumberQualifier = jobEOEntity.qualifierForPrimaryKey(/* see previous email */);
EOEntity versionEOEntity = EOUtilities.entityNamed(ec, Version.ENTITY_NAMED);
EOQualifier jobRelationQualifier = EOQualifierSQLGeneration.Support._qualifierMigratedFromEntityRelationshipPath(jobNumberQualifier, versionEOEntity, Version.JOB_KEY);
EOQualifier versionQualifier = Version.VERSION_STATUS.dot(VersionStatus.VERSION_STATUS_TITLE).eq("Billed").and(jobRelationQualifier);
boolean noSuchJobNumber = true;
NSArray<Version> versionList = NSArray.emptyArray();
try {
versionList = Version.fetchVersions(ec, versionQualifier, null);
noSuchJobNumber = false;
}
catch (EOObjectNotAvailableException e) {
// boo hoo
}
catch (NumberFormatException e) {
// boo hiss
}
with regards,
--
Lachlan Deck
_______________________________________________
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