com.xpn.xwiki.store.migration
Class AbstractDataMigrationManager

java.lang.Object
  extended by com.xpn.xwiki.store.migration.AbstractDataMigrationManager
All Implemented Interfaces:
DataMigrationManager, org.xwiki.component.phase.Initializable
Direct Known Subclasses:
HibernateDataMigrationManager

public abstract class AbstractDataMigrationManager
extends Object
implements DataMigrationManager, org.xwiki.component.phase.Initializable

Template for DataMigrationManager.

Since:
3.4M1
Version:
$Id: 4ed4814f68908f5864d768e6d39ce7358747f36c $

Nested Class Summary
protected  class AbstractDataMigrationManager.XWikiMigration
          Internal class used to find out the data migration that are being forced in the XWiki configuration file.
 
Field Summary
protected  org.xwiki.component.manager.ComponentManager componentManager
          Component manager used to access stores and data migrations.
protected  org.slf4j.Logger logger
          Logger.
protected  Collection<AbstractDataMigrationManager.XWikiMigration> migrations
          Ordered list of migrators that may be applied.
protected  org.xwiki.observation.ObservationManager observationManager
          Component manager used to access stores and data migrations.
 
Constructor Summary
AbstractDataMigrationManager()
          Unified constructor for all subclasses.
 
Method Summary
 void checkDatabase()
          Check current database version and proceed to migrations.
protected abstract  List<? extends DataMigration> getAllMigrations()
           
 DataMigrationStatus getDataMigrationStatus()
           
 XWikiDBVersion getDBVersion()
           
protected  XWikiDBVersion getDBVersionFromConfig()
          read data version from xwiki.cfg.
protected  XWikiDBVersion getDBVersionFromDatabase()
          Read data version from database.
protected  Map<XWikiDBVersion,AbstractDataMigrationManager.XWikiMigration> getForcedMigrations()
           
 XWikiDBVersion getLatestVersion()
           
protected  String getMainXWiki()
           
protected  Collection<AbstractDataMigrationManager.XWikiMigration> getNeededMigrations()
           
protected  List<String> getVirtualWikisDatabaseNames()
           
protected  XWikiConfig getXWikiConfig()
           
protected  XWikiContext getXWikiContext()
           
 void initialize()
           
protected abstract  void initializeEmptyDB()
           
 void initNewDB()
          Setup the schema of a new DB and set it to the latest version (not running migrations).
protected  boolean isVirtualMode()
          Deprecated. Virtual mode is on by default, starting with XWiki 5.0M2.
protected  void setDBVersion(XWikiDBVersion version)
          Update database version and status cache (not after a migration, use updateMigrationStatus).
protected abstract  void setDBVersionToDatabase(XWikiDBVersion version)
           
protected  void startMigrations()
          Start the migration process.
protected  void startMigrations(Collection<AbstractDataMigrationManager.XWikiMigration> migrations)
           
protected abstract  void updateSchema(Collection<AbstractDataMigrationManager.XWikiMigration> migrations)
          Update database schema to the latest structure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

componentManager

@Inject
protected org.xwiki.component.manager.ComponentManager componentManager
Component manager used to access stores and data migrations.


observationManager

@Inject
protected org.xwiki.observation.ObservationManager observationManager
Component manager used to access stores and data migrations.


migrations

protected Collection<AbstractDataMigrationManager.XWikiMigration> migrations
Ordered list of migrators that may be applied.


logger

@Inject
protected org.slf4j.Logger logger
Logger.

Constructor Detail

AbstractDataMigrationManager

public AbstractDataMigrationManager()
Unified constructor for all subclasses.

Method Detail

getXWikiContext

protected XWikiContext getXWikiContext()
Returns:
XWikiContext

getXWikiConfig

protected XWikiConfig getXWikiConfig()
Returns:
XWikiConfig to read configuration from xwiki.cfg

isVirtualMode

protected boolean isVirtualMode()
Deprecated. Virtual mode is on by default, starting with XWiki 5.0M2.

Returns:
true if running in virtual mode

getVirtualWikisDatabaseNames

protected List<String> getVirtualWikisDatabaseNames()
                                             throws DataMigrationException
Returns:
list of virtual database names
Throws:
DataMigrationException - on error

