本文整理汇总了Java中liquibase.database.DatabaseConnection类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseConnection类的具体用法?Java DatabaseConnection怎么用?Java DatabaseConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseConnection类属于liquibase.database包,在下文中一共展示了DatabaseConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConnectionSchemaName
import liquibase.database.DatabaseConnection; //导入依赖的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: start
import liquibase.database.DatabaseConnection; //导入依赖的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));
}
示例3: createLiquibaseInstance
import liquibase.database.DatabaseConnection; //导入依赖的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);
}
}
示例4: createDatabase
import liquibase.database.DatabaseConnection; //导入依赖的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;
}
示例5: close
import liquibase.database.DatabaseConnection; //导入依赖的package包/类
@Override
public void close() throws DatabaseException {
// copy-paste from AbstractJdbcDatabase plus reflection to deal with private fields...
ExecutorService.getInstance().clearExecutor(this);
DatabaseConnection connection = getConnection();
if (connection != null) {
Boolean previousAutoCommit = previousAutoCommit();
if (previousAutoCommit != null) {
try {
connection.setAutoCommit(previousAutoCommit);
} catch (DatabaseException e) {
LogFactory.getInstance().getLog().warning("Failed to restore the auto commit to " + previousAutoCommit);
throw e;
}
}
connection.close();
}
}
示例6: setup
import liquibase.database.DatabaseConnection; //导入依赖的package包/类
@Before
public void setup() {
System.setProperty(Configuration.LIQUIBASE_PASSWORD, "root");
database = new MySQLDatabase();
database.setLiquibaseSchemaName("testdb");
DatabaseConnection conn = new MockDatabaseConnection("jdbc:mysql://[email protected]:3306/testdb",
"[email protected]");
database.setConnection(conn);
ExecutorService.getInstance().setExecutor(database, new JdbcExecutor());
PTOnlineSchemaChangeStatement.available = true;
PTOnlineSchemaChangeStatement.perconaToolkitVersion = null;
System.setProperty(Configuration.FAIL_IF_NO_PT, "false");
System.setProperty(Configuration.NO_ALTER_SQL_DRY_MODE, "false");
System.setProperty(Configuration.SKIP_CHANGES, "");
setupChange(change);
}
示例7: setConnection
import liquibase.database.DatabaseConnection; //导入依赖的package包/类
@Override
public void setConnection(DatabaseConnection conn) {
try {
Method wrappedConn = conn.getClass().getMethod("getWrappedConnection");
wrappedConn.setAccessible(true);
Connection sqlConn = (Connection)wrappedConn.invoke(conn);
Method method = sqlConn.getClass().getMethod("setRemarksReporting", Boolean.TYPE);
method.setAccessible(true);
method.invoke(sqlConn, true);
reservedWords.addAll(Arrays.asList(sqlConn.getMetaData().getSQLKeywords().toUpperCase().split(",\\s*")));
reservedWords.addAll(Arrays.asList("USER", "SESSION","RESOURCE")); //more reserved words not returned by driver
} catch (Exception e) {
LogFactory.getLogger().info("Could not set remarks reporting on OracleDatabase: "+e.getMessage());
; //cannot set it. That is OK
}
super.setConnection(conn);
}
示例8: check
import liquibase.database.DatabaseConnection; //导入依赖的package包/类
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
DatabaseConnection connection = database.getConnection();
try {
String result = (String) ExecutorService.getInstance().getExecutor(database).queryForObject(new RawSqlStatement(getSql().replaceFirst(";$","")), String.class);
if (result == null) {
throw new PreconditionFailedException("No rows returned from SQL Precondition", changeLog, this);
}
if (!expectedResult.equals(result)) {
throw new PreconditionFailedException("SQL Precondition failed. Expected '"+expectedResult+"' got '"+result+"'", changeLog, this);
}
} catch (DatabaseException e) {
throw new PreconditionErrorException(e, changeLog, this);
}
}
示例9: execute
import liquibase.database.DatabaseConnection; //导入依赖的package包/类
public Object execute(StatementCallback action, List<SqlVisitor> sqlVisitors) throws DatabaseException {
DatabaseConnection con = database.getConnection();
Statement stmt = null;
try {
stmt = ((JdbcConnection) con).getUnderlyingConnection().createStatement();
Statement stmtToUse = stmt;
return action.doInStatement(stmtToUse);
}
catch (SQLException ex) {
// Release Connection early, to avoid potential connection pool deadlock
// in the case when the exception translator hasn't been initialized yet.
JdbcUtils.closeStatement(stmt);
stmt = null;
throw new DatabaseException("Error executing SQL " + StringUtils.join(applyVisitors(action.getStatement(), sqlVisitors), "; on "+ con.getURL())+": "+ex.getMessage(), ex);
}
finally {
JdbcUtils.closeStatement(stmt);
}
}
示例10: geometryColumnsExistsTestData
import liquibase.database.DatabaseConnection; //导入依赖的package包/类
@DataProvider
public Object[][] geometryColumnsExistsTestData() throws SQLException {
// Create an H2 database instance without geometry_columns table.
final Database noGeometryColumnsDatabase = new H2Database();
noGeometryColumnsDatabase.setConnection(new JdbcConnection(DriverManager
.getConnection("jdbc:h2:mem:target/noGeometryColumns")));
final Database geometryColumnsDatabase = new H2Database();
Connection connection = DriverManager
.getConnection("jdbc:h2:mem:target/geometryColumns");
DatabaseConnection conn = new JdbcConnection(connection);
geometryColumnsDatabase.setConnection(conn);
Statement statement = connection.createStatement();
statement
.execute("CREATE TABLE geometry_columns (f_table_schema VARCHAR(128), "
+ "f_table_name VARCHAR(128), f_geometry_column VARCHAR(128), coord_dimension INT, "
+ "srid INT, type VARCHAR(30))");
statement.close();
return new Object[][] {
new Object[] { noGeometryColumnsDatabase, false },
new Object[] { geometryColumnsDatabase, true } };
}
示例11: migrate
import liquibase.database.DatabaseConnection; //导入依赖的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);
}
}
示例12: createLiquibaseInstance
import liquibase.database.DatabaseConnection; //导入依赖的package包/类
public Liquibase createLiquibaseInstance(DmnEngineConfiguration dmnEngineConfiguration)
throws SQLException, DatabaseException, LiquibaseException {
Connection jdbcConnection = null;
CommandContext commandContext = CommandContextUtil.getCommandContext();
if (commandContext == null) {
jdbcConnection = dmnEngineConfiguration.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(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName());
database.setDatabaseChangeLogLockTableName(DmnEngineConfiguration.LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName());
String databaseSchema = dmnEngineConfiguration.getDatabaseSchema();
if (StringUtils.isNotEmpty(databaseSchema)) {
database.setDefaultSchemaName(databaseSchema);
database.setLiquibaseSchemaName(databaseSchema);
}
String databaseCatalog = dmnEngineConfiguration.getDatabaseCatalog();
if (StringUtils.isNotEmpty(databaseCatalog)) {
database.setDefaultCatalogName(databaseCatalog);
database.setLiquibaseCatalogName(databaseCatalog);
}
Liquibase liquibase = new Liquibase(LIQUIBASE_CHANGELOG, new ClassLoaderResourceAccessor(), database);
return liquibase;
}
示例13: main
import liquibase.database.DatabaseConnection; //导入依赖的package包/类
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();
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: dropSchema
import liquibase.database.DatabaseConnection; //导入依赖的package包/类
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);
}
示例15: createDbConnection
import liquibase.database.DatabaseConnection; //导入依赖的package包/类
protected static DatabaseConnection createDbConnection() throws Exception {
Properties properties = new Properties();
properties.load(DbScriptUtil.class.getClassLoader().getResourceAsStream("META-INF/flowable-admin/TEST-db.properties"));
Connection connection = DriverManager.getConnection(properties.getProperty("datasource.url"),
properties.getProperty("datasource.username"), properties.getProperty("datasource.password"));
DatabaseConnection databaseConnection = new JdbcConnection(connection);
return databaseConnection;
}