当前位置: 首页>>代码示例>>Java>>正文


Java DataSourceFactory类代码示例

本文整理汇总了Java中io.bootique.jdbc.DataSourceFactory的典型用法代码示例。如果您正苦于以下问题:Java DataSourceFactory类的具体用法?Java DataSourceFactory怎么用?Java DataSourceFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataSourceFactory类属于io.bootique.jdbc包,在下文中一共展示了DataSourceFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCreateRealm

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
public void testCreateRealm() throws NoSuchFieldException, IllegalAccessException {

    DataSource ds = mock(DataSource.class);

    DataSourceFactory mockDSFactory = mock((DataSourceFactory.class));
    when(mockDSFactory.forName("testDS")).thenReturn(ds);

    Injector injector = mock(Injector.class);
    Mockito.when(injector.getInstance(DataSourceFactory.class)).thenReturn(mockDSFactory);


    JdbcRealmFactory factory = new JdbcRealmFactory();
    factory.setName("testName");
    factory.setDatasource("testDS");

    JdbcRealm realm = (JdbcRealm) factory.createRealm(injector);
    assertEquals("testName", realm.getName());

    Field dsField = JdbcRealm.class.getDeclaredField("dataSource");
    dsField.setAccessible(true);
    assertSame(ds, dsField.get(realm));
}
 
开发者ID:bootique,项目名称:bootique-shiro,代码行数:24,代码来源:JdbcRealmFactoryTest.java

