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


Java DataSourceFactory.setValidationQuery方法代码示例

本文整理汇总了Java中io.dropwizard.db.DataSourceFactory.setValidationQuery方法的典型用法代码示例。如果您正苦于以下问题:Java DataSourceFactory.setValidationQuery方法的具体用法?Java DataSourceFactory.setValidationQuery怎么用?Java DataSourceFactory.setValidationQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.dropwizard.db.DataSourceFactory的用法示例。


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

示例1: setup

import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
@Before
public void setup() throws Exception
{
    DBIFactory factory = new DBIFactory();
    Environment environment = new Environment("test", new ObjectMapper(), null, new MetricRegistry(), ClassLoader.getSystemClassLoader());
    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setUrl("jdbc:hsqldb:mem:soa-jdbi;shutdown=true");
    dataSourceFactory.setDriverClass("org.hsqldb.jdbc.JDBCDriver");
    dataSourceFactory.setLogValidationErrors(true);
    dataSourceFactory.setUser("SA");
    dataSourceFactory.setValidationQuery("SELECT * FROM INFORMATION_SCHEMA.SYSTEM_TABLES");
    DBI jdbi = factory.build(environment, dataSourceFactory, "test");
    dynamicAttributes = new JdbiDynamicAttributes(jdbi, Collections.singletonList("test"));

    dynamicAttributes.getDao().createTable();
    dynamicAttributes.start();
}
 
开发者ID:soabase,项目名称:soabase,代码行数:18,代码来源:TestJdbiDynamicAttributes.java

示例2: configureDataSourceFactory

import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
private DataSourceFactory configureDataSourceFactory(MappedJsonConfiguration configuration) {
    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    DatabaseType databaseType = configuration.getDatabaseConfiguration().getDbms();
    String connectionString = configuration.getDatabaseConfiguration().getConnection();

    if (!StringUtils.startsWithIgnoreCase(connectionString, databaseType.getConnectionPrefix())) {
        String msg = String.format("Invalid database connection URL: \"%s\" - must start with \"%s\"", connectionString, databaseType.getConnectionPrefix());
        LOGGER.error(msg);
        throw new MetadictRuntimeException(msg);
    }

    dataSourceFactory.setDriverClass(databaseType.getJdbcDriver());
    dataSourceFactory.setUrl(configuration.getDatabaseConfiguration().getConnection());
    dataSourceFactory.setValidationQuery(VALIDATION_QUERY_COMMENT + databaseType.getValidationQuery());

    LOGGER.info("Configured new DataSourceFactory of type {} to {}", databaseType, connectionString);

    return dataSourceFactory;
}
 
开发者ID:jhendess,项目名称:metadict,代码行数:20,代码来源:DatabaseBundle.java

示例3: setUp

import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    final Environment environment = mock(Environment.class);
    when(environment.lifecycle()).thenReturn(mock(LifecycleEnvironment.class));
    when(environment.metrics()).thenReturn(new MetricRegistry());

    when(this.bundle.getSessionHolders()).thenReturn(this.sessionHolders);

    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setUrl("jdbc:hsqldb:mem:unit-of-work-" + UUID.randomUUID().toString());
    dataSourceFactory.setUser("sa");
    dataSourceFactory.setDriverClass("org.hsqldb.jdbcDriver");
    dataSourceFactory.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");
    dataSourceFactory.setProperties(ImmutableMap.of("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"));
    dataSourceFactory.setMinSize(1);

    this.sessionFactory = new SessionFactoryFactory()
            .build(this.bundle, environment, dataSourceFactory, ImmutableList.<Class<?>>of(), RemoteCredentialHibernateBundle.DEFAULT_NAME);
    when(this.bundle.getSessionFactory()).thenReturn(this.sessionFactory);
    final Session session = this.sessionFactory.openSession();
    try {
        session.createSQLQuery("create table user_sessions (token varchar(64) primary key, username varchar(16))")
                .executeUpdate();
        session.createSQLQuery("insert into user_sessions values ('67ab89d', 'jeff_28')")
                .executeUpdate();
    } finally {
        session.close();
    }
}
 
