當前位置: 首頁>>代碼示例>>Java>>正文


Java DatabaseFactory類代碼示例

本文整理匯總了Java中liquibase.database.DatabaseFactory的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseFactory類的具體用法?Java DatabaseFactory怎麽用?Java DatabaseFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DatabaseFactory類屬於liquibase.database包,在下文中一共展示了DatabaseFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initDatabaseSchema

import liquibase.database.DatabaseFactory; //導入依賴的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());
        }
    }
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:21,代碼來源:DataManager.java

示例2: connectToDB

import liquibase.database.DatabaseFactory; //導入依賴的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);
    }
}
 
開發者ID:CDKGlobal,項目名稱:liquibase-snowflake,代碼行數:20,代碼來源:BaseTestCase.java

示例3: setUpClass

import liquibase.database.DatabaseFactory; //導入依賴的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());
}
 
開發者ID:XIVStats,項目名稱:XIVStats-Gatherer-Java,代碼行數:22,代碼來源:GathererControllerIT.java

示例4: createTestData

import liquibase.database.DatabaseFactory; //導入依賴的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();
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:17,代碼來源:SingularityHistoryTest.java

示例5: invoke

import liquibase.database.DatabaseFactory; //導入依賴的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: createLiquibaseInstance

import liquibase.database.DatabaseFactory; //導入依賴的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);
    }
}
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:27,代碼來源:ContentDbSchemaManager.java

示例7: migrate

import liquibase.database.DatabaseFactory; //導入依賴的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();
    }
}
 
開發者ID:flipkart-incubator,項目名稱:flux,代碼行數:20,代碼來源:MigrationsRunner.java

示例8: getLiquibase

import liquibase.database.DatabaseFactory; //導入依賴的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);
}
 
開發者ID:Blazebit,項目名稱:blaze-storage,代碼行數:20,代碼來源:LiquibaseUpdater.java

示例9: initPool

import liquibase.database.DatabaseFactory; //導入依賴的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;
}
 
開發者ID:redsaz,項目名稱:deciservice,代碼行數:22,代碼來源:HsqlNotesService.java

示例10: createDatabase

import liquibase.database.DatabaseFactory; //導入依賴的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;
    }
 
開發者ID:bootique,項目名稱:bootique-liquibase,代碼行數:18,代碼來源:LiquibaseRunner.java

示例11: connectToDB

import liquibase.database.DatabaseFactory; //導入依賴的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 );
	}
}
 
開發者ID:mrswadge,項目名稱:liquibase-flexibleview,代碼行數:18,代碼來源:BaseTestCase.java

示例12: warmUp

import liquibase.database.DatabaseFactory; //導入依賴的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();
}
 
開發者ID:oglimmer,項目名稱:lunchy,代碼行數:21,代碼來源:TestDbLoadHsql.java

示例13: dropDatabaseObjects

import liquibase.database.DatabaseFactory; //導入依賴的package包/類
/**
 * Drops database objects of given schema.
 * @param persistenceUnit the persistence unit
 * @param propertiesCategory the properties category
 */
private static void dropDatabaseObjects(String persistenceUnit, String propertiesCategory) {
    try {
        final EntityManagerFactory tempRefEntityManagerFactory = newEntityManagerFactory(persistenceUnit, propertiesCategory);
        final EntityManager entityManager = tempRefEntityManagerFactory.createEntityManager();
        entityManager.getTransaction().begin();
        final Connection connection = entityManager.unwrap(Connection.class);
        final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
        database.dropDatabaseObjects(database.getDefaultSchema());
        entityManager.getTransaction().commit();
        entityManager.close();
        database.close();
        tempRefEntityManagerFactory.close();
    } catch(final Exception e) {
        throw new SiteException("Error dropping database objects.", e);
    }
}
 
開發者ID:bubblecloud,項目名稱:ilves,代碼行數:22,代碼來源:PersistenceUtil.java

示例14: after

import liquibase.database.DatabaseFactory; //導入依賴的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);
}
 
開發者ID:bubblecloud,項目名稱:ilves,代碼行數:19,代碼來源:TestUtil.java

示例15: main

import liquibase.database.DatabaseFactory; //導入依賴的package包/類
public static void main(String[] args) {
    for (Database database : DatabaseFactory.getInstance().getImplementedDatabases()) {
        TypeConverter typeConverter = TypeConverterFactory.getInstance().findTypeConverter(database);
        System.out.println("Database: "+database.getTypeName()+", Converter: "+typeConverter.getClass().getName());
        System.out.println("'bigint'="+typeConverter.getBigIntType());
        System.out.println("'blob'="+typeConverter.getBlobType());
        System.out.println("'boolean'="+typeConverter.getBooleanType());
        System.out.println("'char'="+typeConverter.getCharType());
        System.out.println("'clob'="+typeConverter.getClobType());
        System.out.println("'currency'="+typeConverter.getCurrencyType());
        System.out.println("'datetime'="+typeConverter.getDateTimeType());
        System.out.println("'double'="+typeConverter.getDoubleType());
        System.out.println("'float'="+typeConverter.getFloatType());
        System.out.println("'int'="+typeConverter.getIntType());
        System.out.println("'time'="+typeConverter.getTimeType());
        System.out.println("'tinyint'="+typeConverter.getTinyIntType());
        System.out.println("'uuid'="+typeConverter.getUUIDType());
        System.out.println("'varchar'="+typeConverter.getVarcharType());

        System.out.println("");
    }
}
 
開發者ID:hongliangpan,項目名稱:manydesigns.cn,代碼行數:23,代碼來源:TypeConversionReport.java


注:本文中的liquibase.database.DatabaseFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。