Re: EO Custom Data Type problem (repost)
Re: EO Custom Data Type problem (repost)
- Subject: Re: EO Custom Data Type problem (repost)
- From: Timo Höpfner <email@hidden>
- Date: Thu, 11 Mar 2004 16:03:23 +0100
Hi,
I'm still fighting with this problem... If anyone has an idea, please
let me know. I have a small reproduction project (XCode, 44KB ZIP) if
someone wants to try it by himself.
Thanks,
Timo
Am 04.03.2004 um 14:46 schrieb Timo Hvpfner:
> (This is a repost of the message, since I didn't see it appearing on
> the list. Sorry if you get it twice...)
>
> Hi,
>
> I have som problems using custom data types in EO. Basically I'm
> trying to use ERXMutableDictionary from Project Wonder. It seems like
> EO is sometimes returning NSData instead of the custom data type. I
> made some small project for reproduction of the issue. Here are the
> relavant parts:
>
> Entity "MyEntity", Attribute "myEntityDictionary":
> {
> adaptorValueConversionMethodName = toBlob;
> allowsNull = Y;
> columnName = myEntityDictionary;
> externalType = BLOB;
> name = myEntityDictionary;
> valueClassName = MyDictionary;
> valueFactoryMethodName = fromBlob;
> width = 255;
> }
>
> I modified the accessor-method to report the type recieved from
> storedValueForKey:
> public MyDictionary myEntityDictionary() {
> Object o = storedValueForKey("myEntityDictionary");
> if(o!=null){
> System.out.println("Got type "+o.getClass());
> }
> return (MyDictionary)o;
> }
>
>
> MyDictionary is a copy of ERXMutableDictionary. It contains the
> conversion methods:
>
> public class MyDictionary extends NSMutableDictionary {
> public static NSData toBlob(MyDictionary d) throws Exception {
> System.out.println("MyDictionary.toBlob");
> ...}
> public static MyDictionary fromBlob(NSData d) throws Exception {
> System.out.println("MyDictionary.fromBlob");
> ...}
> public NSData toBlob() throws Exception {
> return toBlob(this);
> }
> public Object clone() {...}
> ...}
>
> Repro code:
>
> private MyEntity getTestObject(){
> System.out.println("Main.getTestObject()");
>
> MyEntity myEntity=null;
> try{
> myEntity = (MyEntity)
> EOUtilities.objectMatchingKeyAndValue(session().defaultEditingContext()
> ,"MyEntity","myEntityName","test");
> }catch(Exception e){}
> return myEntity;
> }
>
> public WOComponent create()
> {
> System.out.println("Main.create()");
> MyEntity myEntity=getTestObject();
>
> if(myEntity!=null){
> session().defaultEditingContext().deleteObject(myEntity);
> session().defaultEditingContext().saveChanges();
>
> }
>
> myEntity = new MyEntity();
> session().defaultEditingContext().insertObject(myEntity);
> myEntity.setMyEntityName("test");
> MyDictionary dict = new MyDictionary();
> dict.takeValueForKey("test","test");
> myEntity.setMyEntityDictionary(dict);
> session().defaultEditingContext().saveChanges();
>
> return null;
> }
>
> public WOComponent read()
> {
> System.out.println("Main.read()");
>
> try{
> System.out.println("Before invalidateAllObjects()");
> MyEntity myEntity = getTestObject();
> if(myEntity!=null){
> System.out.println("retrieved dictionary:
> "+myEntity.myEntityDictionary());
> }
>
> session().defaultEditingContext().invalidateAllObjects();
> System.out.println("After invalidateAllObjects()");
>
> myEntity = getTestObject();
>
> if(myEntity!=null){
> System.out.println("retrieved dictionary:
> "+myEntity.myEntityDictionary());
> }
> }catch(ClassCastException e){
> System.out.println("Got Exception: "+e.getClass());
> }
> return null;
> }
>
>
> Output when calling "create()->read()"
>
> Main.create()
> Main.getTestObject()
> Got type class MyDictionary
> MyDictionary.toBlob
> MyDictionary.toBlob
> Main.read()
> Before invalidateAllObjects()
> Main.getTestObject()
> Got type class MyDictionary
> retrieved dictionary: {test = "test"; }
> After invalidateAllObjects()
> Main.getTestObject()
> Got type class com.webobjects.foundation.NSData
> Got Exception: class java.lang.ClassCastException
> ...
>
> As you can see "fromBlob" is never called.
> Any idea what's going wrong here? When I catch the ClassCastException
> and manually call fromBlob with the NSData recieved, I get a correct
> "MyDictionary"...
>
> Timo
_______________________________________________
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.