本文整理汇总了Java中liquibase.resource.ResourceAccessor类的典型用法代码示例。如果您正苦于以下问题:Java ResourceAccessor类的具体用法?Java ResourceAccessor怎么用?Java ResourceAccessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceAccessor类属于liquibase.resource包,在下文中一共展示了ResourceAccessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initDatabaseSchema
import liquibase.resource.ResourceAccessor; //导入依赖的package包/类
private void initDatabaseSchema() throws SQLException, LiquibaseException {
if (config.hasKey("database.changelog")) {
ResourceAccessor resourceAccessor = new FileSystemResourceAccessor();
Database database = DatabaseFactory.getInstance().openDatabase(
config.getString("database.url"),
config.getString("database.user"),
config.getString("database.password"),
null, resourceAccessor);
Liquibase liquibase = new Liquibase(
config.getString("database.changelog"), resourceAccessor, database);
liquibase.clearCheckSums();
liquibase.update(new Contexts());
}
}
示例2: LiquibaseHelper
import liquibase.resource.ResourceAccessor; //导入依赖的package包/类
LiquibaseHelper(
final Map<String, String> props,
final ResourceAccessor resourceAccessor,
final File resourcesDir,
final String masterChangeLogName) {
this.resourceAccessor = resourceAccessor;
this.resourcesDir = resourcesDir;
persistenceUnitName = props.get(MinijaxProperties.PERSISTENCE_UNIT_NAME);
driver = props.get(MinijaxProperties.DB_DRIVER);
url = props.get(MinijaxProperties.DB_URL);
username = props.get(MinijaxProperties.DB_USERNAME);
password = props.get(MinijaxProperties.DB_PASSWORD);
referenceUrl = props.get(MinijaxProperties.DB_REFERENCE_URL);
migrationsDir = new File(resourcesDir, MIGRATIONS_DIR);
masterChangeLogFile = new File(migrationsDir, masterChangeLogName);
}
示例3: createTables
import liquibase.resource.ResourceAccessor; //导入依赖的package包/类
private void createTables(String changelog) {
Connection holdingConnection;
try {
ResourceAccessor resourceAccessor = new FileSystemResourceAccessor();
holdingConnection = getConnectionImpl(USER_NAME, getPostgresPassword());
JdbcConnection conn = new JdbcConnection(holdingConnection);
PostgresDatabase database = new PostgresDatabase();
database.setDefaultSchemaName("public");
database.setConnection(conn);
liquibase = new Liquibase(changelog, resourceAccessor, database);
liquibase.dropAll();
liquibase.update("test");
conn.close();
} catch (SQLException | LiquibaseException ex) {
LOG.error("Error during createTable step", ex);
throw new RuntimeException("Error during createTable step", ex);
}
}
示例4: LinearProgressionFacade
import liquibase.resource.ResourceAccessor; //导入依赖的package包/类
/**
*
* @param connection The JDBC connection to work on.
* @param versions The versions used as reference.
* @param changesetFileLocator A function that returns the path to where the liquibase changeset file is located for a given version.
* @param resourceAccessorGenerator A function that returns the {@code ResourceAccessor} used to fetch a given version's changeset file.
* @throws NullPointerException if any of the parameters are {@code null}
* @throws IllegalArgumentException if {@code versions} is empty
* @throws IllegalStateException if {@code versions} does not contain the {@link Version versions} already applied to the database schema
* @since 1.0.0
*/
public LinearProgressionFacade(
Connection connection,
List<Version> versions,
Function<Version, String> changesetFileLocator,
Function<Version, ResourceAccessor> resourceAccessorGenerator
) throws LiquibaseException {
this.connection = Objects.requireNonNull(connection, "null connection.");
this.versions = Optional.of(new ArrayList<>(Objects.requireNonNull(versions, "null version list.")))
.filter(v -> v.size() > 0)
.orElseThrow(() -> new IllegalArgumentException("empty version list."));
this.changesetFileLocator = Objects.requireNonNull(changesetFileLocator, "null changesetFileLocator function.");
this.resourceAccessorGenerator = Objects.requireNonNull(resourceAccessorGenerator, "null resourceAccessorGenerator function.");
errorOnInconsistentDatabaseRevisions();
}
示例5: createDatabase
import liquibase.resource.ResourceAccessor; //导入依赖的package包/类
protected Database createDatabase(Connection c, ResourceAccessor resourceAccessor) throws DatabaseException {
DatabaseConnection liquibaseConnection = new JdbcConnection(c);
DatabaseFactory databaseFactory = DatabaseFactory.getInstance();
// expand factory with our extensions....
databaseFactory.register(new DerbyDatabase());
Database database = databaseFactory.findCorrectDatabaseImplementation(liquibaseConnection);
// set default schema
String defaultSchema = cli.optionString(LiquibaseModule.DEFAULT_SCHEMA_OPTION);
if (defaultSchema != null) {
database.setDefaultSchemaName(defaultSchema);
}
return database;
}
示例6: createLiquibase
import liquibase.resource.ResourceAccessor; //导入依赖的package包/类
protected Liquibase createLiquibase() throws Exception {
ResourceAccessor antFO = new AntResourceAccessor(getProject(), classpath);
ResourceAccessor fsFO = new FileSystemResourceAccessor();
Database database = createDatabaseObject(getDriver(), getUrl(), getUsername(), getPassword(), getDefaultSchemaName(), getDatabaseClass());
String changeLogFile = null;
if (getChangeLogFile() != null) {
changeLogFile = getChangeLogFile().trim();
}
Liquibase liquibase = new Liquibase(changeLogFile, new CompositeResourceAccessor(antFO, fsFO), database);
liquibase.setCurrentDateTimeFunction(currentDateTimeFunction);
for (Map.Entry<String, Object> entry : changeLogProperties.entrySet()) {
liquibase.setChangeLogParameter(entry.getKey(), entry.getValue());
}
return liquibase;
}
示例7: parse
import liquibase.resource.ResourceAccessor; //导入依赖的package包/类
public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException {
RawSQLChange change = new RawSQLChange();
try {
InputStream sqlStream = resourceAccessor.getResourceAsStream(physicalChangeLogLocation);
String sql = StreamUtil.getStreamContents(sqlStream, null);
change.setSql(sql);
} catch (IOException e) {
throw new ChangeLogParseException(e);
}
change.setResourceAccessor(resourceAccessor);
change.setSplitStatements(false);
change.setStripComments(false);
ChangeSet changeSet = new ChangeSet("raw", "includeAll", false, false, physicalChangeLogLocation, null, null, true);
changeSet.addChange(change);
DatabaseChangeLog changeLog = new DatabaseChangeLog();
changeLog.setPhysicalFilePath(physicalChangeLogLocation);
changeLog.addChangeSet(changeSet);
return changeLog;
}
示例8: testLiquibaseUpdateTestingRollback
import liquibase.resource.ResourceAccessor; //导入依赖的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();
}
}
示例9: testLiquibaseUpdate
import liquibase.resource.ResourceAccessor; //导入依赖的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();
}
}
示例10: update
import liquibase.resource.ResourceAccessor; //导入依赖的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);
}
}
示例11: parseAndGenerate
import liquibase.resource.ResourceAccessor; //导入依赖的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());
}
示例12: parseAndGenerate
import liquibase.resource.ResourceAccessor; //导入依赖的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());
}
示例13: performDatabaseSetupOrClean
import liquibase.resource.ResourceAccessor; //导入依赖的package包/类
private void performDatabaseSetupOrClean(boolean setup) {
try {
ResourceAccessor resourceAccessor = new FileSystemResourceAccessor();
Class.forName(getJdbcDriverClassname());
Connection holdingConnection = DriverManager.getConnection(getJdbcConnectionString(), getDbUsername(), getDbPassword());
HsqlConnection hsconn = new HsqlConnection(holdingConnection);
LogFactory.getLogger().setLogLevel("warning");
Liquibase liquibase = new Liquibase(CHANGE_LOG, resourceAccessor, hsconn);
liquibase.dropAll();
if (setup) {
liquibase.update("test");
liquibase = new Liquibase(TEST_DATA_CHANGE_LOG, resourceAccessor, hsconn);
liquibase.update("test");
}
hsconn.close();
} catch (Exception ex) {
String msg = setup ? "Error during database initialization" : "Error during database clean-up";
LOG.error(msg, ex);
throw new RuntimeException(msg, ex);
}
}
示例14: migrate
import liquibase.resource.ResourceAccessor; //导入依赖的package包/类
/**
* <p>migrate</p>
*
* @param migration a {@link org.opennms.core.schema.Migration} object.
* @throws org.opennms.core.schema.MigrationException if any.
*/
public void migrate(final Migration migration) throws MigrationException {
Connection connection = null;
try {
connection = m_dataSource.getConnection();
final DatabaseConnection dbConnection = new JdbcConnection(connection);
ResourceAccessor accessor = migration.getAccessor();
if (accessor == null) accessor = new SpringResourceAccessor();
final Liquibase liquibase = new Liquibase( migration.getChangeLog(), accessor, dbConnection );
liquibase.setChangeLogParameter("install.database.admin.user", migration.getAdminUser());
liquibase.setChangeLogParameter("install.database.admin.password", migration.getAdminPassword());
liquibase.setChangeLogParameter("install.database.user", migration.getDatabaseUser());
liquibase.getDatabase().setDefaultSchemaName(migration.getSchemaName());
final String contexts = System.getProperty("opennms.contexts", "production");
liquibase.update(contexts);
} catch (final Throwable e) {
throw new MigrationException("unable to migrate the database", e);
} finally {
cleanUpDatabase(connection, null, null);
}
}
示例15: applyChangelog
import liquibase.resource.ResourceAccessor; //导入依赖的package包/类
private void applyChangelog(
final Connection c,
final String contexts,
final ResourceAccessor resourceAccessor,
final String changelogFile
) throws LiquibaseException {
liquibase.Liquibase liquibase = null;
final Database database = DatabaseFactory.getInstance()
.findCorrectDatabaseImplementation(new JdbcConnection(c));
liquibase = new liquibase.Liquibase(changelogFile, resourceAccessor, database);
liquibase.update(contexts);
}