Search in sources :

Example 6 with Logger

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;
        }
    });
}
Also used : MockResourceAccessor(liquibase.sdk.resource.MockResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) LockService(liquibase.lockservice.LockService) LockServiceFactory(liquibase.lockservice.LockServiceFactory) ChangeLogParserFactory(liquibase.parser.ChangeLogParserFactory) Logger(liquibase.logging.Logger) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) LogFactory(liquibase.logging.LogFactory) MockResourceAccessor(liquibase.sdk.resource.MockResourceAccessor) ChangeLogIterator(liquibase.changelog.ChangeLogIterator) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) ChangeLogParser(liquibase.parser.ChangeLogParser) MockDatabase(liquibase.sdk.database.MockDatabase) Database(liquibase.database.Database) Before(org.junit.Before)

Example 7 with Logger

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;
}
Also used : ChangeExecListener(liquibase.changelog.visitor.ChangeExecListener) Database(liquibase.database.Database) Logger(liquibase.logging.Logger) Properties(java.util.Properties)

Example 8 with Logger

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);
    }
}
Also used : SkippedChangeSetVisitor(liquibase.changelog.visitor.SkippedChangeSetVisitor) Logger(liquibase.logging.Logger)

Aggregations

Logger (liquibase.logging.Logger)8 IOException (java.io.IOException)2 URL (java.net.URL)2 JarEntry (java.util.jar.JarEntry)2 JarFile (java.util.jar.JarFile)2 Database (liquibase.database.Database)2 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)2 SqlStatement (liquibase.statement.SqlStatement)2 FileNotFoundException (java.io.FileNotFoundException)1 URLClassLoader (java.net.URLClassLoader)1 PrivilegedAction (java.security.PrivilegedAction)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ParseException (java.text.ParseException)1 Properties (java.util.Properties)1 ColumnConfig (liquibase.change.ColumnConfig)1 ChangeLogIterator (liquibase.changelog.ChangeLogIterator)1 ChangeLogParameters (liquibase.changelog.ChangeLogParameters)1 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)1