EO Custom Data Type problem (repost)
EO Custom Data Type problem (repost)
- Subject: EO Custom Data Type problem (repost)
- From: Timo Höpfner <email@hidden>
- Date: Thu, 4 Mar 2004 14:46:06 +0100
(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.