liquibase.resource.ClassLoaderResourceAccessor Java Examples
The following examples show how to use
liquibase.resource.ClassLoaderResourceAccessor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DBTestUtils.java From trellis with Apache License 2.0 | 6 votes |
static EmbeddedPostgres setupDatabase(final String directory) { try { final EmbeddedPostgres pg = EmbeddedPostgres.builder() .setDataDirectory(directory + separator + "pgdata-" + new RandomStringGenerator .Builder().withinRange('a', 'z').build().generate(10)).start(); // Set up database migrations try (final Connection c = pg.getPostgresDatabase().getConnection()) { final Liquibase liquibase = new Liquibase("org/trellisldp/jdbc/migrations.yml", new ClassLoaderResourceAccessor(), new JdbcConnection(c)); final Contexts ctx = null; liquibase.update(ctx); } return pg; } catch (final IOException | SQLException | LiquibaseException ex) { LOGGER.error("Error setting up tests", ex); } return null; }
Example #2
Source File: TestDataSourceProvider.java From multiapps with Apache License 2.0 | 6 votes |
public static DataSource getDataSource(String liquibaseChangelogLocation) throws Exception { // create a hsql in memory connection Connection connection = createH2InMemory(); // Create the schema for unit testing Database liquibaseDb = DatabaseFactory.getInstance() .findCorrectDatabaseImplementation(new JdbcConnection(connection)); Liquibase lq = new Liquibase(liquibaseChangelogLocation, new ClassLoaderResourceAccessor(), liquibaseDb); try { lq.update(""); } catch (MigrationFailedException e) { // catch the exception because in PopulateConfigurationRegistrySpaceIdColumnChange liquibase change there is rest call if (e.getCause() .getClass() != UnexpectedLiquibaseException.class) { throw e; } } // Initialize the fileService to use our in-memory connection through a pool emulation (so // that close releases rather than close) return new SingleConnectionDataSource(connection, true); }
Example #3
Source File: LiquibaseIT.java From liquibase-spatial with Apache License 2.0 | 6 votes |
/** * Tests Liquibase updating the database. * * @param changeLogFile * the database change log to use in the {@link Liquibase#update(Contexts) update}. * @throws LiquibaseException * if Liquibase fails to initialize or run the update. * @throws SQLException * if unable to get the database connection. */ @Test(dataProvider = "databaseUrlProvider") public void testLiquibaseUpdate(final String changeLogFile) throws LiquibaseException, SQLException { final Connection connection = getConnection(); final JdbcConnection jdbcConnection = new JdbcConnection(connection); try { final ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(); final Liquibase liquibase = createLiquibase(changeLogFile, resourceAccessor, jdbcConnection); final Contexts contexts = null; liquibase.update(contexts); final List<ChangeSet> unrunChangeSets = liquibase.listUnrunChangeSets(contexts); assertTrue(unrunChangeSets.isEmpty(), "All change sets should have run"); } finally { jdbcConnection.rollback(); jdbcConnection.close(); } }
Example #4
Source File: LiquibaseIT.java From liquibase-spatial with Apache License 2.0 | 6 votes |
/** * Tests Liquibase updating and rolling back the database. * * @param changeLogFile * the database change log to use in the {@link Liquibase#update(Contexts) update}. * @throws LiquibaseException * if Liquibase fails to initialize or run the update. * @throws SQLException * if unable to get the database connection. */ @Test(dataProvider = "databaseUrlProvider", enabled = false) public void testLiquibaseUpdateTestingRollback(final String changeLogFile) throws LiquibaseException, SQLException { final Connection connection = getConnection(); final JdbcConnection jdbcConnection = new JdbcConnection(connection); try { final ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(); final Liquibase liquibase = createLiquibase(changeLogFile, resourceAccessor, jdbcConnection); final Contexts contexts = null; final LabelExpression labels = new LabelExpression(); liquibase.updateTestingRollback(contexts, labels); final List<ChangeSet> unrunChangeSets = liquibase.listUnrunChangeSets(contexts, labels); assertTrue(unrunChangeSets.isEmpty(), "All change sets should have run"); } finally { jdbcConnection.rollback(); jdbcConnection.close(); } }
Example #5
Source File: LiquibasePreparer.java From otj-pg-embedded with Apache License 2.0 | 6 votes |
@Override public void prepare(DataSource ds) throws SQLException { Connection connection = null; try { connection = ds.getConnection(); Database database = getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); Liquibase liquibase = new Liquibase(location, new ClassLoaderResourceAccessor(), database); liquibase.update(contexts); } catch (LiquibaseException e) { throw new SQLException(e); } finally { if (connection != null) { connection.rollback(); connection.close(); } } }
Example #6
Source File: DbSchemaDrop.java From flowable-engine with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { DmnEngine dmnEngine = DmnEngines.getDefaultDmnEngine(); DataSource dataSource = dmnEngine.getDmnEngineConfiguration().getDataSource(); DatabaseConnection connection = new JdbcConnection(dataSource.getConnection()); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName()); if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema())) { database.setDefaultSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema()); database.setLiquibaseSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema()); } if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog())) { database.setDefaultCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog()); database.setLiquibaseCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog()); } Liquibase liquibase = new Liquibase("org/flowable/dmn/db/liquibase/flowable-dmn-db-changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); liquibase.getDatabase().close(); } catch (Exception e) { e.printStackTrace(); } }
Example #7
Source File: LiquibaseProcessor.java From quarkus with Apache License 2.0 | 5 votes |
/** * Finds all resource files for the given change log file */ private Set<String> findAllChangeLogs(String file, ChangeLogParserFactory changeLogParserFactory, ClassLoaderResourceAccessor classLoaderResourceAccessor, ChangeLogParameters changeLogParameters) { try { ChangeLogParser parser = changeLogParserFactory.getParser(file, classLoaderResourceAccessor); DatabaseChangeLog changelog = parser.parse(file, changeLogParameters, classLoaderResourceAccessor); if (changelog != null) { Set<String> result = new LinkedHashSet<>(); // get all changeSet files for (ChangeSet changeSet : changelog.getChangeSets()) { result.add(changeSet.getFilePath()); // get all parents of the changeSet DatabaseChangeLog parent = changeSet.getChangeLog(); while (parent != null) { result.add(parent.getFilePath()); parent = parent.getParentChangeLog(); } } result.add(changelog.getFilePath()); return result; } } catch (LiquibaseException ex) { throw new IllegalStateException(ex); } return Collections.emptySet(); }
Example #8
Source File: DbScriptUtil.java From flowable-engine with Apache License 2.0 | 5 votes |
public static void dropSchema() throws Exception { System.out.println("Dropping schema"); DatabaseConnection databaseConnection = createDbConnection(); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(databaseConnection); Liquibase liquibase = new Liquibase("META-INF/liquibase/db-changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); closeDatabase(database, databaseConnection); }
Example #9
Source File: DbSchemaDrop.java From flowable-engine with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { FormEngine formEngine = FormEngines.getDefaultFormEngine(); DataSource dataSource = formEngine.getFormEngineConfiguration().getDataSource(); DatabaseConnection connection = new JdbcConnection(dataSource.getConnection()); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(FormEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(FormEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName()); if (StringUtils.isNotEmpty(formEngine.getFormEngineConfiguration().getDatabaseSchema())) { database.setDefaultSchemaName(formEngine.getFormEngineConfiguration().getDatabaseSchema()); database.setLiquibaseSchemaName(formEngine.getFormEngineConfiguration().getDatabaseSchema()); } if (StringUtils.isNotEmpty(formEngine.getFormEngineConfiguration().getDatabaseCatalog())) { database.setDefaultCatalogName(formEngine.getFormEngineConfiguration().getDatabaseCatalog()); database.setLiquibaseCatalogName(formEngine.getFormEngineConfiguration().getDatabaseCatalog()); } Liquibase liquibase = new Liquibase("org/flowable/form/db/liquibase/flowable-form-db-changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); liquibase.getDatabase().close(); } catch (Exception e) { e.printStackTrace(); } }
Example #10
Source File: DbSchemaDrop.java From flowable-engine with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { ContentEngine contentEngine = ContentEngines.getDefaultContentEngine(); DataSource dataSource = contentEngine.getContentEngineConfiguration().getDataSource(); DatabaseConnection connection = new JdbcConnection(dataSource.getConnection()); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(ContentEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(ContentEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName()); if (StringUtils.isNotEmpty(contentEngine.getContentEngineConfiguration().getDatabaseSchema())) { database.setDefaultSchemaName(contentEngine.getContentEngineConfiguration().getDatabaseSchema()); database.setLiquibaseSchemaName(contentEngine.getContentEngineConfiguration().getDatabaseSchema()); } if (StringUtils.isNotEmpty(contentEngine.getContentEngineConfiguration().getDatabaseCatalog())) { database.setDefaultCatalogName(contentEngine.getContentEngineConfiguration().getDatabaseCatalog()); database.setLiquibaseCatalogName(contentEngine.getContentEngineConfiguration().getDatabaseCatalog()); } Liquibase liquibase = new Liquibase("org/flowable/content/db/liquibase/flowable-content-db-changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); liquibase.getDatabase().close(); } catch (Exception e) { e.printStackTrace(); } }
Example #11
Source File: DbSchemaDrop.java From flowable-engine with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { EventRegistryEngine eventRegistryEngine = EventRegistryEngines.getDefaultEventRegistryEngine(); EventRegistryEngineConfiguration eventRegistryEngineConfiguration = eventRegistryEngine.getEventRegistryEngineConfiguration(); DataSource dataSource = eventRegistryEngineConfiguration.getDataSource(); DatabaseConnection connection = new JdbcConnection(dataSource.getConnection()); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(EventRegistryEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(EventRegistryEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName()); if (StringUtils.isNotEmpty(eventRegistryEngineConfiguration.getDatabaseSchema())) { database.setDefaultSchemaName(eventRegistryEngineConfiguration.getDatabaseSchema()); database.setLiquibaseSchemaName(eventRegistryEngineConfiguration.getDatabaseSchema()); } if (StringUtils.isNotEmpty(eventRegistryEngineConfiguration.getDatabaseCatalog())) { database.setDefaultCatalogName(eventRegistryEngineConfiguration.getDatabaseCatalog()); database.setLiquibaseCatalogName(eventRegistryEngineConfiguration.getDatabaseCatalog()); } Liquibase liquibase = new Liquibase("org/flowable/eventregistry/db/liquibase/flowable-eventregistry-db-changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); liquibase.getDatabase().close(); } catch (Exception e) { e.printStackTrace(); } }
Example #12
Source File: LiquibaseService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public Liquibase newConnectedLiquibase() throws SQLException, LiquibaseException { config.refresh(); DatabaseConnection dbConnection = new JdbcConnection( dataSource.get().getConnection() ); return new Liquibase( config.get().changeLog().get(), new ClassLoaderResourceAccessor(), dbConnection ); }
Example #13
Source File: LiquibaseImpl.java From iaf with Apache License 2.0 | 5 votes |
public LiquibaseImpl(IbisContext ibisContext, ClassLoader classLoader, JdbcConnection connection, String configurationName, String changeLogFile) throws LiquibaseException { this.ibisContext = ibisContext; this.configurationName = configurationName; ClassLoaderResourceAccessor resourceOpener = new ClassLoaderResourceAccessor(classLoader); this.liquibase = new Liquibase(changeLogFile, resourceOpener, connection); this.liquibase.validate(); }
Example #14
Source File: LiquibaseProducer.java From tutorials with MIT License | 5 votes |
@Produces public Liquibase produceLiquibase() throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ResourceAccessor classLoaderResourceAccessor = new ClassLoaderResourceAccessor(classLoader); Liquibase liquibase = new Liquibase(liquibaseConfig.changeLog, classLoaderResourceAccessor, new JdbcConnection(dataSource.getConnection())); return liquibase; }
Example #15
Source File: DefaultLiquibaseConnectionProvider.java From keycloak with Apache License 2.0 | 5 votes |
@Override public Liquibase getLiquibase(Connection connection, String defaultSchema) throws LiquibaseException { Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); if (defaultSchema != null) { database.setDefaultSchemaName(defaultSchema); } String changelog = LiquibaseJpaUpdaterProvider.CHANGELOG; ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(getClass().getClassLoader()); logger.debugf("Using changelog file %s and changelogTableName %s", changelog, database.getDatabaseChangeLogTableName()); return new Liquibase(changelog, resourceAccessor, database); }
Example #16
Source File: DefaultLiquibaseConnectionProvider.java From keycloak with Apache License 2.0 | 5 votes |
@Override public Liquibase getLiquibaseForCustomUpdate(Connection connection, String defaultSchema, String changelogLocation, ClassLoader classloader, String changelogTableName) throws LiquibaseException { Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); if (defaultSchema != null) { database.setDefaultSchemaName(defaultSchema); } ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(classloader); database.setDatabaseChangeLogTableName(changelogTableName); logger.debugf("Using changelog file %s and changelogTableName %s", changelogLocation, database.getDatabaseChangeLogTableName()); return new Liquibase(changelogLocation, resourceAccessor, database); }
Example #17
Source File: QuarkusLiquibaseConnectionProvider.java From keycloak with Apache License 2.0 | 5 votes |
@Override public Liquibase getLiquibaseForCustomUpdate(Connection connection, String defaultSchema, String changelogLocation, ClassLoader classloader, String changelogTableName) throws LiquibaseException { Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); if (defaultSchema != null) { database.setDefaultSchemaName(defaultSchema); } ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(classloader); database.setDatabaseChangeLogTableName(changelogTableName); logger.debugf("Using changelog file %s and changelogTableName %s", changelogLocation, database.getDatabaseChangeLogTableName()); return new Liquibase(changelogLocation, resourceAccessor, database); }
Example #18
Source File: Launcher.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
public boolean isMigrationNeeded() throws SQLException, LiquibaseException { App app = new App(dir); DataSource dataSource = new DataSourceFactory(app.options("database", DatabaseOptions.class)).setDir(dir).build(); try (Connection connection = dataSource.getConnection()) { Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); Liquibase liquibase = new Liquibase("conf/db/change-logs.yml", new ClassLoaderResourceAccessor(), database); return !liquibase.tagExists("0.9.0"); } }
Example #19
Source File: LiquibaseProcessor.java From quarkus with Apache License 2.0 | 5 votes |
/** * Collect the configured changeLog file for the default and all named datasources. * <p> * A {@link LinkedHashSet} is used to avoid duplications. */ private List<String> getChangeLogs(Collection<String> dataSourceNames, LiquibaseBuildTimeConfig liquibaseBuildConfig) { if (dataSourceNames.isEmpty()) { return Collections.emptyList(); } ChangeLogParameters changeLogParameters = new ChangeLogParameters(); ClassLoaderResourceAccessor classLoaderResourceAccessor = new ClassLoaderResourceAccessor( Thread.currentThread().getContextClassLoader()); ChangeLogParserFactory changeLogParserFactory = ChangeLogParserFactory.getInstance(); Set<String> resources = new LinkedHashSet<>(); // default datasource if (DataSourceUtil.hasDefault(dataSourceNames)) { resources.addAll(findAllChangeLogs(liquibaseBuildConfig.defaultDataSource.changeLog, changeLogParserFactory, classLoaderResourceAccessor, changeLogParameters)); } // named datasources Collection<String> namedDataSourceChangeLogs = dataSourceNames.stream() .filter(n -> !DataSourceUtil.isDefault(n)) .map(liquibaseBuildConfig::getConfigForDataSourceName) .map(c -> c.changeLog) .collect(Collectors.toCollection(LinkedHashSet::new)); for (String namedDataSourceChangeLog : namedDataSourceChangeLogs) { resources.addAll( findAllChangeLogs(namedDataSourceChangeLog, changeLogParserFactory, classLoaderResourceAccessor, changeLogParameters)); } LOGGER.debugf("Liquibase changeLogs: %s", resources); return new ArrayList<>(resources); }
Example #20
Source File: LiquibaseFactory.java From quarkus with Apache License 2.0 | 5 votes |
/** * Creates the liquibase instance. * * @return the liquibase. */ public Liquibase createLiquibase() { try { ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor(Thread.currentThread().getContextClassLoader()); Database database = DatabaseFactory.getInstance() .findCorrectDatabaseImplementation(new JdbcConnection(dataSource.getConnection())); ; if (database != null) { database.setDatabaseChangeLogLockTableName(config.databaseChangeLogLockTableName); database.setDatabaseChangeLogTableName(config.databaseChangeLogTableName); config.liquibaseCatalogName.ifPresent(database::setLiquibaseCatalogName); config.liquibaseSchemaName.ifPresent(database::setLiquibaseSchemaName); config.liquibaseTablespaceName.ifPresent(database::setLiquibaseTablespaceName); if (config.defaultCatalogName.isPresent()) { database.setDefaultCatalogName(config.defaultCatalogName.get()); } if (config.defaultSchemaName.isPresent()) { database.setDefaultSchemaName(config.defaultSchemaName.get()); } } return new Liquibase(config.changeLog, resourceAccessor, database); } catch (Exception ex) { throw new IllegalStateException(ex); } }
Example #21
Source File: DbSchemaDrop.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { FormEngine formEngine = FormEngines.getDefaultFormEngine(); DataSource dataSource = formEngine.getFormEngineConfiguration().getDataSource(); DatabaseConnection connection = new JdbcConnection(dataSource.getConnection()); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(FormEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(FormEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogLockTableName()); if (StringUtils.isNotEmpty(formEngine.getFormEngineConfiguration().getDatabaseSchema())) { database.setDefaultSchemaName(formEngine.getFormEngineConfiguration().getDatabaseSchema()); database.setLiquibaseSchemaName(formEngine.getFormEngineConfiguration().getDatabaseSchema()); } if (StringUtils.isNotEmpty(formEngine.getFormEngineConfiguration().getDatabaseCatalog())) { database.setDefaultCatalogName(formEngine.getFormEngineConfiguration().getDatabaseCatalog()); database.setLiquibaseCatalogName(formEngine.getFormEngineConfiguration().getDatabaseCatalog()); } Liquibase liquibase = new Liquibase("org/activiti/form/db/liquibase/activiti-form-db-changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); } catch (Exception e) { e.printStackTrace(); } }
Example #22
Source File: FormEngineConfiguration.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void initDbSchema() { try { DatabaseConnection connection = new JdbcConnection(dataSource.getConnection()); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogLockTableName()); if (StringUtils.isNotEmpty(databaseSchema)) { database.setDefaultSchemaName(databaseSchema); database.setLiquibaseSchemaName(databaseSchema); } if (StringUtils.isNotEmpty(databaseCatalog)) { database.setDefaultCatalogName(databaseCatalog); database.setLiquibaseCatalogName(databaseCatalog); } Liquibase liquibase = new Liquibase("org/activiti/form/db/liquibase/activiti-form-db-changelog.xml", new ClassLoaderResourceAccessor(), database); if (DB_SCHEMA_UPDATE_DROP_CREATE.equals(databaseSchemaUpdate)) { logger.debug("Dropping and creating schema FORM"); liquibase.dropAll(); liquibase.update("form"); } else if (DB_SCHEMA_UPDATE_TRUE.equals(databaseSchemaUpdate)) { logger.debug("Updating schema FORM"); liquibase.update("form"); } else if (DB_SCHEMA_UPDATE_FALSE.equals(databaseSchemaUpdate)) { logger.debug("Validating schema FORM"); liquibase.validate(); } } catch (Exception e) { throw new ActivitiFormException("Error initialising form data schema", e); } }
Example #23
Source File: DbScriptUtil.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public static void dropSchema() throws Exception { System.out.println("Dropping schema"); DatabaseConnection databaseConnection = createDbConnection(); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(databaseConnection); Liquibase liquibase = new Liquibase("META-INF/liquibase/db-changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); closeDatabase(database, databaseConnection); }
Example #24
Source File: DbScriptUtil.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public static void dropSchema() throws Exception { System.out.println("Dropping schema"); DatabaseConnection databaseConnection = createDbConnection(); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(databaseConnection); Liquibase liquibase = new Liquibase("META-INF/liquibase/db-changelog-onpremise.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); closeDatabase(database, databaseConnection); }
Example #25
Source File: DmnEngineConfiguration.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void initDbSchema() { try { DatabaseConnection connection = new JdbcConnection(dataSource.getConnection()); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName()); if (StringUtils.isNotEmpty(databaseSchema)) { database.setDefaultSchemaName(databaseSchema); database.setLiquibaseSchemaName(databaseSchema); } if (StringUtils.isNotEmpty(databaseCatalog)) { database.setDefaultCatalogName(databaseCatalog); database.setLiquibaseCatalogName(databaseCatalog); } Liquibase liquibase = new Liquibase("org/activiti/dmn/db/liquibase/activiti-dmn-db-changelog.xml", new ClassLoaderResourceAccessor(), database); if (DB_SCHEMA_UPDATE_DROP_CREATE.equals(databaseSchemaUpdate)) { logger.debug("Dropping and creating schema DMN"); liquibase.dropAll(); liquibase.update("dmn"); } else if (DB_SCHEMA_UPDATE_TRUE.equals(databaseSchemaUpdate)) { logger.debug("Updating schema DMN"); liquibase.update("dmn"); } else if (DB_SCHEMA_UPDATE_FALSE.equals(databaseSchemaUpdate)) { logger.debug("Validating schema DMN"); liquibase.validate(); } } catch (Exception e) { throw new ActivitiDmnException("Error initialising dmn data model"); } }
Example #26
Source File: DbSchemaDrop.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { DmnEngine dmnEngine = DmnEngines.getDefaultDmnEngine(); DataSource dataSource = dmnEngine.getDmnEngineConfiguration().getDataSource(); DatabaseConnection connection = new JdbcConnection(dataSource.getConnection()); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogLockTableName()); if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema())) { database.setDefaultSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema()); database.setLiquibaseSchemaName(dmnEngine.getDmnEngineConfiguration().getDatabaseSchema()); } if (StringUtils.isNotEmpty(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog())) { database.setDefaultCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog()); database.setLiquibaseCatalogName(dmnEngine.getDmnEngineConfiguration().getDatabaseCatalog()); } Liquibase liquibase = new Liquibase("org/activiti/dmn/db/liquibase/activiti-dmn-db-changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); } catch (Exception e) { e.printStackTrace(); } }
Example #27
Source File: AbstractLiquibaseTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Bootstrapping public static void prepareDataBase(final DataSource ds) throws Exception { final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(ds.getConnection())); final Liquibase liquibase = new Liquibase("changelog/changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); liquibase.update((String) null); }
Example #28
Source File: Launcher.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
public void migrate() throws SQLException, LiquibaseException { logger.info("migrating database"); App app = new App(dir); DataSource dataSource = new DataSourceFactory(app.options("database", DatabaseOptions.class)).setDir(dir).build(); try (Connection connection = dataSource.getConnection()) { Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); Liquibase liquibase = new Liquibase("conf/db/change-logs.yml", new ClassLoaderResourceAccessor(), database); liquibase.update(""); liquibase.tag("0.9.0"); } }
Example #29
Source File: Main.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
public static void main(String[] args) throws LiquibaseException, SQLException, IOException, ParserConfigurationException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl("jdbc:mysql://localhost:3306/main?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setUsername("root"); java.sql.Connection connection = dataSource.getConnection(); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); Liquibase liquibase = new Liquibase("db-changes.yml", new ClassLoaderResourceAccessor(), database); CatalogAndSchema catalogAndSchema = new CatalogAndSchema(null, "main"); DiffToChangeLog changeLog = new DiffToChangeLog(new DiffOutputControl(false, false, true, null)); liquibase.generateChangeLog(catalogAndSchema, changeLog, new PrintStream(new FileOutputStream("./change-logs.yml")), new YamlChangeLogSerializer(), snapTypes()); }
Example #30
Source File: DefaultTenantProvisioningService.java From cloud-s4-sdk-examples with Apache License 2.0 | 5 votes |
@Override public void subscribeTenant(final String tenantId) { String defaultSchemaName; try { Validate.isTrue(isValidTenantId(tenantId), String.format("Invalid tenant id: \"%s\"", tenantId)); final String schemaName = TenantUtil.createSchemaName(tenantId); final Connection connection = dataSource.getConnection(); final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); try (Statement statement = connection.createStatement()) { statement.execute(String.format("CREATE SCHEMA IF NOT EXISTS \"%s\"", schemaName)); connection.commit(); defaultSchemaName = database.getDefaultSchemaName(); database.setDefaultSchemaName(schemaName); final String filePath = LIQUIBASE_PATH; final Liquibase liquibase = new liquibase.Liquibase(filePath, new ClassLoaderResourceAccessor(), database); liquibase.update(new Contexts(), new LabelExpression()); database.setDefaultSchemaName(defaultSchemaName); } } catch (SQLException | LiquibaseException | IllegalArgumentException e) { final BadRequestException badRequestException = new BadRequestException(); logger.error("Tenant subscription failed for {}.", tenantId, e); throw badRequestException; } }