本文整理汇总了Java中io.dropwizard.db.DataSourceFactory.setDriverClass方法的典型用法代码示例。如果您正苦于以下问题:Java DataSourceFactory.setDriverClass方法的具体用法?Java DataSourceFactory.setDriverClass怎么用?Java DataSourceFactory.setDriverClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.dropwizard.db.DataSourceFactory
的用法示例。
在下文中一共展示了DataSourceFactory.setDriverClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例2: setupTests
import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
@Before
public void setupTests() throws IOException {
final DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass("org.h2.Driver");
dataSourceFactory.setUrl("jdbc:h2:mem:test-" + System.currentTimeMillis() + "?user=sa");
dataSourceFactory.setInitialSize(1);
final DBI dbi = new VavrDBIFactory().build(env, dataSourceFactory, "test");
try (Handle h = dbi.open()) {
h.execute("CREATE TABLE tasks (" +
"id INT PRIMARY KEY, " +
"assignee VARCHAR(255) NOT NULL, " +
"start_date TIMESTAMP, " +
"end_date TIMESTAMP, " +
"comments VARCHAR(1024) " +
")");
}
dao = dbi.onDemand(TaskDao.class);
dao.insert(100, Option.some("Name 1"), LocalDate.parse("2017-08-24"), Option.none(), Option.none());
dao.insert(200, Option.some("Name 2"), LocalDate.parse("2017-08-25"), Option.none(), Option.some("To be done"));
}
示例3: setUp
import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
environment = new Environment("test", new ObjectMapper(), Validators.newValidator(),
metricRegistry, ClassLoader.getSystemClassLoader());
DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setUrl("jdbc:h2:mem:jdbi3-test");
dataSourceFactory.setUser("sa");
dataSourceFactory.setDriverClass("org.h2.Driver");
dataSourceFactory.asSingleConnectionPool();
dbi = new JdbiFactory(new TimedAnnotationNameStrategy()).build(environment, dataSourceFactory, "h2");
dbi.useTransaction(h -> {
h.createScript(Resources.toString(Resources.getResource("schema.sql"), Charsets.UTF_8)).execute();
h.createScript(Resources.toString(Resources.getResource("data.sql"), Charsets.UTF_8)).execute();
});
dao = dbi.onDemand(GameDao.class);
for (LifeCycle lc : environment.lifecycle().getManagedObjects()) {
lc.start();
}
}
示例4: setUp
import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
@Before
public void setUp() {
//create a valid config
DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass("org.postgresql.Driver");
dataSourceFactory.setUrl("jdbc:postgresql://db.example.com/db-prod");
dataSourceFactory.setUser("user");
CassandraFactory cassandraFactory = new CassandraFactory();
cassandraFactory.setContactPoints(new String[]{"127.0.0.1"});
config.setCassandraFactory(cassandraFactory);
config.setPostgresDataSourceFactory(dataSourceFactory);
config.setHangingRepairTimeoutMins(1);
config.setRepairParallelism(RepairParallelism.DATACENTER_AWARE);
config.setRepairRunThreadCount(1);
config.setSegmentCount(1);
config.setScheduleDaysBetween(7);
config.setStorageType("foo");
config.setIncrementalRepair(false);
}
示例5: 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;
}
示例6: initializeConnection
import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
private void initializeConnection() throws SQLException {
if (connection == null) {
DataSourceFactory factory = new DataSourceFactory();
factory.setDriverClass(getDriverClass());
factory.setUrl(String.format("%s//%s/%s", getJDBCUrlPrefix(), dbUrl, dbName));
factory.setProperties(getJDBCProperties());
if (dbUser != null) {
factory.setUser(this.dbUser);
}
if (dbPassword != null) {
factory.setPassword(dbPassword);
}
source = factory.build(MacroBase.metrics, dbName);
this.connection = source.getConnection();
}
}
示例7: uses_configured_dropwizard_values
import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
@Test
public void uses_configured_dropwizard_values() {
final CamundaConfiguration configuration = new CamundaConfiguration();
final DataSourceFactory database = configuration.getCamunda().getDatabase();
database.setDriverClass(DRIVER);
database.setUser(USER);
database.setPassword(PASSWORD);
database.setUrl(URL);
final ProcessEngineConfiguration processEngineConfiguration = configuration.buildProcessEngineConfiguration();
assertThat(processEngineConfiguration.getJdbcDriver()).isEqualTo(DRIVER);
assertThat(processEngineConfiguration.getJdbcUsername()).isEqualTo(USER);
assertThat(processEngineConfiguration.getJdbcPassword()).isEqualTo(PASSWORD);
assertThat(processEngineConfiguration.getJdbcUrl()).isEqualTo(URL);
}
示例8: setupTests
import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
@Before
public void setupTests() throws IOException {
final DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass("org.h2.Driver");
dataSourceFactory.setUrl("jdbc:h2:mem:date-time-optional-" + System.currentTimeMillis() + "?user=sa");
dataSourceFactory.setInitialSize(1);
final DBI dbi = new DBIFactory().build(env, dataSourceFactory, "test");
try (Handle h = dbi.open()) {
h.execute("CREATE TABLE tasks (" +
"id INT PRIMARY KEY, " +
"assignee VARCHAR(255) NOT NULL, " +
"start_date TIMESTAMP, " +
"end_date TIMESTAMP, " +
"comments VARCHAR(1024) " +
")");
}
dao = dbi.onDemand(TaskDao.class);
}
示例9: getDataSourceFactory
import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
private DataSourceFactory getDataSourceFactory() {
DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass("org.h2.Driver");
dataSourceFactory.setUrl("jdbc:h2:mem:singularity;DB_CLOSE_DELAY=-1");
dataSourceFactory.setUser("user");
dataSourceFactory.setPassword("password");
return dataSourceFactory;
}
示例10: 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
示例11: getDataSourceFactory
import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
private DataSourceFactory getDataSourceFactory() {
DataSourceFactory dataSourceFactory = new DataSourceFactory();
dataSourceFactory.setDriverClass("org.postgresql.Driver");
dataSourceFactory.setUrl("jdbc:postgresql://localhost:5432/ft_openregister_java_multi");
dataSourceFactory.setUser("postgres");
dataSourceFactory.setPassword("");
return dataSourceFactory;
}
开发者ID:openregister,项目名称:openregister-java,代码行数:9,代码来源:PostgresRegisterTransactionalFunctionalTest.java
示例12: 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;
}
示例13: 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");
}
示例14: 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);
}
示例15: clone
import io.dropwizard.db.DataSourceFactory; //导入方法依赖的package包/类
public static DataSourceFactory clone(DataSourceFactory dbConfig) {
DataSourceFactory newConfig = new DataSourceFactory();
newConfig.setUser(dbConfig.getUser());
newConfig.setPassword(dbConfig.getPassword());
newConfig.setUrl(dbConfig.getUrl());
newConfig.setDriverClass(dbConfig.getDriverClass());
newConfig.setMaxSize(dbConfig.getMaxSize());
newConfig.setMinSize(dbConfig.getMinSize());
newConfig.setInitialSize(dbConfig.getInitialSize());
return newConfig;
}