public class UpgradeDriver extends Object implements UpgradeDriverManager
TASK_ANALYZE, TASK_NONE, TASK_POSTUPGRADE, TASK_PREUPGRADE, TASK_ROLLBACK, TASK_UPGRADE
Constructor and Description |
---|
UpgradeDriver(DataSource dataSource,
InputStream upgradeScript,
AttributeValue[] defaultProperties)
Constructs an UpgradeDriver.
|
Modifier and Type | Method and Description |
---|---|
protected Connection |
acquireLock()
Acquires the exclusive right for the calling thread to access this
UpgradeDriver's state and use its JDBC connection.
|
void |
addUpgradeDriverListener(UpgradeDriverListener udl)
Adds an UpgradeDriverListener.
|
boolean |
analyze()
Starts or continues the analysis phase of a schema upgrade.
|
void |
dispose()
Disposes this UpgradeDriverManager.
|
int |
getCurrentTask()
Gets the current task being performed by the upgrade driver.
|
UpgradeStatus |
getMostRecentUpgrade()
Gets the most-recent schema upgrade performed or attempted.
|
protected PreparedStatement |
getPreparedStatement(String sql)
Gets a PreparedStatement for the specified SQL.
|
UpgradeStatus[] |
getUpgradeHistory()
Gets the history of all schema upgrades performed or attempted, in
chronological order.
|
protected long |
getUpgradeSequenceNextValue()
Returns the next value from the database sequence used for upgrades.
|
boolean |
isDisposed()
Gets whether
dispose has been called on this
UpgradeDriverManager. |
boolean |
postUpgrade()
Starts or continues the post-upgrade phase of a schema upgrade.
|
boolean |
preUpgrade()
Starts, continues, or repeats the pre-upgrade phase of a schema upgrade.
|
protected void |
releaseLock()
Releases the exclusive right for the calling thread to access this
UpgradeDriver's state and use its JDBC connection.
|
void |
removeUpgradeDriverListener(UpgradeDriverListener udl)
Removes an UpgradeDriverListener.
|
boolean |
rollback(boolean offline)
Starts or continues rolling back a schema upgrade.
|
protected static void |
rollbackTransaction(Connection conn)
Rolls-back the specified connection's transaction, best efforts.
|
void |
stop()
|
String |
toStatusLabel(int status)
Gets a string representation of the specified status value.
|
String |
toTaskLabel(int task)
Gets a string representation of the specified task value.
|
boolean |
upgrade(boolean offline)
Starts or continues the upgrade phase of a schema upgrade.
|
public UpgradeDriver(DataSource dataSource, InputStream upgradeScript, AttributeValue[] defaultProperties) throws IfsException
Default properties can be specified. These will be merged with the default properties in the upgrade script, overriding any like-named default properties there.
dataSource
- a DataSource for the repository's schemaupgradeScript
- the XML upgrade scriptdefaultProperties
- additional default properties, or null if noneIfsException
- if the operation failspublic void addUpgradeDriverListener(UpgradeDriverListener udl) throws IfsException
addUpgradeDriverListener
in interface UpgradeDriverManager
udl
- the listenerIfsException
- if the operation failspublic void removeUpgradeDriverListener(UpgradeDriverListener udl) throws IfsException
removeUpgradeDriverListener
in interface UpgradeDriverManager
udl
- the listenerIfsException
- if the operation failspublic boolean analyze() throws IfsException
An exception is thrown if analyze
, preUpgrade
,
upgrade
, postUpgrade
, or rollback
are underway in another thread.
When the method is called, the upgrade
status
must be Initialized or Analyzing. Otherwise an exception is
thrown.
If the analyze
method of an upgrade action
in the schema upgrade throws an exception, it is logged and rethrown.
The upgrade status is set to Analyzing.
The method returns when the analysis phase is completed or stopped
. If the analysis phase completes with no errors, the upgrade
status is set to Analyzed and true
is returned; otherwise
the upgrade status is set to Analyzing and false
is returned.
analyze
in interface UpgradeDriverManager
IfsException
- if the operation failspublic boolean preUpgrade() throws IfsException
An exception is thrown if analyze
, preUpgrade
,
upgrade
, postUpgrade
, or rollback
are underway in another thread.
When the method is called, the upgrade
status
must be Analyzed, Pre-upgrading, or Pre-upgraded. Otherwise an
exception is thrown.
If the preUpgrade
method of an upgrade
action in the schema upgrade throws an exception, it is logged and
rethrown. The upgrade status is set to Pre-upgrading.
The method returns when the pre-upgrade phase is completed or stopped
. If the pre-upgrade phase completes with no errors, the upgrade
status is set to Pre-upgraded and true
is returned; otherwise
the upgrade status is set to Pre-upgrading and false
is
returned.
preUpgrade
in interface UpgradeDriverManager
IfsException
- if the operation failspublic boolean upgrade(boolean offline) throws IfsException
An exception is thrown if analyze
, preUpgrade
,
upgrade
, postUpgrade
, or rollback
are underway in another thread.
When the method is called, the upgrade
status
must be Pre-upgraded or Upgrading. Otherwise an exception is
thrown.
The upgrade phase must be performed with the repository offline (that is,
with all nodes stopped). If the repository is not offline, as indicated
by the offline
argument, an exception is thrown.
If the upgrade
method of an upgrade
action in the schema upgrade throws an exception, it is logged and
rethrown. The upgrade status is set to Upgrading.
The method returns when the upgrade phase is completed or stopped
. If the upgrade phase completes with no errors, the upgrade
status is set to Upgraded, the schema version is updated to the target schema version
, and
true
is returned; otherwise the upgrade status is set to
Upgrading and false
is returned.
upgrade
in interface UpgradeDriverManager
offline
- whether the repository is offline (that is, whether
all nodes are stopped)IfsException
- if the operation failspublic boolean postUpgrade() throws IfsException
An exception is thrown if analyze
, preUpgrade
,
upgrade
, postUpgrade
, or rollback
are underway in another thread.
When the method is called, the upgrade
status
must be Upgraded or Post-upgrading. Otherwise an exception is
thrown.
If the postUpgrade
method of an upgrade
action in the schema upgrade throws an exception, it is logged and
rethrown. The upgrade status is set to Post-upgrading.
The method returns when the post-upgrade phase is completed or stopped
. If the post-upgrade phase completes with no errors, the
upgrade status is set to Completed and true
is returned;
otherwise the upgrade status is set to Post-upgrading and false
is returned.
postUpgrade
in interface UpgradeDriverManager
IfsException
- if the operation failspublic boolean rollback(boolean offline) throws IfsException
An exception is thrown if analyze
, preUpgrade
,
upgrade
, postUpgrade
, or rollback
are underway in another thread.
When the method is called, the upgrade
status
must be Initialized, Analyzing, Analyzed, Pre-upgrading,
Pre-upgraded, Upgrading, Upgraded, Post-upgrading, Completed, or
Rolling-back. Otherwise an exception is thrown.
If the upgrade status is Upgrading, Upgraded, Post-upgrading, or Completed,
the rollback must be performed with the repository offline (that is,
with all nodes stopped). If the repository is not offline, as indicated
by the offline
argument, an exception is thrown.
If the rollback
method of an upgrade
action in the schema upgrade throws an exception, it is logged and
rethrown. The upgrade status is set to Rolling-back.
The method returns when the rollback is completed or stopped
.
If the rollback completes with no errors, the upgrade status is set to
Rolled-back, the schema version is updated to the source schema version
, and
true
is returned; otherwise the upgrade status is set to
Rolling-back and false
is returned.
rollback
in interface UpgradeDriverManager
offline
- whether the repository is offline (that is, whether
all nodes are stopped)IfsException
- if the operation failspublic int getCurrentTask() throws IfsException
The returned value is one of:
TASK_NONE
if no task is being performed,TASK_ANALYZE
if executing the
analyze
method,TASK_PREUPGRADE
if executing the
preUpgrade
method,TASK_UPGRADE
if executing the
upgrade
method,TASK_POSTUPGRADE
if executing the
postUpgrade
method, orTASK_ROLLBACK
if executing the
rollback
methodgetCurrentTask
in interface UpgradeDriverManager
IfsException
- if the operation failspublic void stop() throws IfsException
analyze
, preUpgrade
, upgrade
, postUpgrade
,
or rollback
to stop.
If none of these methods are underway, a call to stop
has no effect.
stop
in interface UpgradeDriverManager
IfsException
public void dispose() throws IfsException
After this method is called, all other methods on this interface (apart
from isDisposed
, but including dispose
) will
throw an exception.
dispose
in interface UpgradeDriverManager
IfsException
- if the operation failspublic boolean isDisposed() throws IfsException
dispose
has been called on this
UpgradeDriverManager.isDisposed
in interface UpgradeDriverManager
IfsException
- if the operation failspublic UpgradeStatus[] getUpgradeHistory() throws IfsException
getUpgradeHistory
in interface UpgradeDriverManager
IfsException
- if the operation failspublic UpgradeStatus getMostRecentUpgrade() throws IfsException
If an schema upgrade is underway, this method will return that upgrade.
getMostRecentUpgrade
in interface UpgradeDriverManager
IfsException
- if the operation failspublic String toTaskLabel(int task)
toTaskLabel
in interface UpgradeDriverManager
task
- the task; must be public String toStatusLabel(int status)
toStatusLabel
in interface UpgradeDriverManager
status
- the status value; must be protected Connection acquireLock() throws IfsException
The calling thread must call releaseLock()
to release the lock.
IfsException
- if the operation failsprotected void releaseLock() throws IfsException
IfsException
- if the operation failsprotected PreparedStatement getPreparedStatement(String sql) throws IfsException
If a PreparedStatement was previously created for the SQL, it is returned. Otherwise a new PreparedStatement is created and returned.
The caller should not close the returned PreparedStatement.
sql
- the SQLIfsException
- if the operation failsprotected static void rollbackTransaction(Connection conn)
conn
- the connectionprotected long getUpgradeSequenceNextValue() throws IfsException
IfsException
- if the operation failsCopyright © 2023. All rights reserved.