1.0

Table Of Contents
Evolution - Your tools for evolving a class which simply implements java.io.Serializable are very limited.
Fortunately, it is easy to write a version-aware UDT which implements java.io.Serializable and can evolve itself over
time. For example, here is the rst version of such a class:
package com.acme.types;
import java.io.*;
import java.math.*;
public class Price implements Externalizable
{
// initial version id
private static final int FIRST_VERSION = 0;
public String currencyCode;
public BigDecimal amount;
// zero-arg constructor needed by Externalizable machinery
public Price() {}
public Price( String currencyCode, BigDecimal amount )
{
this.currencyCode = currencyCode;
this.amount = amount;
}
// Externalizable implementation
public void writeExternal(ObjectOutput out) throws IOException
{
// first write the version id
out.writeInt( FIRST_VERSION );
// now write the state
out.writeObject( currencyCode );
out.writeObject( amount );
}
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException
{
// read the version id
int oldVersion = in.readInt();
if ( oldVersion < FIRST_VERSION ) {
throw new IOException( "Corrupt data stream." );
}
if ( oldVersion > FIRST_VERSION ) {
throw new IOException( "Can't deserialize from the future." );
}
currencyCode = (String) in.readObject();
amount = (BigDecimal) in.readObject();
}
}
After this, it is easy to write a second version of the user-dened type which adds a new eld. When old versions of
Price values are read from the database, they upgrade themselves on the y. Changes are shown in bold:
package com.acme.types;
vFabric SQLFire User's Guide158
Developing Applications with SQLFire