I have a need to copy a record in a database, and then modify the
original and the copy. I make a new record using
ParcelORM newOne = (ParcelORM) ParcelORM.meta.createWithGeneratedKey();
then I want to copy all of the fields except the key field (which has
been generated).
I can't use clone() because it won't work once I'm attached. So I'm
proceeding as shown below, and would appreciate any feedback.
First I wrote code in my user object to copy the fields:
for (int i=0;i<fieldValues.length;i++) {
if (!meta.isKeyField(i)) {
fieldValues[i]= source.fieldValues[i];
}
}
setDirty();
The I added this method to SRecordMeta:
public boolean isKeyField(int i) {
for (int k=0;k<keySFieldMetas.size();k++) {
SFieldMeta s = (SFieldMeta) keySFieldMetas.get(k);
if (s.fieldIndex==i) return true;
}
return false;
}
}
So I'm copying all the fields that aren't key fields. The foreign key
fields might still be a problem, I don't have any foreign keys so it's
hard to know.
Another approach would be to detach the original, use the deprecated
clone() method, then try to reattach the original and attach the copy.
But that seems overly complex.
--
John Abraham
jabraham@...