net.jot.persistance
Class JOTDBUpgrader

java.lang.Object
  extended by net.jot.persistance.JOTDBUpgrader

public abstract class JOTDBUpgrader
extends java.lang.Object

Extend this class to create your own DBUpdater. If you have an existing JOTDB (Using JOTMOdel's) and you need to change some model/tables definition (ie: add fields, rename columns etc ...) you should create a DBUpdater from it and imp,ement upgradeDb() You must define your implementaion in db.properties: Ex: db.upgrader.class = com.mycomp.mydb.MyUpgrader Then in the upgradeDb() you can handle the upgrade,

Author:
thibautc

Field Summary
static int ALTER_TYPE_BIGINT_TO_DECIMAL
           
static int ALTER_TYPE_DATE_TO_TIMESTAMP
           
static int ALTER_TYPE_INT_TO_BIGINT
           
static int ALTER_TYPE_INT_TO_DOUBLE
           
static int ALTER_TYPE_INT_TO_FLOATL
           
static int ALTER_TYPE_SMALLINT_TO_INT
           
static int ALTER_TYPE_TIMESTAMP_TO_DATE
           
static int ALTER_TYPE_TINYINT_TO_SMALLINT
           
 
Constructor Summary
protected JOTDBUpgrader()
           
 
Method Summary
 void addTableColumn(java.lang.Class modelClass, java.lang.String fieldName, java.lang.Object defaultValue)
          Add a new Field to a table The field must exists in the table model (JOTModel).
abstract  int getLatestVersion()
          return the DBModel Version(code).
abstract  void upgradeDb(int version)
          Implement this method to handle a db upgrade.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALTER_TYPE_TINYINT_TO_SMALLINT

public static final int ALTER_TYPE_TINYINT_TO_SMALLINT
See Also:
Constant Field Values

ALTER_TYPE_SMALLINT_TO_INT

public static final int ALTER_TYPE_SMALLINT_TO_INT
See Also:
Constant Field Values

ALTER_TYPE_INT_TO_BIGINT

public static final int ALTER_TYPE_INT_TO_BIGINT
See Also:
Constant Field Values

ALTER_TYPE_BIGINT_TO_DECIMAL

public static final int ALTER_TYPE_BIGINT_TO_DECIMAL
See Also:
Constant Field Values

ALTER_TYPE_INT_TO_FLOATL

public static final int ALTER_TYPE_INT_TO_FLOATL
See Also:
Constant Field Values

ALTER_TYPE_INT_TO_DOUBLE

public static final int ALTER_TYPE_INT_TO_DOUBLE
See Also:
Constant Field Values

ALTER_TYPE_DATE_TO_TIMESTAMP

public static final int ALTER_TYPE_DATE_TO_TIMESTAMP
See Also:
Constant Field Values

ALTER_TYPE_TIMESTAMP_TO_DATE

public static final int ALTER_TYPE_TIMESTAMP_TO_DATE
See Also:
Constant Field Values
Constructor Detail

JOTDBUpgrader

protected JOTDBUpgrader()
Method Detail

upgradeDb

public abstract void upgradeDb(int version)
                        throws java.lang.Exception
Implement this method to handle a db upgrade. You can use the other methods provided here to upgrade your tables(ie: addTableColumn etc...) Make sure to bump the version after each version upgrade : setVersion(x); Note: if the DB is brand new, the version passed will be "1".

Throws:
java.lang.Exception

getLatestVersion

public abstract int getLatestVersion()
return the DBModel Version(code). a.k.a the version we should be at after the upgrade.


addTableColumn

public void addTableColumn(java.lang.Class modelClass,
                           java.lang.String fieldName,
                           java.lang.Object defaultValue)
                    throws java.lang.Exception
Add a new Field to a table The field must exists in the table model (JOTModel).

Throws:
java.lang.Exception