boolean updatesRequired; try { updatesRequired = DatabaseUpdater.updatesRequired(); if (DatabaseUpdater.allowAutoUpdate()) { DatabaseUpdater.executeChangelog(); } else { throw new DatabaseUpdateException(
/** * Ask Liquibase if it needs to do any updates. Only looks at the {@link #CHANGE_LOG_FILE} * * @return true/false whether database updates are required * @throws LockException * @should always have a valid update to latest file */ public static boolean updatesRequired() throws LockException { log.debug("checking for updates"); List<OpenMRSChangeSet> changesets = getUnrunDatabaseChanges(); // if the db is locked, it means there was a crash // or someone is executing db updates right now. either way // returning true here stops the openmrs startup and shows // the user the maintenance wizard for updates if (isLocked() && changesets.isEmpty()) { // if there is a db lock but there are no db changes we undo the // lock DatabaseUpdater.releaseDatabaseLock(); log.debug("db lock found and released automatically"); return false; } return !changesets.isEmpty(); }
/** * This method knows about all the filters that openmrs uses for setup. Currently those are the * {@link InitializationFilter} and the {@link UpdateFilter}. If either of these have to do * something, openmrs won't start in this Listener. * * @return true if one of the filters needs to take some action */ private boolean setupNeeded() throws Exception { if (!runtimePropertiesFound) { return true; } return DatabaseUpdater.updatesRequired() && !DatabaseUpdater.allowAutoUpdate(); }
/** * Convenience method that reads from liquibase again to get the most recent list of changesets * that still need to be run. */ public void updateChanges() { Logger log = LoggerFactory.getLogger(getClass()); try { changes = DatabaseUpdater.getUnrunDatabaseChanges(); // not sure why this is necessary... if (changes == null && DatabaseUpdater.isLocked()) { changes = DatabaseUpdater.getUnrunDatabaseChanges(); } } catch (Exception e) { log.error("Unable to get the database changes", e); } }
@Test public void createUpdateFilterModel_shouldNotRequireAnUpdateIfDatabaseUpdaterIsLockedAndCallingDatabaseUpdaterTwiceAlwaysReturnsNull() throws Exception { when(DatabaseUpdater.getUnrunDatabaseChanges()).thenReturn(null); when(DatabaseUpdater.isLocked()).thenReturn(true); when(DatabaseUpdater.updatesRequired()).thenReturn(false); model = new UpdateFilterModel(); assertFalse("should not require an update", model.updateRequired); assertNull("should not have changes", model.changes); PowerMockito.verifyStatic(times(2)); DatabaseUpdater.getUnrunDatabaseChanges(); PowerMockito.verifyStatic(); DatabaseUpdater.updatesRequired(); }
/** * Default constructor that sets up some of the properties */ public UpdateFilterModel() { updateChanges(); try { if (changes != null && !changes.isEmpty()) { updateRequired = true; } else { updateRequired = DatabaseUpdater.updatesRequired(); } } catch (Exception e) { // do nothing } }
if (!isLockReleased() && DatabaseUpdater.isLocked()) { DatabaseUpdater.releaseDatabaseLock(); setLockReleased(true);
/** * Convenience method to run the changesets using Liquibase to bring the database up to a * version compatible with the code * * @throws InputRequiredException if the changelog file requires some sort of user input. The * error object will list of the user prompts and type of data for each prompt * @see #executeChangelog(String, Map) */ public static void executeChangelog() throws DatabaseUpdateException, InputRequiredException { executeChangelog(null, null); }
try { if (connection == null) { connection = DatabaseUpdater.getConnection(); needToCloseConection = true;
Liquibase liquibase = getLiquibase(null, null); database = liquibase.getDatabase(); if (database.hasDatabaseChangeLogLockTable() && isLocked()) { LockService.getInstance(database).forceReleaseLock();
/** * Ask Liquibase if it needs to do any updates * * @param changeLogFilenames the filenames of all files to search for unrun changesets * @return true/false whether database updates are required * @should always have a valid update to latest file */ public static boolean updatesRequired(String... changeLogFilenames) throws Exception { log.debug("checking for updates"); List<OpenMRSChangeSet> changesets = getUnrunDatabaseChanges(changeLogFilenames); return !changesets.isEmpty(); }
List<List<Object>> duplicateResult; boolean duplicateName; Connection con = DatabaseUpdater.getConnection(); do { String sqlValidatorString = "select * from encounter_role where name = '" + newName + "'"; pStmt.setInt(2, DatabaseUpdater.getAuthenticatedUserId());
Connection connection = null; try { connection = DatabaseUpdater.getConnection(); if (results.next()) { Integer userId = results.getInt(1); DatabaseUpdater.setAuthenticatedUserId(userId); String storedPassword = results.getString(2); String salt = results.getString(3); if (results.next()) { Integer userId = results.getInt(1); DatabaseUpdater.setAuthenticatedUserId(userId); String storedPassword = results.getString(2); String salt = results.getString(3);
/** * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig) */ @Override public void init(ServletConfig config) throws ServletException { super.init(config); // hacky way to know if one of the startup filters needs to be run if (UpdateFilter.updatesRequired() && !DatabaseUpdater.allowAutoUpdate()) { log.info("DB updates are required, the update wizard must be run"); } if (InitializationFilter.initializationRequired()) { log.info("Runtime properties were not found or the database is empty, so initialization is required"); } }
@Test public void createUpdateFilterModel_shouldNotRequireAnUpdateIfChangesAreNullAndDatabaseUpdaterDoesNotRequireAnUpdate() throws Exception { when(DatabaseUpdater.getUnrunDatabaseChanges()).thenReturn(null); when(DatabaseUpdater.isLocked()).thenReturn(false); when(DatabaseUpdater.updatesRequired()).thenReturn(false); model = new UpdateFilterModel(); assertFalse("should not require an update", model.updateRequired); assertNull("should not have changes", model.changes); PowerMockito.verifyStatic(); DatabaseUpdater.getUnrunDatabaseChanges(); PowerMockito.verifyStatic(); DatabaseUpdater.updatesRequired(); }
/** * @throws LockException * @see DatabaseUpdater#updatesRequired() */ @Test public void updatesRequired_shouldAlwaysHaveAValidUpdateToLatestFile() throws LockException { // expects /metadata/model to be on the classpath so that // the liquibase-update-to-latest.xml can be found. try { DatabaseUpdater.updatesRequired(); } catch (RuntimeException rex) { log.error("Runtime Exception in test for Validation Errors"); } // does not run DatabaseUpdater.update() because hsqldb doesn't like single quotes in strings } }
/** * Updates the openmrs database to the latest. This is only needed if using the API alone. <br> * <br> * The typical use-case would be: Try to {@link #startup(String, String, String, Properties)}, * if that fails, call this method to get the database up to speed. * * @param userInput (can be null) responses from the user about needed input * @throws DatabaseUpdateException if an error occurred while updating * @throws InputRequiredException if user input is required * @since 1.5 */ public static void updateDatabase(Map<String, Object> userInput) throws DatabaseUpdateException, InputRequiredException { DatabaseUpdater.executeChangelog(null, userInput); }
connection = DatabaseUpdater.getConnection(); List<List<Object>> results = DatabaseUtil.executeSQL(connection, "select property_value from global_property where property = '" + globalPropertyName + "'", true);
/** * @see DatabaseUpdater#getUnrunDatabaseChanges(String...) */ @Authorized(PrivilegeConstants.GET_DATABASE_CHANGES) public static List<OpenMRSChangeSet> getUnrunDatabaseChanges() { return getUnrunDatabaseChanges(CHANGE_LOG_FILE); }
List<List<Object>> duplicateResult; boolean duplicateName; Connection con = DatabaseUpdater.getConnection(); do { String sqlValidatorString = "select * from location_attribute_type where name = '" + newName + "'"; pStmt.setInt(2, DatabaseUpdater.getAuthenticatedUserId());