示例2: testDerbyDataSource

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
public void testDerbyDataSource() throws SQLException {
    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPDerbyIT.yml")
            .autoLoadModules()
            .createRuntime();

    DataSource ds4 = runtime.getInstance(DataSourceFactory.class).forName("derby4");
    assertNotNull(ds4);
    assertTrue(ds4 instanceof HikariDataSource);

    HikariDataSource hikariDS = (HikariDataSource) ds4;

    assertEquals("org.apache.derby.jdbc.EmbeddedDataSource", hikariDS.getDataSourceClassName());

    HikariPool pool = (HikariPool) hikariDS.getHikariPoolMXBean();

    assertTrue(pool.getUnwrappedDataSource().getClass().isAssignableFrom(EmbeddedDataSource.class));

    try (Connection c = hikariDS.getConnection()) {
        assertEquals("jdbc:derby:target/derby4", c.getMetaData().getURL());
    }
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:23,代码来源:HikariCPDerbyIT.java

示例3: testDerbyDriverDataSource

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
public void testDerbyDriverDataSource() throws SQLException {
    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPDerbyIT.yml")
            .autoLoadModules()
            .createRuntime();

    DataSource ds5 = runtime.getInstance(DataSourceFactory.class).forName("derby5");
    assertNotNull(ds5);
    assertTrue(ds5 instanceof HikariDataSource);

    HikariDataSource hikariDS = (HikariDataSource) ds5;

    assertEquals("org.apache.derby.jdbc.EmbeddedDriver", hikariDS.getDriverClassName());

    HikariPool pool = (HikariPool) hikariDS.getHikariPoolMXBean();

    assertTrue(pool.getUnwrappedDataSource() instanceof DriverDataSource);

    try (Connection c = hikariDS.getConnection()) {
        assertEquals("jdbc:derby:", c.getMetaData().getURL());
    }
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:23,代码来源:HikariCPDerbyIT.java

示例4: testDataSource

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
public void testDataSource() {

    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPModuleIT_ds.yml")
            .autoLoadModules()
            .createRuntime();

    DataSource ds = runtime.getInstance(DataSourceFactory.class).forName("derby1");
    assertNotNull(ds);
    assertTrue(ds instanceof HikariDataSource);

    HikariDataSource hikariDS = (HikariDataSource) ds;

    assertEquals("jdbc:derby:target/derby1;create=true", hikariDS.getJdbcUrl());
    assertEquals("sa", hikariDS.getUsername());
    assertEquals(1, hikariDS.getMinimumIdle());
    assertEquals(3, hikariDS.getMaximumPoolSize());
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:19,代码来源:HikariCPModuleIT.java

示例5: testAllNames_PartialConfigsExcluded_Vars

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
@Deprecated
public void testAllNames_PartialConfigsExcluded_Vars() {

    BQRuntime runtime = testFactory.app("-c", "classpath:dummy-2ds.yml")
            .autoLoadModules()
            .module(b -> {
                BQCoreModule.extend(b)
                        .setVar("BQ_JDBC_PARTIAL_PASSWORD", "p1")
                        .setVar("BQ_JDBC_FULLDS2_PASSWORD", "p2")
                        .setVar("BQ_JDBC_FULLDSVARS_JDBCURL", "jdbc:dummy");
            })
            .createRuntime();
    DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);

    Set<String> names = new HashSet<>(factory.allNames());
    assertEquals(new HashSet<>(Arrays.asList("fullds1", "fullds2", "FULLDSVARS")), names);
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:19,代码来源:HikariCPModuleIT.java

示例6: testDataSource

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
public void testDataSource() {

    BQRuntime runtime = testFactory.app("-c", "classpath:TomcatJdbcModuleIT_full.yml")
            .autoLoadModules()
            .createRuntime();

    DataSource ds = runtime.getInstance(DataSourceFactory.class).forName("derby1");
    assertNotNull(ds);
    assertTrue(ds instanceof org.apache.tomcat.jdbc.pool.DataSource);

    org.apache.tomcat.jdbc.pool.DataSource tomcatDS = (org.apache.tomcat.jdbc.pool.DataSource) ds;

    assertEquals("jdbc:derby:target/derby1;create=true", tomcatDS.getUrl());
    assertEquals("sa", tomcatDS.getUsername());
    assertEquals(0, tomcatDS.getInitialSize());
    assertEquals(1, tomcatDS.getMinIdle());
    assertEquals(3, tomcatDS.getMaxIdle());
    assertEquals(6, tomcatDS.getMaxActive());
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:21,代码来源:TomcatJdbcModuleIT.java

示例7: testAllNames_PartialConfigsExcluded_Vars

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
@Deprecated
public void testAllNames_PartialConfigsExcluded_Vars() {

    BQRuntime runtime = testFactory.app("-c", "classpath:dummy-2ds.yml")
            .autoLoadModules()
            .module(b -> {
                BQCoreModule.extend(b)
                        .setVar("BQ_JDBC_PARTIAL_PASSWORD", "p1")
                        .setVar("BQ_JDBC_FULLDS2_PASSWORD", "p2")
                        .setVar("BQ_JDBC_FULLDSVARS_URL", "jdbc:dummy");
            })
            .createRuntime();
    DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);

    Set<String> names = new HashSet<>(factory.allNames());
    assertEquals(new HashSet<>(Arrays.asList("fullds1", "fullds2", "FULLDSVARS")), names);
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:19,代码来源:TomcatJdbcModuleIT.java

示例8: createRunner

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
public LiquibaseRunner createRunner(DataSourceFactory dataSourceFactory,
                                    Function<Collection<ResourceFactory>,
                                            Collection<ResourceFactory>> changeLogMerger,
                                    Cli cli) {
    DataSource ds = getDataSource(dataSourceFactory);

    if (changeLog != null) {

        if (changeLogs != null) {
            throw new IllegalStateException("Using both old style 'changeLog' property and new style 'changeLogs'. " +
                    "You can use either one or the other");
        }

        String asClasspath = "classpath:" + changeLog;
        LOGGER.warn("Using deprecated 'changeLog' property. " +
                "Consider switching to 'changeLogs' collection instead. " +
                "The new value will be '" + asClasspath + "'");

        return new LegacyLiquibaseRunner(changeLog, ds, cli);
    }


    Collection<ResourceFactory> allChangeLogs = changeLogMerger.apply(changeLogs);
    return new LiquibaseRunner(allChangeLogs, ds, cli);
}
 
开发者ID:bootique,项目名称:bootique-liquibase,代码行数:26,代码来源:LiquibaseFactory.java

示例9: getDataSource

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
private DataSource getDataSource(DataSourceFactory dataSourceFactory) {
    Collection<String> allNames = dataSourceFactory.allNames();

    if (datasource == null) {
        if (allNames.isEmpty()) {
            throw new IllegalStateException("No DataSources are available for Liquibase. " +
                    "Add a DataSource via 'bootique-jdbc'or 'bootique-liquibase'");
        }

        if (allNames.size() == 1) {
            return dataSourceFactory.forName(allNames.iterator().next());
        } else {
            throw new IllegalStateException(
                    String.format("Can't map Liquibase DataSource: 'liquibase.datasource' is missing. " +
                            "Available DataSources are %s", allNames));
        }
    } else {
        if (!allNames.contains(datasource)) {
            throw new IllegalStateException(
                    String.format("Can't map Liquibase DataSource: 'liquibase.datasource' is set to '%s'. " +
                            "Available DataSources: %s", datasource, allNames));
        }

        return dataSourceFactory.forName(datasource);
    }
}
 
开发者ID:bootique,项目名称:bootique-liquibase,代码行数:27,代码来源:LiquibaseFactory.java

示例10: cayenneBuilder

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
/**
 * Creates and returns a preconfigured {@link ServerRuntimeBuilder} with
 * Cayenne config, name, Java8 integration module and a DataSource. Override
 * to add custom modules, extra projects, etc.
 *
 * @param dataSourceFactory injected Bootique {@link DataSourceFactory}
 * @return a {@link ServerRuntimeBuilder} that can be extended in
 * subclasses.
 */
protected ServerRuntimeBuilder cayenneBuilder(DataSourceFactory dataSourceFactory) {

    // building our own Cayenne extensions module...
    return ServerRuntime.builder(name).addModule(binder -> {

        // provide schema creation hook
        if (createSchema) {
            binder.bind(SchemaUpdateStrategyFactory.class).toInstance(descriptor -> new CreateIfNoSchemaStrategy());
        }

        DefaultDataSourceName defaultDataSourceName = defaultDataSourceName(dataSourceFactory);
        binder.bind(Key.get(DefaultDataSourceName.class)).toInstance(defaultDataSourceName);
        binder.bindList(DataMapConfig.class).addAll(maps);

        // provide default DataNode
        // TODO: copied from Cayenne, as the corresponding provider is not public or rather
        // until https://issues.apache.org/jira/browse/CAY-2095 is implemented
        binder.bind(DataDomain.class).toProvider(SyntheticNodeDataDomainProvider.class);

        // Bootique DataSource hooks...
        BQCayenneDataSourceFactory bqCayenneDSFactory =
                new BQCayenneDataSourceFactory(dataSourceFactory, datasource, maps);
        binder.bind(org.apache.cayenne.configuration.server.DataSourceFactory.class).toInstance(bqCayenneDSFactory);
    });
}
 
开发者ID:bootique,项目名称:bootique-cayenne,代码行数:35,代码来源:ServerRuntimeFactory.java

示例11: createFactory

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
public DefaultJooqFactory createFactory(DataSourceFactory dataSourceFactory) {

        // pretty evil side effect on system properties. Wish Jooq had abstracted its properties bootstrap.
        // Still the logo has to go.
        System.setProperty("org.jooq.no-logo", "true");

        Settings defaultSettings = SettingsTools.defaultSettings();
        defaultSettings.setExecuteLogging(executeLogging);

        // TODO: guess the dialect based on the connection info - https://github.com/bootique/bootique-jooq/issues/3
        Objects.requireNonNull(dialect);

        return new DefaultJooqFactory(dataSourceFactory, dialect, defaultSettings);
    }
 
开发者ID:bootique,项目名称:bootique-jooq,代码行数:15,代码来源:DefaultJooqFactoryFactory.java

示例12: provideJooqFactory

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
@Provides
@Singleton
JooqFactory provideJooqFactory(ConfigurationFactory configurationFactory, DataSourceFactory dataSourceFactory) {
    return configurationFactory
            .config(DefaultJooqFactoryFactory.class, configPrefix)
            .createFactory(dataSourceFactory);
}
 
开发者ID:bootique,项目名称:bootique-jooq,代码行数:8,代码来源:JooqModule.java

示例13: createRealm

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
@Override
public Realm createRealm(Injector injector) {

    DataSource ds = findDataSource(injector.getInstance(DataSourceFactory.class));

    JdbcRealm realm = new JdbcRealm();

    if (name != null) {
        realm.setName(name);
    }

    realm.setDataSource(ds);
    realm.setPermissionsLookupEnabled(lookupPermissions);

    if (authenticationQuery != null) {
        realm.setAuthenticationQuery(authenticationQuery);
    }

    if (permissionsQuery != null) {
        realm.setPermissionsQuery(permissionsQuery);
    }

    if (saltStyle != null) {
        realm.setSaltStyle(saltStyle);
    }

    if(userRolesQuery != null) {
        realm.setUserRolesQuery(userRolesQuery);
    }

    return realm;
}
 
开发者ID:bootique,项目名称:bootique-shiro,代码行数:33,代码来源:JdbcRealmFactory.java

示例14: findDataSource

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
protected DataSource findDataSource(DataSourceFactory factory) {
    if (this.datasource == null) {

        Collection<String> allNames = factory.allNames();
        if (allNames.size() == 1) {
            String defaultName = allNames.iterator().next();
            LOGGER.debug("No explicit DataSource name is set, using default '{}'", defaultName);
            return factory.forName(defaultName);
        }

        throw new IllegalStateException("No explicit DataSource name is set, and no default DataSource is defined");
    }

    return factory.forName(datasource);
}
 
开发者ID:bootique,项目名称:bootique-shiro,代码行数:16,代码来源:JdbcRealmFactory.java

示例15: provideDatabaseChannelFactory

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
@Singleton
@Provides
DatabaseChannelFactory provideDatabaseChannelFactory(
        ConfigurationFactory configFactory,
        DataSourceFactory dataSourceFactory) {
    return configFactory.config(DatabaseChannelFactoryFactory.class, configPrefix).createFactory(dataSourceFactory);
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:8,代码来源:JdbcTestModule.java


注:本文中的io.bootique.jdbc.DataSourceFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。