liquibase.exception.LiquibaseException Java Examples
The following examples show how to use
liquibase.exception.LiquibaseException.
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: LiquibaseService.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public void applyChangelog( Map<String, Object> parameters ) throws SQLException, LiquibaseException { Liquibase liquibase = null; try { liquibase = newConnectedLiquibase(); for( Map.Entry<String, Object> entry : parameters.entrySet() ) { liquibase.getChangeLogParameters().set( entry.getKey(), entry.getValue() ); } liquibase.update( config.get().contexts().get() ); } finally { if( liquibase != null ) { liquibase.getDatabase().close(); } } }
Example #2
Source File: SqlTest.java From restful-booker-platform with GNU General Public License v3.0 | 6 votes |
@Before public void resetDB() throws SQLException, LiquibaseException { // We call resetDB to return it back to it's vanilla state roomDB.resetDB(); // We then create a Room object to send to the roomDB Room room = new Room(101, "Twin", false, "https://www.mwtestconsultancy.co.uk/img/room1.jpg", "Aenean porttitor mauris sit amet lacinia molestie", new String[]{"Wifi", "TV", "Safe"}, 100); // With the room created we can send it to the RoomDB to be created Room createdRoom = roomDB.create(room); // Finally we need the current room ID to use in our tests // so we save it currentRoomId currentRoomId = createdRoom.getRoomid(); }
Example #3
Source File: SqlTest.java From restful-booker-platform with GNU General Public License v3.0 | 6 votes |
@Before public void resetDb() throws SQLException, LiquibaseException { // We call resetDB to return it back to it's vanilla state bookingDB.resetDB(); // We then create a new Booking using the data builder pattern Booking booking = new Booking.BookingBuilder() .setRoomid(1) .setFirstname("James") .setLastname("Dean") .setDepositpaid(true) .setCheckin(LocalDate.of(2018, Month.FEBRUARY, 26)) .setCheckout(LocalDate.of(2018, Month.FEBRUARY, 26)) .build(); // With the booking created we can send it to the BookingDb to be created CreatedBooking createdBooking = bookingDB.create(booking); // Finally we need the current booking ID to use in our tests // so we save it currentBookingId currentBookingId = createdBooking.getBookingid(); }
Example #4
Source File: AsyncSpringLiquibase.java From OpenIoE with Apache License 2.0 | 6 votes |
@Override public void afterPropertiesSet() throws LiquibaseException { if (!env.acceptsProfiles(Constants.SPRING_PROFILE_NO_LIQUIBASE)) { if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT, Constants.SPRING_PROFILE_HEROKU)) { taskExecutor.execute(() -> { try { log.warn("Starting Liquibase asynchronously, your database might not be ready at startup!"); initDb(); } catch (LiquibaseException e) { log.error("Liquibase could not start correctly, your database is NOT ready: {}", e.getMessage(), e); } }); } else { log.debug("Starting Liquibase synchronously"); initDb(); } } else { log.debug("Liquibase is disabled"); } }
Example #5
Source File: AsyncSpringLiquibase.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 6 votes |
@Override public void afterPropertiesSet() throws LiquibaseException { if (!env.acceptsProfiles(Constants.SPRING_PROFILE_NO_LIQUIBASE)) { if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT, Constants.SPRING_PROFILE_HEROKU)) { taskExecutor.execute(() -> { try { log.warn("Starting Liquibase asynchronously, your database might not be ready at startup!"); initDb(); } catch (LiquibaseException e) { log.error("Liquibase could not start correctly, your database is NOT ready: {}", e.getMessage(), e); } }); } else { log.debug("Starting Liquibase synchronously"); initDb(); } } else { log.debug("Liquibase is disabled"); } }
Example #6
Source File: _AsyncSpringLiquibase.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 6 votes |
@Override public void afterPropertiesSet() throws LiquibaseException { if (!env.acceptsProfiles(Constants.SPRING_PROFILE_NO_LIQUIBASE)) { if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT, Constants.SPRING_PROFILE_HEROKU)) { taskExecutor.execute(() -> { try { log.warn("Starting Liquibase asynchronously, your database might not be ready at startup!"); initDb(); } catch (LiquibaseException e) { log.error("Liquibase could not start correctly, your database is NOT ready: {}", e.getMessage(), e); } }); } else { log.debug("Starting Liquibase synchronously"); initDb(); } } else { log.debug("Liquibase is disabled"); } }
Example #7
Source File: AsyncSpringLiquibase.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 6 votes |
@Override public void afterPropertiesSet() throws LiquibaseException { if (!env.acceptsProfiles(Constants.SPRING_PROFILE_NO_LIQUIBASE)) { if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT, Constants.SPRING_PROFILE_HEROKU)) { taskExecutor.execute(() -> { try { log.warn("Starting Liquibase asynchronously, your database might not be ready at startup!"); initDb(); } catch (LiquibaseException e) { log.error("Liquibase could not start correctly, your database is NOT ready: {}", e.getMessage(), e); } }); } else { log.debug("Starting Liquibase synchronously"); initDb(); } } else { log.debug("Liquibase is disabled"); } }
Example #8
Source File: AsyncSpringLiquibase.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 6 votes |
@Override public void afterPropertiesSet() throws LiquibaseException { if (!env.acceptsProfiles(Constants.SPRING_PROFILE_NO_LIQUIBASE)) { if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT, Constants.SPRING_PROFILE_HEROKU)) { taskExecutor.execute(() -> { try { log.warn("Starting Liquibase asynchronously, your database might not be ready at startup!"); initDb(); } catch (LiquibaseException e) { log.error("Liquibase could not start correctly, your database is NOT ready: {}", e.getMessage(), e); } }); } else { log.debug("Starting Liquibase synchronously"); initDb(); } } else { log.debug("Liquibase is disabled"); } }
Example #9
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 #10
Source File: AsyncSpringLiquibase.java From expper with GNU General Public License v3.0 | 6 votes |
@Override public void afterPropertiesSet() throws LiquibaseException { if (env.acceptsProfiles(Constants.SPRING_PROFILE_DEVELOPMENT, Constants.SPRING_PROFILE_HEROKU)) { taskExecutor.execute(() -> { try { log.warn("Starting Liquibase asynchronously, your database might not be ready at startup!"); initDb(); } catch (LiquibaseException e) { log.error("Liquibase could not start correctly, your database is NOT ready: {}", e.getMessage(), e); } }); } else { log.debug("Starting Liquibase synchronously"); initDb(); } }
Example #11
Source File: Launcher.java From jweb-cms with GNU Affero General Public License v3.0 | 6 votes |
public void start() { try { if (isMigrationNeeded()) { migrate(); } } catch (LiquibaseException | SQLException e) { throw new ApplicationException("failed to migrate database", e); } app = new UndertowApp(dir); ServiceLoader<AbstractModule> modules = ServiceLoader.load(AbstractModule.class); for (AbstractModule module : modules) { app.install(module); } app.start(); }
Example #12
Source File: AbstractJdbcDatabase.java From jweb-cms with GNU Affero General Public License v3.0 | 6 votes |
@Override public void execute(final SqlStatement[] statements, final List<SqlVisitor> sqlVisitors) throws LiquibaseException { for (SqlStatement statement : statements) { if (statement.skipOnUnsupported() && !SqlGeneratorFactory.getInstance().supports(statement, this)) { continue; } LogService.getLog(getClass()).debug(LogType.LOG, "Executing Statement: " + statement); try { ExecutorService.getInstance().getExecutor(this).execute(statement, sqlVisitors); } catch (DatabaseException e) { if (statement.continueOnError()) { LogService.getLog(getClass()).severe(LogType.LOG, "Error executing statement '" + statement.toString() + "', but continuing", e); } else { throw e; } } } }
Example #13
Source File: AsyncSpringLiquibase.java From jhipster with Apache License 2.0 | 5 votes |
/** * <p>initDb.</p> * * @throws liquibase.exception.LiquibaseException if any. */ protected void initDb() throws LiquibaseException { StopWatch watch = new StopWatch(); watch.start(); super.afterPropertiesSet(); watch.stop(); logger.debug(STARTED_MESSAGE, watch.getTotalTimeMillis()); if (watch.getTotalTimeMillis() > SLOWNESS_THRESHOLD * 1000L) { logger.warn(SLOWNESS_MESSAGE, SLOWNESS_THRESHOLD); } }
Example #14
Source File: RepositoryFactoryImpl.java From datashare with GNU Affero General Public License v3.0 | 5 votes |
void initDatabase(final DataSource dataSource) { try (Connection connection = dataSource.getConnection()){ Liquibase liquibase = new liquibase.Liquibase("liquibase/changelog/db.changelog.yml", new ClassLoaderResourceAccessor(), DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection))); liquibase.update(new Contexts()); } catch (LiquibaseException | SQLException e) { throw new RuntimeException(e); } }
Example #15
Source File: MessageDBTest.java From restful-booker-platform with GNU General Public License v3.0 | 5 votes |
@Before public void resetDB() throws SQLException, LiquibaseException { messageDB.resetDB(); Message message = new Message("James", "[email protected]", "01821 123321", "Just getting a message setup", "Lorem ipsum dolores est"); Message createdMessage = messageDB.create(message); currentMessageId = createdMessage.getMessageid(); }
Example #16
Source File: ModelDBHibernateUtil.java From modeldb with Apache License 2.0 | 5 votes |
private static void createTablesLiquibaseMigration(MetadataSources metaDataSrc) throws LiquibaseException, SQLException, InterruptedException { // Get database connection try (Connection con = metaDataSrc.getServiceRegistry().getService(ConnectionProvider.class).getConnection()) { JdbcConnection jdbcCon = new JdbcConnection(con); // Overwrite default liquibase table names by custom GlobalConfiguration liquibaseConfiguration = LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class); liquibaseConfiguration.setDatabaseChangeLogLockWaitTime(1L); // Initialize Liquibase and run the update Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(jdbcCon); String rootPath = System.getProperty(ModelDBConstants.userDir); rootPath = rootPath + "\\src\\main\\resources\\liquibase\\db-changelog-1.0.xml"; Liquibase liquibase = new Liquibase(rootPath, new FileSystemResourceAccessor(), database); boolean liquibaseExecuted = false; while (!liquibaseExecuted) { try { liquibase.update(new Contexts(), new LabelExpression()); liquibaseExecuted = true; } catch (LockException ex) { LOGGER.warn( "ModelDBHibernateUtil createTablesLiquibaseMigration() getting LockException ", ex); releaseLiquibaseLock(metaDataSrc); } } } }
Example #17
Source File: AsyncSpringLiquibase.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 5 votes |
protected void initDb() throws LiquibaseException { StopWatch watch = new StopWatch(); watch.start(); super.afterPropertiesSet(); watch.stop(); log.debug("Started Liquibase in {} ms", watch.getTotalTimeMillis()); }
Example #18
Source File: AsyncSpringLiquibase.java From OpenIoE with Apache License 2.0 | 5 votes |
protected void initDb() throws LiquibaseException { StopWatch watch = new StopWatch(); watch.start(); super.afterPropertiesSet(); watch.stop(); log.debug("Started Liquibase in {} ms", watch.getTotalTimeMillis()); }
Example #19
Source File: BaseTest.java From restful-booker-platform with GNU General Public License v3.0 | 5 votes |
@BeforeClass public static void createBookingDb() throws SQLException, LiquibaseException { // First we check if a DB is already open by seeing if // dbOpen is set to true. If it's not, create a new BookingDB if(!dbOpen){ bookingDB = new BookingDB(); bookingDB.resetDB(); dbOpen = true; } }
Example #20
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; } }
Example #21
Source File: ImpalaDatabase.java From liquibase-impala with Apache License 2.0 | 5 votes |
@Override public void execute(SqlStatement[] statements, List<SqlVisitor> sqlVisitors) throws LiquibaseException { if (syncDdl) { List<SqlStatement> sqlStatementList = new ArrayList<SqlStatement>(); sqlStatementList.add(UserSessionSettings.syncDdlStart()); sqlStatementList.addAll(Arrays.asList(statements)); sqlStatementList.add(UserSessionSettings.syncDdlStop()); SqlStatement[] wrappedStatements = new SqlStatement[sqlStatementList.size()]; sqlStatementList.toArray(wrappedStatements); super.execute(wrappedStatements, sqlVisitors); } else { super.execute(statements, sqlVisitors); } }
Example #22
Source File: AsyncSpringLiquibase.java From expper with GNU General Public License v3.0 | 5 votes |
protected void initDb() throws LiquibaseException { StopWatch watch = new StopWatch(); watch.start(); super.afterPropertiesSet(); watch.stop(); log.debug("Started Liquibase in {} ms", watch.getTotalTimeMillis()); }
Example #23
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 #24
Source File: HiveStandardChangeLogHistoryService.java From liquibase-impala with Apache License 2.0 | 5 votes |
@Override public int getNextSequenceValue() throws LiquibaseException { if (lastChangeSetSequenceValue == null) { if (getDatabase().getConnection() == null) { lastChangeSetSequenceValue = 0; } else { lastChangeSetSequenceValue = ExecutorService.getInstance().getExecutor(getDatabase()).queryForInt(new GetNextChangeSetSequenceValueStatement()); } } return ++lastChangeSetSequenceValue; }
Example #25
Source File: HiveStandardChangeLogHistoryService.java From liquibase-impala with Apache License 2.0 | 5 votes |
private boolean hasDatabaseChangeLogTable() throws DatabaseException { if (hasDatabaseChangeLogTable == null) { try { hasDatabaseChangeLogTable = SnapshotGeneratorFactory.getInstance().hasDatabaseChangeLogTable(getDatabase()); } catch (LiquibaseException e) { throw new UnexpectedLiquibaseException(e); } } return hasDatabaseChangeLogTable; }
Example #26
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 #27
Source File: HiveMarkChangeSetRanGenerator.java From liquibase-impala with Apache License 2.0 | 5 votes |
@Override public Sql[] generateSql(MarkChangeSetRanStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { ChangeSet changeSet = statement.getChangeSet(); SqlStatement runStatement; try { if (statement.getExecType().equals(ChangeSet.ExecType.FAILED) || statement.getExecType().equals(ChangeSet.ExecType.SKIPPED)) { return new Sql[0]; //don't mark } String tag = null; for (Change change : changeSet.getChanges()) { if (change instanceof TagDatabaseChange) { TagDatabaseChange tagChange = (TagDatabaseChange) change; tag = tagChange.getTag(); } } runStatement = new HiveInsertStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName()) .addColumnValue(changeSet.getId()) .addColumnValue(changeSet.getAuthor()) .addColumnValue(changeSet.getFilePath()) .addColumnValue(DateTimeUtils.getCurrentTS("yyyy-MM-dd HH:mm:ss")) .addColumnValue(ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).getNextSequenceValue()) .addColumnValue(statement.getExecType().value) .addColumnValue(changeSet.generateCheckSum().toString()) .addColumnValue(changeSet.getDescription()) .addColumnValue(StringUtils.trimToEmpty(changeSet.getComments())) .addColumnValue(tag == null ? "NULL" : tag) .addColumnValue(ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).getDeploymentId()) .addColumnValue(changeSet.getContexts() == null || changeSet.getContexts().isEmpty() ? null : changeSet.getContexts().toString()) .addColumnValue(changeSet.getLabels() == null || changeSet.getLabels().isEmpty() ? null : changeSet.getLabels().toString()) .addColumnValue(LiquibaseUtil.getBuildVersion()); } catch (LiquibaseException e) { throw new UnexpectedLiquibaseException(e); } return SqlGeneratorFactory.getInstance().generateSql(runStatement, database); }
Example #28
Source File: SpringLiquibase.java From airsonic with GNU General Public License v3.0 | 5 votes |
@Override public void afterPropertiesSet() throws LiquibaseException { LOG.trace("Starting Liquibase Update"); try { super.afterPropertiesSet(); } catch (Exception e) { LOG.error("==============================================="); LOG.error("An exception occurred during database migration"); LOG.error("A rollback file has been generated at " + rollbackFile); LOG.error("Execute it within your database to rollback any changes"); LOG.error("The exception is as follows\n", e); LOG.error("==============================================="); throw(e); } }
Example #29
Source File: AsyncSpringLiquibaseTest.java From jhipster with Apache License 2.0 | 5 votes |
@Override protected void initDb() throws LiquibaseException { synchronized (executor) { super.initDb(); executor.notifyAll(); } }
Example #30
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()); }