开发者ID:mtakaki,项目名称:CredentialStorageService-dw-hibernate,代码行数:30,代码来源:UnitOfWorkAwareProxyFactoryTest.java

示例4: createConfig

import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
private DataSourceFactory createConfig(String dbName) {
    Map<String, String> properties = Maps.newHashMap();
    properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    properties.put("hibernate.hbm2ddl.auto", "create");

    DataSourceFactory shard = new DataSourceFactory();
    shard.setDriverClass("org.h2.Driver");
    shard.setUrl("jdbc:h2:mem:" + dbName);
    shard.setValidationQuery("select 1");
    shard.setProperties(properties);

    return shard;
}
 
开发者ID:santanusinha,项目名称:dropwizard-db-sharding-bundle,代码行数:14,代码来源:DBShardingBundleBaseTest.java

示例5: setUp

import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    when(bundle.name()).thenReturn(getClass().getSimpleName() + "-bundle");
    when(environment.metrics()).thenReturn(metricRegistry);
    when(environment.lifecycle()).thenReturn(lifecycleEnvironment);

    config = new DataSourceFactory();
    config.setUrl("jdbc:hsqldb:mem:DbTest-" + System.currentTimeMillis());
    config.setUser("sa");
    config.setDriverClass("org.hsqldb.jdbcDriver");
    config.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");
}
 
开发者ID:scottescue,项目名称:dropwizard-entitymanager,代码行数:13,代码来源:EntityManagerFactoryFactoryTest.java

示例6: setUp

import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
    final EntityManagerBundle<?> bundle = mock(EntityManagerBundle.class);
    final Environment environment = mock(Environment.class);
    when(bundle.name()).thenReturn("test-bundle");
    when(environment.lifecycle()).thenReturn(mock(LifecycleEnvironment.class));
    when(environment.metrics()).thenReturn(new MetricRegistry());

    final DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setUrl("jdbc:hsqldb:mem:unit-of-work-" + UUID.randomUUID().toString());
    dataSourceFactory.setUser("sa");
    dataSourceFactory.setDriverClass("org.hsqldb.jdbcDriver");
    dataSourceFactory.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");
    dataSourceFactory.setProperties(ImmutableMap.of("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"));
    dataSourceFactory.setInitialSize(1);
    dataSourceFactory.setMinSize(1);

    entityManagerFactory = new EntityManagerFactoryFactory()
            .build(bundle, environment, dataSourceFactory, ImmutableList.<Class<?>>of());

    final EntityManager entityManager = entityManagerFactory.createEntityManager();
    try {
        EntityTransaction entityTransaction = entityManager.getTransaction();
        entityTransaction.begin();

        entityManager.createNativeQuery("create table user_sessions (token varchar(64) primary key, username varchar(16))")
                .executeUpdate();
        entityManager.createNativeQuery("insert into user_sessions values ('67ab89d', 'jeff_28')")
                .executeUpdate();

        entityTransaction.commit();
    } finally {
        entityManager.close();
    }

    final EntityManagerContext entityManagerContext = new EntityManagerContext(entityManagerFactory);
    sharedEntityManager = new SharedEntityManagerFactory().build(entityManagerContext);
}
 
开发者ID:scottescue,项目名称:dropwizard-entitymanager,代码行数:39,代码来源:UnitOfWorkAwareProxyFactoryTest.java

示例7: configure

