Last update: 2011-06-23

org.proteios.core
Class AbstractUpdateToSchemaVersion

java.lang.Object
  extended by org.proteios.core.AbstractUpdateToSchemaVersion
All Implemented Interfaces:
UpdateToSchemaVersionInterface
Direct Known Subclasses:
UpdateToSchemaVersion10, UpdateToSchemaVersion2, UpdateToSchemaVersion3, UpdateToSchemaVersion4, UpdateToSchemaVersion5, UpdateToSchemaVersion6, UpdateToSchemaVersion7, UpdateToSchemaVersion8, UpdateToSchemaVersion9, UpdateToSchemaVersionTmpl

public abstract class AbstractUpdateToSchemaVersion
extends Object
implements UpdateToSchemaVersionInterface

This abstract class contains methods to perform incremental update and adjustment of existing database items from a previous schema version to the version corresponding to this class. It contains common attributes and methods performing general consistency checks and update of schema version, and is intended to be the extended by classes that overrides the methods performing the actual update and adjustments of database items. Based on BASE2 class src/core/net/sf/basedb/core/Update.java, but adapted to use a main updater class that performs a general update by calling methods in classes that an incremental update from one version to the next.

Version:
2.0
Author:
Olle
Last modified
$Date: 2007-02-08 10:14:33Z $

Constructor Summary
AbstractUpdateToSchemaVersion()
           
 
Method Summary
 int adjustExistingItems(org.hibernate.Session session)
          Adjust the existing items in the database to be compatible with the latest mappings corresponding to this class.
protected abstract  int adjustItemsToNewSchemaVersion(org.hibernate.Session session)
          Adjust the existing items in the database to be compatible with the latest mappings corresponding to this class.
abstract  int getUpdateSchemaVersion()
          Get the update schema version.
 int update(org.hibernate.Session session)
          Update the database by modifying existing items to follow new requirements.
protected abstract  int updateToNewSchemaVersion(org.hibernate.Session session)
          Updates the database to the version corresponding to this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractUpdateToSchemaVersion

public AbstractUpdateToSchemaVersion()
Method Detail

update

public int update(org.hibernate.Session session)
           throws BaseException
Update the database by modifying existing items to follow new requirements. Performs updates between the previous schema version and the version the class corresponds to.

Specified by:
update in interface UpdateToSchemaVersionInterface
Parameters:
session - org.hibernate.Session a Hibernate session to use for transactions.
Returns:
int the schema version this class updates to.
Throws:
BaseException

adjustExistingItems

public int adjustExistingItems(org.hibernate.Session session)
                        throws BaseException
Adjust the existing items in the database to be compatible with the latest mappings corresponding to this class. No update to the schema version should be done here. The code must also consider the case that the update fails at a later stage and that the same update is executed again.

Specified by:
adjustExistingItems in interface UpdateToSchemaVersionInterface
Parameters:
session - org.hibernate.Session the Hibernate session to use.
Returns:
int The number of affected items.
Throws:
BaseException

getUpdateSchemaVersion

public abstract int getUpdateSchemaVersion()
Get the update schema version.

Returns:
int the update schema version.

updateToNewSchemaVersion

protected abstract int updateToNewSchemaVersion(org.hibernate.Session session)
                                         throws BaseException
Updates the database to the version corresponding to this class. Override this method to update the database by one or more queries managed by Hibernate.

Parameters:
session - org.hibernate.Session the Hibernate session to use.
Returns:
int The number of affected items.
Throws:
BaseException

adjustItemsToNewSchemaVersion

protected abstract int adjustItemsToNewSchemaVersion(org.hibernate.Session session)
                                              throws BaseException
Adjust the existing items in the database to be compatible with the latest mappings corresponding to this class. Override this method to adjust items by one or more queries managed by Hibernate.

Parameters:
session - org.hibernate.Session the Hibernate session to use.
Returns:
int The number of affected items.
Throws:
BaseException

Last update: 2011-06-23