db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig Russell <Craig.Russ...@Sun.COM>
Subject Re: JPOX enhancer bug
Date Wed, 10 Aug 2005 19:48:58 GMT
Hi Andy,

On Aug 10, 2005, at 11:44 AM, Andy Jefferson wrote:

>> I've patched the JDOImplHelper class to make the construct method
>> static. There are no issues that I can think of to make this method
>> static, so I'll change this.
>>
>> Does this help?
>>
>
> Hi Craig,
>
> Thanks for looking into it. Referring to Michael's mail of the added
> jdoCopyKeyFieldsFromObjectId() method, the error is at the end  
> where it needs
> to create a Date (or Locale, or Currency, or whatever) from the  
> "oid". Is
> construct() doing this ?

The helper method creates an instance of Currency, Locale, or Date  
given a String.

> or is it doing the reverse (I remember scanning
> through it when you added ObjectIdentity and seeing the sort of  
> parsing I
> need to create an object from the oid, but may have been mistaken).
>
>      protected void jdoCopyKeyFieldsFromObjectId(Object oid)
>      {
>          if(!(oid instanceof ObjectIdentity))
>          {
>              throw new ClassCastException("key class is not
> javax.jdo.identity.ObjectIdentity or null");
>          } else
>          {
>              ObjectIdentity o = (ObjectIdentity)oid;
>              id = new Date(o.getKey());

I should have noticed this earlier. There already is a proper Date in  
the ObjectIdentity oid instance and all you need to do is to get it  
and cast it.

id = (Date)o.getKeyAsObject();

You can also do validity checking to make sure that the  
ObjectIdentity instance has the proper key type:

Object idAsObject = o.getKeyAsObject();
if (idAsObject.getClass().getName() != "java.util.Date") throw  
StupidUserException.

Craig

>              return;
>          }
>      }
>
> -- 
> Andy
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Mime
View raw message