public class DatabaseUpdater
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
DatabaseUpdater.ChangeSetExecutorCallback
Interface used for callbacks when updating the database.
|
static class |
DatabaseUpdater.OpenMRSChangeSet
Represents each change in the liquibase-update-to-latest
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DATABASE_UPDATES_LOG_FILE |
Constructor and Description |
---|
DatabaseUpdater() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Boolean |
allowAutoUpdate()
Indicates whether automatic database updates are allowed by this server.
|
static void |
executeChangelog()
Convenience method to run the changesets using Liquibase to bring the database up to a
version compatible with the code
|
static void |
executeChangelog(java.lang.String changelog,
java.util.Map<java.lang.String,java.lang.Object> userInput)
Run changesets on database using Liquibase to get the database up to the most recent version
|
static java.util.List<java.lang.String> |
executeChangelog(java.lang.String changelog,
java.util.Map<java.lang.String,java.lang.Object> userInput,
DatabaseUpdater.ChangeSetExecutorCallback callback)
Executes the given changelog file.
|
static java.util.List<java.lang.String> |
executeChangelog(java.lang.String changeLogFile,
java.lang.String contexts,
java.util.Map<java.lang.String,java.lang.Object> userInput,
DatabaseUpdater.ChangeSetExecutorCallback callback)
|
static java.util.List<java.lang.String> |
executeChangelog(java.lang.String changeLogFile,
java.lang.String contexts,
java.util.Map<java.lang.String,java.lang.Object> userInput,
DatabaseUpdater.ChangeSetExecutorCallback callback,
java.lang.ClassLoader cl)
This code was borrowed from the liquibase jar so that we can call the given callback
function.
|
static java.lang.Integer |
getAuthenticatedUserId() |
static java.sql.Connection |
getConnection()
Gets a database connection for liquibase to do the updates
|
static java.util.List<DatabaseUpdater.OpenMRSChangeSet> |
getDatabaseChanges()
Looks at the current liquibase-update-to-latest.xml file and then checks the database to see
if they have been run.
|
static java.util.List<DatabaseUpdater.OpenMRSChangeSet> |
getUnrunDatabaseChanges() |
static java.util.List<DatabaseUpdater.OpenMRSChangeSet> |
getUnrunDatabaseChanges(java.lang.String... changeLogFilenames)
Looks at the specified liquibase change log files and returns all changesets in the files
that have not been run on the database yet.
|
static boolean |
isLocked()
This method currently checks the liquibasechangeloglock table to see if there is a row
with a lock in it.
|
static void |
releaseDatabaseLock()
This method releases the liquibase db lock after a crashed database update.
|
static void |
reportUpdateWarnings(java.util.List<java.lang.String> warnings)
This method is called by an executing custom changeset to register warning messages.
|
static void |
setAuthenticatedUserId(java.lang.Integer userId) |
static boolean |
updatesRequired()
Ask Liquibase if it needs to do any updates.
|
static boolean |
updatesRequired(java.lang.String... changeLogFilenames)
Ask Liquibase if it needs to do any updates
|
static void |
writeUpdateMessagesToFile(java.lang.String text)
This method writes the given text to the database updates log file located in the application
data directory.
|
public static final java.lang.String DATABASE_UPDATES_LOG_FILE
public static void executeChangelog() throws DatabaseUpdateException, InputRequiredException
InputRequiredException
- if the changelog file requirest some sort of user input. The
error object will list of the user prompts and type of data for each promptDatabaseUpdateException
#update(Map)
,
executeChangelog(String, Map)
public static void executeChangelog(java.lang.String changelog, java.util.Map<java.lang.String,java.lang.Object> userInput) throws DatabaseUpdateException, InputRequiredException
changelog
- the liquibase changelog file to use (or null to use the default file)userInput
- nullable map from question to user answer. Used if a call to update(null)
threw an InputRequiredException
DatabaseUpdateException
InputRequiredException
public static java.util.List<java.lang.String> executeChangelog(java.lang.String changelog, java.util.Map<java.lang.String,java.lang.Object> userInput, DatabaseUpdater.ChangeSetExecutorCallback callback) throws DatabaseUpdateException, InputRequiredException
CHANGE_LOG_FILE
is ran.changelog
- The string filename of a liquibase changelog xml file to runuserInput
- nullable map from question to user answer. Used if a call to
executeChangelog(InputRequiredException
InputRequiredException
- if the changelog file requirest some sort of user input. The
error object will list of the user prompts and type of data for each promptDatabaseUpdateException
@Deprecated public static java.util.List<java.lang.String> executeChangelog(java.lang.String changeLogFile, java.lang.String contexts, java.util.Map<java.lang.String,java.lang.Object> userInput, DatabaseUpdater.ChangeSetExecutorCallback callback) throws java.lang.Exception
java.lang.Exception
public static java.util.List<java.lang.String> executeChangelog(java.lang.String changeLogFile, java.lang.String contexts, java.util.Map<java.lang.String,java.lang.Object> userInput, DatabaseUpdater.ChangeSetExecutorCallback callback, java.lang.ClassLoader cl) throws java.lang.Exception
changeLogFile
- the file to executecontexts
- the liquibase changeset contextuserInput
- answers given by the usercallback
- the function to call after every changesetcl
- ClassLoader
to use to find the changeLogFile (or null to use
OpenmrsClassLoader
)java.lang.Exception
public static boolean updatesRequired() throws java.lang.Exception
CHANGE_LOG_FILE
java.lang.Exception
public static boolean updatesRequired(java.lang.String... changeLogFilenames) throws java.lang.Exception
changeLogFilenames
- the filenames of all files to search for unrun changesetsjava.lang.Exception
public static java.lang.Boolean allowAutoUpdate()
public static java.sql.Connection getConnection() throws java.lang.Exception
java.lang.Exception
@Authorized(value="View Database Changes") public static java.util.List<DatabaseUpdater.OpenMRSChangeSet> getDatabaseChanges() throws java.lang.Exception
java.lang.Exception
@Authorized(value="View Database Changes") public static java.util.List<DatabaseUpdater.OpenMRSChangeSet> getUnrunDatabaseChanges() throws java.lang.Exception
java.lang.Exception
getUnrunDatabaseChanges(String...)
@Authorized(value="View Database Changes") public static java.util.List<DatabaseUpdater.OpenMRSChangeSet> getUnrunDatabaseChanges(java.lang.String... changeLogFilenames) throws java.lang.Exception
changeLogFilenames
- the filenames of all files to search for unrun changesetsjava.lang.Exception
public static java.lang.Integer getAuthenticatedUserId()
public static void setAuthenticatedUserId(java.lang.Integer userId)
authenticatedUserId
- the authenticatedUserId to setpublic static void reportUpdateWarnings(java.util.List<java.lang.String> warnings)
warnings
- list of warnings to append to the end of the current listpublic static void writeUpdateMessagesToFile(java.lang.String text)
the
- text to be written to the filepublic static void releaseDatabaseLock() throws liquibase.exception.LockException
liquibase.exception.LockException
public static boolean isLocked()
Copyright © 2018 OpenMRS Inc.. All Rights Reserved.