getMainXWiki

protected String getMainXWiki()
Returns:
the main XWiki database name

initialize

public void initialize()
                throws org.xwiki.component.phase.InitializationException
Specified by:
initialize in interface org.xwiki.component.phase.Initializable
Throws:
org.xwiki.component.phase.InitializationException

getDBVersionFromConfig

protected XWikiDBVersion getDBVersionFromConfig()
read data version from xwiki.cfg.

Returns:
data version if set, or null.

getDBVersionFromDatabase

protected XWikiDBVersion getDBVersionFromDatabase()
                                           throws DataMigrationException
Read data version from database.

Returns:
data version or null if this is a new database
Throws:
DataMigrationException - in case of an unexpected error

getDBVersion

public final XWikiDBVersion getDBVersion()
                                  throws DataMigrationException
Specified by:
getDBVersion in interface DataMigrationManager
Returns:
current DB version or null for a new database
Throws:
DataMigrationException - if any error

getDataMigrationStatus

public DataMigrationStatus getDataMigrationStatus()
                                           throws DataMigrationException
Specified by:
getDataMigrationStatus in interface DataMigrationManager
Returns:
current DB migration status or null for a new database
Throws:
DataMigrationException - if any error

getLatestVersion

public final XWikiDBVersion getLatestVersion()
Specified by:
getLatestVersion in interface DataMigrationManager
Returns:
latest DB version

initNewDB

public void initNewDB()
               throws DataMigrationException
Description copied from interface: DataMigrationManager
Setup the schema of a new DB and set it to the latest version (not running migrations). This should be used on a newly created DB only

Specified by:
initNewDB in interface DataMigrationManager
Throws:
DataMigrationException - if any error

initializeEmptyDB

protected abstract void initializeEmptyDB()
                                   throws DataMigrationException
Throws:
DataMigrationException - if any error

setDBVersionToDatabase

protected abstract void setDBVersionToDatabase(XWikiDBVersion version)
                                        throws DataMigrationException
Parameters:
version - to set
Throws:
DataMigrationException - if any error

setDBVersion

protected final void setDBVersion(XWikiDBVersion version)
                           throws DataMigrationException
Update database version and status cache (not after a migration, use updateMigrationStatus).

Parameters:
version - database version to be stored
Throws:
DataMigrationException - if any error

updateSchema

protected abstract void updateSchema(Collection<AbstractDataMigrationManager.XWikiMigration> migrations)
                              throws DataMigrationException
Update database schema to the latest structure.

Parameters:
migrations - the migration that will be executed (since 4.0M1)
Throws:
DataMigrationException - if any error

checkDatabase

public void checkDatabase()
                   throws MigrationRequiredException,
                          DataMigrationException
Description copied from interface: DataMigrationManager
Check current database version and proceed to migrations. Migration is processed only once, and depends on the following configuration:

Specified by:
checkDatabase in interface DataMigrationManager
Throws:
MigrationRequiredException - when version is incompatible with current version
DataMigrationException - when an error occurs during check.

startMigrations

protected void startMigrations()
                        throws DataMigrationException
Start the migration process. This one is not thread safe and should be synchronized. The migrations field should not be null.

Throws:
DataMigrationException - in case of any error

getNeededMigrations

protected Collection<AbstractDataMigrationManager.XWikiMigration> getNeededMigrations()
                                                                               throws DataMigrationException
Returns:
collection of DataMigration in ascending order, which need be executed.
Throws:
DataMigrationException - if any error

getForcedMigrations

protected Map<XWikiDBVersion,AbstractDataMigrationManager.XWikiMigration> getForcedMigrations()
                                                                                       throws DataMigrationException
Returns:
a map of forced DataMigration for this manager
Throws:
DataMigrationException - id any error

startMigrations

protected void startMigrations(Collection<AbstractDataMigrationManager.XWikiMigration> migrations)
                        throws DataMigrationException
Parameters:
migrations - - run this migrations in order of collection
Throws:
DataMigrationException - if any error

getAllMigrations

protected abstract List<? extends DataMigration> getAllMigrations()
                                                           throws DataMigrationException
Returns:
List of all DataMigration for this manager
Throws:
DataMigrationException - if any error


Copyright © 2004–2014 XWiki. All rights reserved.