public void checkSchema(String schema) throws LiquibaseException { Connection connection = resolveConnection(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(classLoader); Database database = DatabaseFactory.getInstance() .findCorrectDatabaseImplementation(new JdbcConnection(connection)); Liquibase liquibase = new Liquibase(schema, resourceAccessor, database); liquibase.forceReleaseLocks(); LOG.info("Comprobando actualizaciones de esquema de BBDD"); liquibase.update(""); LOG.info("Comprobacion de esquema de BBDD finalizada"); try { connection.close(); } catch (SQLException ignore) { } }
public void contextInitialized(ServletContextEvent arg0) { try { ConfigDBMapper.getInstance().setDefaultConnectionName("fatec"); Connection conn = ConfigDBMapper.getInstance().getDefaultConnection(); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(conn)); Liquibase liquibase = new Liquibase( "br/com/fatec/aulas/liquibase/changelog-master.xml", new ClassLoaderResourceAccessor(), database); liquibase.forceReleaseLocks(); liquibase.update("fatec"); conn.prepareStatement("COMMIT;").execute(); } catch (Exception e) { // TODO: handle exception } }