• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DataSourceFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testMetrics

import io.bootique.jdbc.DataSourceFactory; //导入依赖的package包/类
@Test
public void testMetrics() {
    BQRuntime runtime = TEST_FACTORY.app("-c", "classpath:io/bootique/jdbc/instrumented/dummy-ds.yml")
            .autoLoadModules()
            .createRuntime();

    DataSourceFactory factory = runtime.getInstance(DataSourceFactory.class);

    DataSource dataSource = factory.forName("DerbyDatabaseIT");
    assertNotNull(dataSource);

    MetricRegistry metricRegistry = runtime.getInstance(MetricRegistry.class);
    assertNotEquals(metricRegistry.getGauges().size(), 0);
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:15,代码来源:TomcatInstrumentedJdbcModuleIT.java


示例17: testDerbyDataSource_ConnectionAttributes

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

    DataSource ds6 = runtime.getInstance(DataSourceFactory.class).forName("derby6");
    assertNotNull(ds6);

    HikariDataSource hikariDS = (HikariDataSource) ds6;

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


示例18: testDerbyDriver_ConnectionAttributes

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

    DataSource ds7 = runtime.getInstance(DataSourceFactory.class).forName("derby7");
    assertNotNull(ds7);

    HikariDataSource hikariDS = (HikariDataSource) ds7;

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


示例19: testDataSource_DriverAutoDetected

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

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

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

    try (Connection c = ds.getConnection()) {
        assertTrue(c.getMetaData().getDriverName().toLowerCase().contains("derby"));
    }
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:16,代码来源:HikariCPModuleIT.java


示例20: testDataSource_TypeAutoDetected

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

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

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

    HikariDataSource hikariDS = (HikariDataSource) ds;

    assertEquals("jdbc:derby:target/derby3;create=true", hikariDS.getJdbcUrl());
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:16,代码来源:HikariCPModuleIT.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SchemaCrawlerException类代码示例发布时间:2022-05-23
下一篇:
Java PDOutlineItem类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap