Re: Documentation suggestion
Klaus Wuestefeld <[email protected]>
| Newsgroups | gmane.comp.java.prevayler |
|---|---|
| Message-ID | <[email protected]> |
Karl, If you write up a full doc we can put it on the site. No problem. See you, Klaus. On Mon, Jan 11, 2010 at 6:32 AM, Karl Wettin <[email protected]> wrote: > Even though it's not that hard to figure out by one self, I think it > might help some users if at least one of the example projects (or if > the Wiki at some smart place) as built to show the pitfalls of > java.io.Serializable and explained how one can achieve backwards > compatibillity using local versioning of domain objects with > Externalizable. It makes life so much easier for people such as me > that have an evolving domain class model. > > Dry-coded example: > > public abstract class LegalPerson implements Serializable, > Externalizable { > > private static final long serialVersionUID = 1l; // never change this > > private String id; > private String name; > > @Override > public void writeExternal(ObjectOutput objectOutput) throws > IOException { > objectOutput.writeInt(1); // version > objectOutput.writeObject(id); > objectOutput.writeObject(name); > } > > @Override > public void readExternal(ObjectInput objectInput) throws > IOException, ClassNotFoundException { > int version = objectInput.readInt(); > if (version == 1) { > id = (String)objectInput.readObject(); > name = (String)objectInput.readObject(); > } else { > throw new IOException("Unknown local version: " + version); > } > } > } > > public abstract class Organization extends LegalPerson { > > private static final long serialVersionUID = 1l; // never change this > > private String organizationNumber; > > @Override > public void writeExternal(ObjectOutput objectOutput) throws > IOException { > super.writeExternal(objectOutput); > > objectOutput.writeInt(1); // version > objectOutput.writeObject(organizationNumber); > } > > @Override > public void readExternal(ObjectInput objectInput) throws > IOException, ClassNotFoundException { > super.readExternal(objectInput); > > int version = objectInput.readInt(); > if (version == 1) { > organizationNumber = (String)objectInput.readObject(); > } else { > throw new IOException("Unknown local version: " + version); > } > } > } > > > ------------------------------------------------------------------------------ > This SF.Net email is sponsored by the Verizon Developer Community > Take advantage of Verizon's best-in-class app development support > A streamlined, 14 day to market process makes app distribution fast and easy > Join now and get one step closer to millions of Verizon customers > http://p.sf.net/sfu/verizon-dev2dev > _______________________________________________ > To unsubscribe go to the end of this page: http://lists.sourceforge.net/lists/listinfo/prevayler-discussion > _______________________________________________ > "Databases in Memoriam" -- http://www.prevayler.org > ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ To unsubscribe go to the end of this page: http://lists.sourceforge.net/lists/listinfo/prevayler-discussion _______________________________________________ "Databases in Memoriam" -- http://www.prevayler.org