use of liquibase.logging.Logger in project liquibase by liquibase.
the class LiquibaseTest method before.
// private TestLiquibase testLiquibase;
// private DatabaseConnection connectionForConstructor;
@Before
public void before() throws Exception {
// if (connectionForConstructor != null) {
// reset(connectionForConstructor);
// }
// connectionForConstructor = createMock(DatabaseConnection.class);
// connectionForConstructor.setAutoCommit(false);
// expectLastCall().atLeastOnce();
//
// DatabaseMetaData metaData = createMock(DatabaseMetaData.class);
// expect(metaData.getDatabaseProductName()).andReturn("Oracle");
// replay(metaData);
//
//// expect(connectionForConstructor.getMetaData()).andReturn(metaData);
// replay(connectionForConstructor);
//
// testLiquibase = new TestLiquibase();
mockResourceAccessor = new MockResourceAccessor();
mockDatabase = mock(Database.class);
mockLockService = mock(LockService.class);
mockLockServiceFactory = mock(LockServiceFactory.class);
mockChangeLogParserFactory = mock(ChangeLogParserFactory.class);
mockChangeLogParser = mock(ChangeLogParser.class);
mockChangeLog = mock(DatabaseChangeLog.class);
mockChangeLogIterator = mock(ChangeLogIterator.class);
mockLogger = mock(Logger.class);
LockServiceFactory.setInstance(mockLockServiceFactory);
when(mockLockServiceFactory.getLockService(any(Database.class))).thenReturn(mockLockService);
ChangeLogParserFactory.setInstance(mockChangeLogParserFactory);
when(mockChangeLogParserFactory.getParser(anyString(), Mockito.isA(ResourceAccessor.class))).thenReturn(mockChangeLogParser);
when(mockChangeLogParser.parse(anyString(), any(ChangeLogParameters.class), Mockito.isA(ResourceAccessor.class))).thenReturn(mockChangeLog);
LogFactory.setInstance(new LogFactory() {
@Override
public Logger getLog(String name) {
return mockLogger;
}
});
}
use of liquibase.logging.Logger in project liquibase by liquibase.
the class ChangeExecListenerUtils method getChangeExecListener.
public static ChangeExecListener getChangeExecListener(Database database, ResourceAccessor resourceAccessor, String changeExecListenerClass, String changeExecListenerPropertiesFile) throws Exception {
ChangeExecListener changeExecListener = null;
if (changeExecListenerClass != null) {
Logger logger = LogFactory.getInstance().getLog();
logger.debug("Setting ChangeExecListener: " + changeExecListenerClass);
ClassLoader classLoader = resourceAccessor.toClassLoader();
Class<?> clazz = Class.forName(changeExecListenerClass, true, classLoader);
Properties properties = loadProperties(changeExecListenerPropertiesFile);
Constructor<?> cons = getConstructor(clazz, Database.class, Properties.class);
if (cons != null) {
logger.debug("Create " + clazz.getSimpleName() + "(Database, Properties)");
changeExecListener = (ChangeExecListener) cons.newInstance(database, properties);
} else {
cons = getConstructor(clazz, Properties.class, Database.class);
if (cons != null) {
logger.debug("Create " + clazz.getSimpleName() + "(Properties, Database)");
changeExecListener = (ChangeExecListener) cons.newInstance(properties, database);
} else {
cons = getConstructor(clazz, Database.class);
if (cons != null) {
logger.debug("Create " + clazz.getSimpleName() + "(Database)");
changeExecListener = (ChangeExecListener) cons.newInstance(database);
} else {
cons = getConstructor(clazz, Properties.class);
if (cons != null) {
logger.debug("Create " + clazz.getSimpleName() + "(Properties)");
changeExecListener = (ChangeExecListener) cons.newInstance(properties);
} else {
logger.debug("Create " + clazz.getSimpleName() + "()");
changeExecListener = (ChangeExecListener) clazz.newInstance();
}
}
}
}
}
return changeExecListener;
}
use of liquibase.logging.Logger in project liquibase by liquibase.
the class ChangeLogIterator method run.
public void run(ChangeSetVisitor visitor, RuntimeEnvironment env) throws LiquibaseException {
Logger log = LogFactory.getLogger();
databaseChangeLog.setRuntimeEnvironment(env);
log.setChangeLog(databaseChangeLog);
try {
List<ChangeSet> changeSetList = new ArrayList<ChangeSet>(databaseChangeLog.getChangeSets());
if (visitor.getDirection().equals(ChangeSetVisitor.Direction.REVERSE)) {
Collections.reverse(changeSetList);
}
for (ChangeSet changeSet : changeSetList) {
boolean shouldVisit = true;
Set<ChangeSetFilterResult> reasonsAccepted = new HashSet<ChangeSetFilterResult>();
Set<ChangeSetFilterResult> reasonsDenied = new HashSet<ChangeSetFilterResult>();
if (changeSetFilters != null) {
for (ChangeSetFilter filter : changeSetFilters) {
ChangeSetFilterResult acceptsResult = filter.accepts(changeSet);
if (acceptsResult.isAccepted()) {
reasonsAccepted.add(acceptsResult);
} else {
shouldVisit = false;
reasonsDenied.add(acceptsResult);
break;
}
}
}
log.setChangeSet(changeSet);
if (shouldVisit && !alreadySaw(changeSet)) {
visitor.visit(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsAccepted);
markSeen(changeSet);
} else {
if (visitor instanceof SkippedChangeSetVisitor) {
((SkippedChangeSetVisitor) visitor).skipped(changeSet, databaseChangeLog, env.getTargetDatabase(), reasonsDenied);
}
}
log.setChangeSet(null);
}
} finally {
log.setChangeLog(null);
databaseChangeLog.setRuntimeEnvironment(null);
}
}
Aggregations