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 Fwd: code sample jdoNewObjectIdInstance()
Date Sat, 10 Sep 2005 14:32:45 GMT
Javadogs,

I believe that this represents the intent of the specification.  
Please comment if you disagree.

Thanks,

Craig

Begin forwarded message:

> From: Martin Zaun <martin.zaun@sun.com>
> Date: August 25, 2005 4:05:30 PM PDT
> To: Craig Russell <Craig.Russell@Sun.COM>
> Cc: Michael Bouschen <mbo.tech@spree.de>
> Subject: code sample jdoNewObjectIdInstance()
>
>
>
> Craig,
>
> below's the jdoNewObjectIdInstance() code sample we've discussed.
>
> I'm putting it into the generator and will get back on how to run
> the TCK on the generated-compiled classes.
>
> Martin
>
> class XXX {
>
>     static private final errMsg = I18N("illegal object id type");
>
>     // datastore identity
>     public Object jdoNewObjectIdInstance() {
>     return null;
>     }
>
>     public Object jdoNewObjectIdInstance(Object obj) {
>     return null;
>     }
>
>     // single field identity
>     public Object jdoNewObjectIdInstance() {
>     return new IntIdentity(Employee.class, this.empid);
>     }
>
>     public Object jdoNewObjectIdInstance(Object obj) {
>     if (obj instanceof String) {
>         return new IntIdentity(Employee.class, (String)obj);
>     }
>     if (obj instanceof Integer) {
>         return new IntIdentity(Employee.class, (Integer)obj);
>     }
>     if (obj instanceof ObjectIdFieldSupplier) {
>         return new IntIdentity(Employee.class,
>                    ((ObjectIdFieldSupplier)obj).fetchIntField(2));
>     }
>     throw new JDOUserException(errMsg);
>     }
>
>     // application identity
>     public Object jdoNewObjectIdInstance() {
>      EmployeeOid oid = new EmployeeOid(Employee.class);
>      oid.key1 = this.key1;
>      oid.key2 = this.key2;
>      return oid;
>     }
>
>     public Object jdoNewObjectIdInstance(Object obj) {
>     if (obj instanceof String) {
>         return new EmployeeOid((String)obj);
>     }
>     if (obj instanceof ObjectIdFieldSupplier) {
>         ObjectIdFieldSupplier fs = (ObjectIdFieldSupplier)obj;
>         EmployeeOid oid = new EmployeeOid();
>         oid.key1 = fs.fetchIntField(2);
>         oid.key2 = fs.fetchStringField(3);
>         return oid;
>     }
>     throw new JDOUserException(errMsg);
>     }
> }
>
>

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