import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
@Override
protected Application configure() {
    this.forceSet(TestProperties.CONTAINER_PORT, "0");

    final MetricRegistry metricRegistry = new MetricRegistry();
    final SessionFactoryFactory factory = new SessionFactoryFactory();
    final DataSourceFactory dbConfig = new DataSourceFactory();
    this.bundle = mock(RemoteCredentialHibernateBundle.class);

    final SessionHolders sessionHolders = mock(SessionHolders.class);
    when(this.bundle.getSessionHolders()).thenReturn(sessionHolders);

    final Environment environment = mock(Environment.class);
    final LifecycleEnvironment lifecycleEnvironment = mock(LifecycleEnvironment.class);
    when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
    when(environment.metrics()).thenReturn(metricRegistry);

    dbConfig.setUrl("jdbc:hsqldb:mem:DbTest-" + System.nanoTime()
            + "?hsqldb.translate_dti_types=false");
    dbConfig.setUser("sa");
    dbConfig.setDriverClass("org.hsqldb.jdbcDriver");
    dbConfig.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");

    this.sessionFactory = factory.build(this.bundle,
            environment,
            dbConfig,
            ImmutableList.<Class<?>> of(Person.class),
            RemoteCredentialHibernateBundle.DEFAULT_NAME);
    when(this.bundle.getSessionFactory()).thenReturn(this.sessionFactory);
    when(this.bundle.getCurrentThreadSessionFactory()).thenReturn(this.sessionFactory);

    final Session session = this.sessionFactory.openSession();
    try {
        session.createSQLQuery("DROP TABLE people IF EXISTS").executeUpdate();
        session.createSQLQuery(
                "CREATE TABLE people (name varchar(100) primary key, email varchar(16), birthday timestamp with time zone)")
                .executeUpdate();
        session.createSQLQuery(
                "INSERT INTO people VALUES ('Coda', '[email protected]', '1979-01-02 00:22:00+0:00')")
                .executeUpdate();
    } finally {
        session.close();
    }

    final DropwizardResourceConfig config = DropwizardResourceConfig
            .forTesting(new MetricRegistry());
    config.register(new UnitOfWorkApplicationListener("hr-db", this.bundle));
    config.register(new PersonResource(new PersonDAO(this.bundle)));
    config.register(new JacksonMessageBodyProvider(Jackson.newObjectMapper(),
            Validators.newValidator()));
    config.register(new DataExceptionMapper());

    return config;
}
 
开发者ID:mtakaki,项目名称:CredentialStorageService-dw-hibernate,代码行数:55,代码来源:JerseyIntegrationTest.java

示例8: configure

import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
@Override
protected Application configure() {
    final MetricRegistry metricRegistry = new MetricRegistry();
    final DataSourceFactory dbConfig = new DataSourceFactory();
    final Environment environment = mock(Environment.class);
    final LifecycleEnvironment lifecycleEnvironment = mock(LifecycleEnvironment.class);
    when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
    when(environment.metrics()).thenReturn(metricRegistry);

    String url = "jdbc:hsqldb:mem:dwtest" + System.nanoTime();

    Map<String, String> props = new HashMap<String, String>();
    props.put("username", "sa");
    props.put("password", "");
    props.put("url", url);

    try {
        HSQLDBInit.initPublic(props);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    dbConfig.setUrl(props.get("url"));
    dbConfig.setUser(props.get("user"));
    dbConfig.setDriverClass("org.hsqldb.jdbcDriver");
    dbConfig.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");

    final DropwizardResourceConfig config = DropwizardResourceConfig.forTesting(new MetricRegistry());

    DataSource dataSource = dbConfig.build(metricRegistry, "jooq");
    config.register(JooqTransactionalApplicationListener.class);

    Configuration configuration = new DefaultConfiguration().set(SQLDialect.HSQLDB);
    configuration.set(new DataSourceConnectionProvider(dataSource));

    config.register(new ConfigurationFactoryProvider.Binder(configuration, dataSource,
            new TestTenantConnectionProvider(dbConfig, metricRegistry, url)));
    config.register(ExampleResource.class);
    config.register(new JacksonMessageBodyProvider(Jackson.newObjectMapper(),
            Validation.buildDefaultValidatorFactory().getValidator()));
    return config;
}
 
开发者ID:tbugrara,项目名称:dropwizard-jooq,代码行数:43,代码来源:ExampleResourceTest.java


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