Date: August 25, 2005 4:05:30 PM PDT
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);
}
}