本文整理汇总了Java中liquibase.database.jvm.JdbcConnection类的典型用法代码示例。如果您正苦于以下问题:Java JdbcConnection类的具体用法?Java JdbcConnection怎么用?Java JdbcConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JdbcConnection类属于liquibase.database.jvm包,在下文中一共展示了JdbcConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConnectionSchemaName
import liquibase.database.jvm.JdbcConnection; //导入依赖的package包/类
@Override
protected String getConnectionSchemaName() {
DatabaseConnection connection = getConnection();
if (connection == null) {
return null;
}
try {
ResultSet resultSet = ((JdbcConnection) connection).createStatement().executeQuery("SELECT CURRENT_SCHEMA()");
resultSet.next();
String schema = resultSet.getString(1);
return schema;
} catch (Exception e) {
log.info("Error getting default schema", e);
}
return null;
}
示例2: connectToDB
import liquibase.database.jvm.JdbcConnection; //导入依赖的package包/类
public static void connectToDB() throws Exception {
if (connection == null) {
info = new Properties();
info.load(new FileInputStream("src/test/resources/liquibase.properties"));
url = info.getProperty("url");
driver = (Driver) Class.forName(DatabaseFactory.getInstance().findDefaultDriver(url), true,
Thread.currentThread().getContextClassLoader()).newInstance();
connection = driver.connect(url, info);
if (connection == null) {
throw new DatabaseException("Connection could not be created to " + url + " with driver "
+ driver.getClass().getName() + ". Possibly the wrong driver for the given database URL");
}
jdbcConnection = new JdbcConnection(connection);
}
}
示例3: setUpClass
import liquibase.database.jvm.JdbcConnection; //导入依赖的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());
}
示例4: createTestData
import liquibase.database.jvm.JdbcConnection; //导入依赖的package包/类
@Before
public void createTestData() throws Exception {
Handle handle = dbiProvider.get().open();
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(handle.getConnection()));
Liquibase liquibase = new Liquibase("singularity_test.sql", new FileSystemResourceAccessor(), database);
liquibase.update((String) null);
try {
database.close();
} catch (Throwable t) {
}
handle.close();
}
示例5: invoke
import liquibase.database.jvm.JdbcConnection; //导入依赖的package包/类
@Override
public List<Map<String, ?>> invoke() {
StandardChangeLogHistoryService service = new StandardChangeLogHistoryService();
try {
DatabaseFactory factory = DatabaseFactory.getInstance();
DataSource dataSource = this.liquibase.getDataSource();
JdbcConnection connection = new JdbcConnection(dataSource.getConnection());
try {
Database database = factory.findCorrectDatabaseImplementation(connection);
return service.queryDatabaseChangeLogTable(database);
}
finally {
connection.close();
}
}
catch (Exception ex) {
throw new IllegalStateException("Unable to get Liquibase changelog", ex);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:LiquibaseEndpoint.java
示例6: start
import liquibase.database.jvm.JdbcConnection; //导入依赖的package包/类
@Override
public void start(final BundleContext context) throws Exception {
try (Connection connection = DefaultOfBizConnectionFactory.getInstance().getConnection()) {
DatabaseConnection databaseConnection = new JdbcConnection(connection);
Liquibase liquibase =
new Liquibase("META-INF/liquibase/org.everit.jira.hr.admin.changelog.xml",
new OSGiResourceAccessor(context.getBundle()), databaseConnection);
liquibase.update("production");
}
QuerydslSupportImpl querydslSupport = new QuerydslSupportImpl();
querydslSupport.execute((connection,
configuration) -> synchronizeDateSequenceIfNecessary(connection, configuration));
}
示例7: run
import liquibase.database.jvm.JdbcConnection; //导入依赖的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("");
}
}
示例8: run
import liquibase.database.jvm.JdbcConnection; //导入依赖的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("");
}
}
示例9: createLiquibaseInstance
import liquibase.database.jvm.JdbcConnection; //导入依赖的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);
}
}
示例10: migrate
import liquibase.database.jvm.JdbcConnection; //导入依赖的package包/类
public void migrate(String dbName) {
try {
Configuration configuration = yamlConfiguration.subset(dbName+ ".Hibernate");
Properties properties = new Properties();
properties.put("user", configuration.getProperty("hibernate.connection.username"));
properties.put("password", configuration.getProperty("hibernate.connection.password"));
String url = (String) configuration.getProperty("hibernate.connection.url");
Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection connection = DriverManager.getConnection(url, properties);
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(dbName+"/migrations.xml").getFile());
Liquibase liquibase = new Liquibase(file.getCanonicalPath(), new FileSystemResourceAccessor(), database);
liquibase.update(new Contexts());
} catch (Exception e) {
System.err.println("Unable to perform database migration.");
e.printStackTrace();
}
}
示例11: createTables
import liquibase.database.jvm.JdbcConnection; //导入依赖的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);
}
}
示例12: getLiquibase
import liquibase.database.jvm.JdbcConnection; //导入依赖的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);
}
示例13: initPool
import liquibase.database.jvm.JdbcConnection; //导入依赖的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;
}
示例14: createDatabase
import liquibase.database.jvm.JdbcConnection; //导入依赖的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;
}
示例15: connectToDB
import liquibase.database.jvm.JdbcConnection; //导入依赖的package包/类
public static void connectToDB() throws Exception {
if ( connection == null ) {
info = new Properties();
info.load( new FileInputStream( "src/test/resources/tests.properties" ) );
url = info.getProperty( "url" );
driver = (Driver) Class.forName( DatabaseFactory.getInstance().findDefaultDriver( url ), true, Thread.currentThread().getContextClassLoader() ).newInstance();
connection = driver.connect( url, info );
if ( connection == null ) {
throw new DatabaseException( "Connection could not be created to " + url + " with driver " + driver.getClass().getName() + ". Possibly the wrong driver for the given database URL" );
}
jdbcConnection = new JdbcConnection( connection );
}
}