本文整理匯總了Java中liquibase.resource.ClassLoaderResourceAccessor類的典型用法代碼示例。如果您正苦於以下問題:Java ClassLoaderResourceAccessor類的具體用法?Java ClassLoaderResourceAccessor怎麽用?Java ClassLoaderResourceAccessor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClassLoaderResourceAccessor類屬於liquibase.resource包,在下文中一共展示了ClassLoaderResourceAccessor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUpClass
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
@BeforeClass
public static void setUpClass() throws ParserConfigurationException, IOException, SAXException, SQLException, LiquibaseException {
ApplicationConfig config = ConfigurationBuilder.createBuilder().loadXMLConfiguration().getConfiguration();
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl("jdbc:" + config.getDbUrl() + "/" + config.getDbName());
hikariConfig.setUsername(config.getDbUser());
hikariConfig.setPassword(config.getDbPassword());
hikariConfig.setMaximumPoolSize(config.getThreadLimit());
if(config.isDbIgnoreSSLWarn()) {
hikariConfig.addDataSourceProperty("useSSL", false);
}
dataSource = new HikariDataSource(hikariConfig);
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(dataSource.getConnection()));
Liquibase liquibase = new Liquibase("db/changelog/db.changelog-master.yaml", new ClassLoaderResourceAccessor(), database);
liquibase.update(new Contexts(), new LabelExpression());
}
示例2: run
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
@Override
public void run(ProductCatalogConfiguration configuration, Environment environment) throws Exception {
environment.jersey().setUrlPattern("/api/*");
environment.healthChecks().register("product catalog service",
guiceBundle.getInjector().getInstance(ProductCatalogServiceHealthCheck.class));
// run the migrations as part of startup and prepare the db with sample
// data
ManagedDataSource mds = configuration.getDataSourceFactory().build(environment.metrics(), "migrations");
try (Connection connection = mds.getConnection()) {
Liquibase migrator = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(),
new JdbcConnection(connection));
migrator.dropAll();
migrator.clearCheckSums();
migrator.update("");
}
}
示例3: run
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
@Override
public void run(final ProductReviewConfiguration configuration, final Environment environment) throws Exception {
environment.jersey().setUrlPattern("/api/*");
environment.healthChecks().register("product review service",
guiceBundle.getInjector().getInstance(ProductReviewServiceHealthCheck.class));
// run the migrations as part of startup and prepare the db with sample
// data
ManagedDataSource mds = configuration.getDataSourceFactory().build(environment.metrics(), "migrations");
try (Connection connection = mds.getConnection()) {
Liquibase migrator = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(),
new JdbcConnection(connection));
migrator.dropAll();
migrator.clearCheckSums();
migrator.update("");
}
}
示例4: createLiquibaseInstance
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
protected static Liquibase createLiquibaseInstance(ContentEngineConfiguration configuration) {
try {
Connection jdbcConnection = null;
CommandContext commandContext = CommandContextUtil.getCommandContext();
if (commandContext == null) {
jdbcConnection = configuration.getDataSource().getConnection();
} else {
jdbcConnection = CommandContextUtil.getDbSqlSession(commandContext).getSqlSession().getConnection();
}
if (!jdbcConnection.getAutoCommit()) {
jdbcConnection.commit();
}
DatabaseConnection connection = new JdbcConnection(jdbcConnection);
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
database.setDatabaseChangeLogTableName(ContentEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
database.setDatabaseChangeLogLockTableName(ContentEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());
Liquibase liquibase = new Liquibase(LIQUIBASE_CHANGELOG, new ClassLoaderResourceAccessor(), database);
return liquibase;
} catch (Exception e) {
throw new FlowableException("Error creating liquibase instance", e);
}
}
示例5: recordSchemaDifferencesBetweenHbm2ddlAndLiquibase
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
public void recordSchemaDifferencesBetweenHbm2ddlAndLiquibase() throws SQLException, LiquibaseException,
IOException, ParserConfigurationException {
Database referenceConnection = createDatabase(liquibaseDataSource.getConnection());
Database comparisonConnection = createDatabase(hbm2ddlDataSource.getConnection());
Liquibase liquibaseObject =
new Liquibase("liquibase/changelog-master.xml", new ClassLoaderResourceAccessor(), referenceConnection);
liquibaseObject.dropAll();
liquibaseObject.update("");
DiffResult result =
DiffGeneratorFactory.getInstance().compare(comparisonConnection, referenceConnection, new CompareControl());
DiffToChangeLog changeLog = new DiffToChangeLog(result, new DiffOutputControl(false, false, false));
changeLog.print(new File("target/schemaDifferences.xml").getAbsolutePath(), new XMLChangeLogSerializer());
changeLog.print(System.out);
}
示例6: getLiquibase
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
private Liquibase getLiquibase(Connection connection) throws Exception {
ServiceLocator sl = ServiceLocator.getInstance();
if (!System.getProperties().containsKey("liquibase.scan.packages")) {
if (sl.getPackages().remove("liquibase.core")) {
sl.addPackageToScan("liquibase.core.xml");
}
if (sl.getPackages().remove("liquibase.parser")) {
sl.addPackageToScan("liquibase.parser.core.xml");
}
if (sl.getPackages().remove("liquibase.serializer")) {
sl.addPackageToScan("liquibase.serializer.core.xml");
}
sl.getPackages().remove("liquibase.ext");
sl.getPackages().remove("liquibase.sdk");
}
LogFactory.setInstance(new LogWrapper());
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
return new Liquibase(CHANGELOG, new ClassLoaderResourceAccessor(getClass().getClassLoader()), database);
}
示例7: initPool
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
private static JDBCPool initPool() {
System.out.println("Initing DB...");
File deciDir = new File("./deciservice");
if (!deciDir.exists() && !deciDir.mkdirs()) {
throw new RuntimeException("Could not create " + deciDir);
}
File deciDb = new File(deciDir, "deciservicedb");
JDBCPool jdbc = new JDBCPool();
jdbc.setUrl("jdbc:hsqldb:" + deciDb.toURI());
jdbc.setUser("SA");
jdbc.setPassword("SA");
try (Connection c = jdbc.getConnection()) {
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(c));
Liquibase liquibase = new Liquibase("deciservice-db.yaml", new ClassLoaderResourceAccessor(), database);
liquibase.update((String) null);
} catch (SQLException | LiquibaseException ex) {
throw new AppServerException("Cannot initialize notes service: " + ex.getMessage(), ex);
}
return jdbc;
}
示例8: warmUp
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
@BeforeClass
public static void warmUp() throws LiquibaseException, SQLException, IOException, ClassNotFoundException {
System.setProperty("lunchy.db.driver", "org.hsqldb.jdbc.JDBCDriver");
System.setProperty("lunchy.db.url", "jdbc:hsqldb:mem:mymemdb");
System.setProperty("lunchy.db.schema", "");
// System.setProperty("lunchy.db.url", "jdbc:hsqldb:hsql://localhost/");
// System.setProperty("lunchy.db.schema", "xdb");
System.setProperty("lunchy.db.user", "sa");
DBConn.INSTANCE.setupDriver();
try (Connection con = DBConn.INSTANCE.get()) {
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(con));
Liquibase liquibaseDD = new Liquibase("all_tables.xml", new ClassLoaderResourceAccessor(), database);
liquibaseDD.update("junit-warmup");
// Liquibase liquibaseDM = new Liquibase("all_data.xml", new ClassLoaderResourceAccessor(), database);
// liquibaseDM.update("junit-warmup");
}
RndDataGenerator dataGen = new RndDataGenerator(0);
dataGen.genCommunities();
}
示例9: after
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
public static void after(final String persistenceUnit, final String propertiesCategory) {
final EntityManager entityManager = entityManagerFactory.createEntityManager();
try {
final String changeLog = PropertiesUtil.getProperty(
propertiesCategory, "liquibase-change-log");
entityManager.getTransaction().begin();
final Connection connection = entityManager.unwrap(Connection.class);
final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(
new JdbcConnection(connection));
final Liquibase liquibase = new Liquibase(changeLog, new ClassLoaderResourceAccessor(), database);
liquibase.dropAll();
} catch (Exception e) {
throw new SiteException("Error clearing database.", e);
}
entityManager.close();
entityManagerFactory.close();
PersistenceUtil.removeEntityManagerFactory(persistenceUnit, propertiesCategory);
}
示例10: testLiquibaseUpdateTestingRollback
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
/**
* 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();
}
}
示例11: testLiquibaseUpdate
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
/**
* 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();
}
}
示例12: update
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
public static void update(Connection con) {
LOG.info("Updating database schema with liquibase changesets ...");
try {
JdbcConnection jdbcConnection = new JdbcConnection(con);
liquibase.database.Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(jdbcConnection);
//if (database instanceof PostgresDatabase) {
// database = new PostgresDatabase() {
// @Override
// public String escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType) {
// return objectName;
// }
// };
// database.setConnection(jdbcConnection);
//}
ResourceAccessor accessor = new ClassLoaderResourceAccessor(Thread.currentThread().getContextClassLoader());
Liquibase liq = new Liquibase("liquibase/master.xml", accessor, database);
liq.update("prod");
LOG.info("Database schema updated");
} catch (Exception e) {
LOG.error("Database liquibase update failed", e);
throw new RuntimeException(e);
}
}
示例13: parseAndGenerate
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
@Test
public void parseAndGenerate() throws Exception {
if (connection == null) {
return;
}
Database database = liquiBase.getDatabase();
ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor();
ChangeLogParameters changeLogParameters = new ChangeLogParameters();
DatabaseChangeLog changeLog = ChangeLogParserFactory.getInstance().getParser(changeLogFile, resourceAccessor).parse(changeLogFile,
changeLogParameters, resourceAccessor);
liquiBase.checkLiquibaseTables(false, changeLog, new Contexts(), new LabelExpression());
changeLog.validate(database);
List<ChangeSet> changeSets = changeLog.getChangeSets();
Change change = changeSets.get(0).getChanges().get(0);
Sql[] sql = SqlGeneratorFactory.getInstance().generateSql(change.generateStatements(database)[0], database);
String expected = "DROP SYNONYM new_synonym";
assertEquals(expected, sql[0].toSql());
}
示例14: parseAndGenerate
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
@Test
public void parseAndGenerate() throws Exception {
if (connection == null) {
return;
}
Database database = liquiBase.getDatabase();
ResourceAccessor resourceAccessor = new ClassLoaderResourceAccessor();
ChangeLogParameters changeLogParameters = new ChangeLogParameters();
DatabaseChangeLog changeLog = ChangeLogParserFactory.getInstance().getParser(changeLogFile, resourceAccessor).parse(changeLogFile,
changeLogParameters, resourceAccessor);
liquiBase.checkLiquibaseTables(false, changeLog, new Contexts(), new LabelExpression());
changeLog.validate(database);
List<ChangeSet> changeSets = changeLog.getChangeSets();
Change change = changeSets.get(0).getChanges().get(0);
Sql[] sql = SqlGeneratorFactory.getInstance().generateSql(change.generateStatements(database)[0], database);
String expected = "CREATE SYNONYM new_synonym FOR object";
assertEquals(expected, sql[0].toSql());
}
示例15: rollback
import liquibase.resource.ClassLoaderResourceAccessor; //導入依賴的package包/類
public void rollback() throws SQLException, LiquibaseException {
Liquibase liquibase = null;
try (Connection connection = configuration.getCoreConnection()) {
connection.setSchema("public");
Database database = DatabaseFactory.getInstance()
.findCorrectDatabaseImplementation(new JdbcConnection(connection));
database.setLiquibaseSchemaName("public");
liquibase = new Liquibase(Loader.MODEL_COM_CHIRALBEHAVIORS_CORE_SCHEMA_CORE_XML,
new ClassLoaderResourceAccessor(getClass().getClassLoader()),
database);
initializeParameters(liquibase);
liquibase.rollback("initial-schema-create", configuration.contexts);
} catch (RollbackFailedException e) {
if (e.getMessage()
.contains("Could not find tag 'initial-schema-create")) {
log.info(String.format("%s is new database, not dropping",
configuration.coreDb));
return;
}
throw e;
}
}