use of liquibase.changelog.ChangeSet in project minijax by minijax.
the class LiquibaseHelperTest method testNotIgnoreAddColumn.
@Test
public void testNotIgnoreAddColumn() {
final AddColumnChange change = new AddColumnChange();
final ChangeSet changeSet = new ChangeSet(null);
changeSet.addChange(change);
assertFalse(LiquibaseHelper.isIgnoredChangeSet(changeSet));
}
use of liquibase.changelog.ChangeSet in project openmrs-core by openmrs.
the class DatabaseUpdater method getDatabaseChanges.
/**
* Looks at the current liquibase-update-to-latest
* .xml file and then checks the database to see
* if they have been run.
*
* @return list of changesets that both have and haven't been run
*/
@Authorized(PrivilegeConstants.GET_DATABASE_CHANGES)
public static List<OpenMRSChangeSet> getDatabaseChanges() throws Exception {
Database database = null;
try {
Liquibase liquibase = getLiquibase(CHANGE_LOG_FILE, null);
database = liquibase.getDatabase();
DatabaseChangeLog changeLog = new XMLChangeLogSAXParser().parse(CHANGE_LOG_FILE, new ChangeLogParameters(), liquibase.getFileOpener());
List<ChangeSet> changeSets = changeLog.getChangeSets();
List<OpenMRSChangeSet> results = new ArrayList<>();
for (ChangeSet changeSet : changeSets) {
OpenMRSChangeSet omrschangeset = new OpenMRSChangeSet(changeSet, database);
results.add(omrschangeset);
}
return results;
} finally {
try {
if (database != null) {
database.getConnection().close();
}
} catch (Exception e) {
// pass
}
}
}
use of liquibase.changelog.ChangeSet in project openmrs-core by openmrs.
the class DatabaseUpdater method executeChangelog.
/**
* This code was borrowed from the liquibase jar so that we can call the given callback
* function.
*
* @param changeLogFile the file to execute
* @param contexts the liquibase changeset context
* @param userInput answers given by the user
* @param callback the function to call after every changeset
* @param cl {@link ClassLoader} to use to find the changeLogFile (or null to use
* {@link OpenmrsClassLoader})
* @return A list of messages or warnings generated by the executed changesets
* @throws Exception
*/
public static List<String> executeChangelog(String changeLogFile, String contexts, Map<String, Object> userInput, ChangeSetExecutorCallback callback, ClassLoader cl) throws Exception {
final class OpenmrsUpdateVisitor extends UpdateVisitor {
private ChangeSetExecutorCallback callback;
private int numChangeSetsToRun;
public OpenmrsUpdateVisitor(Database database, ChangeSetExecutorCallback callback, int numChangeSetsToRun) {
super(database);
this.callback = callback;
this.numChangeSetsToRun = numChangeSetsToRun;
}
@Override
public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database) throws LiquibaseException {
if (callback != null) {
callback.executing(changeSet, numChangeSetsToRun);
}
super.visit(changeSet, databaseChangeLog, database);
}
}
if (cl == null) {
cl = OpenmrsClassLoader.getInstance();
}
log.debug("Setting up liquibase object to run changelog: " + changeLogFile);
Liquibase liquibase = getLiquibase(changeLogFile, cl);
int numChangeSetsToRun = liquibase.listUnrunChangeSets(contexts).size();
Database database = null;
LockService lockHandler = null;
try {
database = liquibase.getDatabase();
lockHandler = LockService.getInstance(database);
lockHandler.waitForLock();
ResourceAccessor openmrsFO = new ClassLoaderFileOpener(cl);
ResourceAccessor fsFO = new FileSystemResourceAccessor();
DatabaseChangeLog changeLog = new XMLChangeLogSAXParser().parse(changeLogFile, new ChangeLogParameters(), new CompositeResourceAccessor(openmrsFO, fsFO));
changeLog.setChangeLogParameters(liquibase.getChangeLogParameters());
changeLog.validate(database);
ChangeLogIterator logIterator = new ChangeLogIterator(changeLog, new ShouldRunChangeSetFilter(database), new ContextChangeSetFilter(contexts), new DbmsChangeSetFilter(database));
database.checkDatabaseChangeLogTable(true, changeLog, new String[] { contexts });
logIterator.run(new OpenmrsUpdateVisitor(database, callback, numChangeSetsToRun), database);
} catch (LiquibaseException e) {
throw e;
} finally {
try {
lockHandler.releaseLock();
} catch (Exception e) {
log.error("Could not release lock", e);
}
try {
database.getConnection().close();
} catch (Exception e) {
// pass
}
}
return updateWarnings;
}
use of liquibase.changelog.ChangeSet in project openmrs-core by openmrs.
the class DatabaseUpdater method getUnrunDatabaseChanges.
/**
* Looks at the specified liquibase change log files and returns all changesets in the files
* that have not been run on the database yet. If no argument is specified, then it looks at the
* current liquibase-update-to-latest.xml file
*
* @param changeLogFilenames the filenames of all files to search for unrun changesets
* @return list of change sets
*/
@Authorized(PrivilegeConstants.GET_DATABASE_CHANGES)
public static List<OpenMRSChangeSet> getUnrunDatabaseChanges(String... changeLogFilenames) {
log.debug("Getting unrun changesets");
Database database = null;
try {
if (changeLogFilenames == null) {
throw new IllegalArgumentException("changeLogFilenames cannot be null");
}
// if no argument, look ONLY in liquibase-update-to-latest.xml
if (changeLogFilenames.length == 0) {
changeLogFilenames = new String[] { CHANGE_LOG_FILE };
}
List<OpenMRSChangeSet> results = new ArrayList<>();
for (String changelogFile : changeLogFilenames) {
Liquibase liquibase = getLiquibase(changelogFile, null);
database = liquibase.getDatabase();
List<ChangeSet> changeSets = liquibase.listUnrunChangeSets(CONTEXT);
for (ChangeSet changeSet : changeSets) {
OpenMRSChangeSet omrschangeset = new OpenMRSChangeSet(changeSet, database);
results.add(omrschangeset);
}
}
return results;
} catch (Exception e) {
throw new RuntimeException("Error occurred while trying to get the updates needed for the database. " + e.getMessage(), e);
} finally {
try {
database.getConnection().close();
} catch (Exception e) {
// pass
}
}
}
use of liquibase.changelog.ChangeSet in project liquibase by liquibase.
the class HubUpdater method populateOperationChange.
private void populateOperationChange(Contexts contexts, LabelExpression labelExpression, ChangeLogIterator changeLogIterator, ListVisitor listVisitor, OperationChange operationChange) throws LiquibaseException {
if (changeLogIterator != null) {
changeLogIterator.run(listVisitor, new RuntimeEnvironment(database, contexts, labelExpression));
List<ChangeSet> operationChangeSets = listVisitor.getSeenChangeSets();
for (ChangeSet operationChangeSet : operationChangeSets) {
operationChange.getChangeSets().add(operationChangeSet);
}
}
}
Aggregations