Copying values directly
John Abraham <[email protected]>
| Newsgroups | gmane.comp.java.orm.simpleorm |
|---|---|
| Message-ID | <[email protected]> |
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
[email protected]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/SimpleORM/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/SimpleORM/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[email protected]
mailto:[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/