Javadogs,

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

Thanks,

Craig

Begin forwarded message:

From: Martin Zaun <[EMAIL PROTECTED]>
Date: August 25, 2005 4:05:30 PM PDT
To: Craig Russell <[EMAIL PROTECTED]>
Cc: Michael Bouschen <[EMAIL PROTECTED]>
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:[EMAIL PROTECTED]

P.S. A good JDO? O, Gasp!


Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to