Re: Getting an abstract ID key - how?
Re: Getting an abstract ID key - how?
- Subject: Re: Getting an abstract ID key - how?
- From: Chuck Hill <email@hidden>
- Date: Sat, 01 Feb 2003 12:27:44 -0800
If I understand correctly (and I'm not sure I do), I can think of several
ways to do this.
1. One the page with the WORepetition, make a cover method to return the
sorted relationship. Bind the list of the WORepetition to this method.
// Assumptions:
// 1. public User user() or a similar method exists that returns the logged
in user
// 2. The relationship that needs to be sorted is user().clients()
protected NSArray sortedClientList = null;
public NSArray sortedClients()
{
// Lazy (just in time) creation of sorted list.
// The list is cached for efficiency
if (sortedClientList == null)
{
// copy the client list
NSMutableArray sortedClientList= new NSMutableArray(user().clients());
// Create your sort ordering here to sort unsorted clients
NSArray sortOrderings = ???
// Sort away!
EOSortOrdering.sortArrayUsingKeyOrderArray(sortedClientList,
sortOrderings );
}
return sortedClientList;
}
2. Change how you fetch the clients. The user has already logged in. You
know the user (otherwise, how would you get the PK?), use that to fetch.
In your model you have a realtionship user.clients and, I presume, a back
pointing relationship on each client: client.adminUser (or whatever you
called it). Change your session to this:
// I'm lazy so I like to use EOUtilities
// aside: laziness and paranoid are supreme virtues in a programmer :-)
import com.webobjects.eoaccess.EOUtilities;
// Assuming these exist with get methods
protected User loggedInUser;
protected NSArray clientList;
NSArray clientList =
EOUtilities.objectsMatchingKeyAndValue(defaultEditingContext(),
"TbClient",
"adminUser",
loggedInUser());
See! No need to do nasty things with a PK in WO! Unless you need this all
over the place, I like solution one better. If I needed it in more than
one place, I'd move this code to the User class and *not* cache it. The
second solution has a defect in that the list will not be updated
automatically if new clients are added. The first solution will update as
long as you return a new instance of the page. You can make the second one
work, but you need to tell the Session / User when to recreate the sorted list
HTH
Chuck
At 07:24 PM 01/02/2003 +0000, Jonathan Fleming wrote:
>well Chuck,
>I want to use it as a reference for an EOQualifier so I can get the user's
>object(s) with a fetchspec when they are logged in. I have a WORepetition
>bound to an NSMutableArray so that I can use in memory sort ordering by
>lastName, companyName etc., but if I bind the WORepetition to the
>relationship in the EOModel I gain what I am trying to do with the ID but
>loose the ability to use in memory sort ordering even though the
>relationship is also a NSMuttableArray.
>So, I have found that if I instantiate (think I've used the right term here)
>a variable with the users ID number I get what I want completly, all the
>objects/database rows for that user.
>As you can see in the code below which sits in the constructor of the
>Session Class the fetchspec works when the local var is given an ID number
>manually but obviously I need to do this progmatically as soon as the user
>is logged in to their session.
>
>/*
> * variable use to preset bindings array else
> * java.lang.IllegalStateException exception will be caused
> * this local var is here for test purposes only!!!
> */
> String adminUserID = "3";
>
> System.out.println(this.getClass().getName() + "s awake method
>called");
> // build fetch specification
> NSArray bindings = new NSArray(
> new Object [] {
> new Integer( adminUserID ) } );
>
> EOQualifier qualifier =
> EOQualifier.qualifierWithQualifierFormat("adminUserID = %@",
>bindings );
> fetchSpec = new EOFetchSpecification("TbClient", qualifier, null);
> // fetch
> fetchTbClientList();
> }
>
>
>I imagine i'm going t get a scolding now... oh well, at least I'll learn.
>
>Regards
>Jonathan
>
>Ps The Pragmatic Programmer book is being delivered on Monday 3rd Feb,
>looking forward to cleaning up my coding act.
>
>
>
>
>
>>From: Chuck Hill <email@hidden>
>>To: "Jonathan Fleming" <email@hidden>,
>>email@hidden
>>Subject: Re: Getting an abstract ID key - how?
>>Date: Sat, 01 Feb 2003 09:58:37 -0800
>>
>>Why do you want to use the PK as a ref number? For what purpose?
>>
>>If you really are going to use the PK for some use other than as a PK, why
>>do you object to being honest ;-) about it and stating so in the EOModel?
>>Yes, you can rape it out, but why?
>>
>>
>>Chuck
>>
>>
>>At 05:34 PM 01/02/2003 +0000, Jonathan Fleming wrote:
>> >I have created a user object in a secure login area and I want to obtain
>>the
>> >primary key of that object as a ref number, but the ID in the entity is
>>set
>> >as abstract so I can not access it from the EOCustomObject (java file)
>> >created by the EOModel. How do I get to present the primary key in an
>>iVar
>> >without turning the diamond on in the EOModel to get the primary key
>> >displayed in an instance variable?
>> >
>> >The table/entity is AdminUser = adminUser
>> >the ID is adminUserID
>> >when I enclose the object in a WOString component I can see:
>> >{values = {accessLevel = "Moderator"; lastName = "Fleming"; clients =
>> >"<com.webobjects.eocontrol._EOCheapCopyMutableArray 6df389
>> >(<EOAccessArrayFaultHandler clients _EOIntegralKeyGlobalID[AdminUser
>> >(java.lang.Integer)3]>)>"; }; this = "<AdminUser 2f72d8
>> >_EOIntegralKeyGlobalID[AdminUser (java.lang.Integer)3]>"; }
>> >
>> >but I don't know how to get the adminUserID (3) or the
>> >_EOIntegralKeyGlobalID[AdminUser (java.lang.Integer)3] out so I can
>>access
>> >an use it for reference
>> >
>> >Can you help?
>> >
>> >Simple enough question, but with WebObjects it an proove very difficult
>> >especially when you don't know how and I don't know how.
>> >
>> >Kind regards
>> >Jonathan
>> >
>> >_________________________________________________________________
>> >Use MSN Messenger to send music and pics to your friends
>> >http://messenger.msn.co.uk
>> >_______________________________________________
>> >webobjects-dev mailing list | email@hidden
>> >Help/Unsubscribe/Archives:
>>http://www.lists.apple.com/mailman/listinfo/webobjects-dev
>> >Do not post admin requests to the list. They will be ignored.
>> >
>>
>>--
>>
>>Chuck Hill email@hidden
>>Global Village Consulting Inc. http://www.global-village.net
>>_______________________________________________
>>webobjects-dev mailing list | email@hidden
>>Help/Unsubscribe/Archives:
>>http://www.lists.apple.com/mailman/listinfo/webobjects-dev
>>Do not post admin requests to the list. They will be ignored.
>
>
>_________________________________________________________________
>It's fast, it's easy and it's free. Get MSN Messenger today!
>http://messenger.msn.co.uk
>
>
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.