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


Java DBI.open方法代碼示例

本文整理匯總了Java中org.skife.jdbi.v2.DBI.open方法的典型用法代碼示例。如果您正苦於以下問題:Java DBI.open方法的具體用法?Java DBI.open怎麽用?Java DBI.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.skife.jdbi.v2.DBI的用法示例。


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

示例1: AnetObjectEngine

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
public AnetObjectEngine(DBI jdbi) { 
	dbHandle = jdbi.open();
	
	personDao = new PersonDao(dbHandle);
	poamDao = new PoamDao(dbHandle);
	locationDao =  new LocationDao(dbHandle);
	orgDao = new OrganizationDao(dbHandle);
	positionDao = new PositionDao(dbHandle);
	asDao = new ApprovalStepDao(dbHandle);
	approvalActionDao = new ApprovalActionDao(dbHandle);
	reportDao = new ReportDao(dbHandle);
	commentDao = new CommentDao(dbHandle);
	adminDao = new AdminDao(dbHandle);
	savedSearchDao = new SavedSearchDao(dbHandle);
	
	instance = this;
	
	//TODO: maybe do this differently!
	if (DaoUtils.isMsSql(dbHandle)) { 
		searcher = new MssqlSearcher();
	} else { 
		searcher = new SqliteSearcher();
	}
}
 
開發者ID:deptofdefense,項目名稱:anet,代碼行數:25,代碼來源:AnetObjectEngine.java

示例2: setupTests

import org.skife.jdbi.v2.DBI; //導入方法依賴的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"));
}
 
開發者ID:dropwizard,項目名稱:dropwizard-vavr,代碼行數:22,代碼來源:VavrDBIFactoryTest.java

示例3: test

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
@Test
public void test() throws Exception {
  DBI dbi = new DBI(ds.getDataSource());

  try (Handle h = dbi.open()) {
    h.execute("create table contacts (id int primary key, name varchar(100))");

    h.execute("insert into contacts (id, name) values (?, ?)", 1, "Alice");
    h.execute("insert into contacts (id, name) values (?, ?)", 2, "Bob");

    List<String> names = h.createQuery("select name from contacts order by id")
        .mapTo(String.class)
        .list();
    assertThat(names)
        .containsExactly("Alice", "Bob");

    String name = h.createQuery("select name from contacts where id = :id")
        .bind("id", 1)
        .mapTo(String.class)
        .first();
    assertThat(name)
        .isEqualTo("Alice");

  }
}
 
開發者ID:qualidafial,項目名稱:jdbi-examples,代碼行數:26,代碼來源:Example01FluentApi.java

示例4: setupDatabase

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
@BeforeMethod
public void setupDatabase()
        throws Exception
{
    TypeRegistry typeRegistry = new TypeRegistry();
    dbi = new DBI("jdbc:h2:mem:test" + System.nanoTime());
    dbi.registerMapper(new TableColumn.Mapper(typeRegistry));
    dummyHandle = dbi.open();
    createTablesWithRetry(dbi);

    RaptorConnectorId connectorId = new RaptorConnectorId("raptor");
    InMemoryNodeManager nodeManager = new InMemoryNodeManager();
    nodeManager.addCurrentNodeDatasource(connectorId.toString());
    NodeSupplier nodeSupplier = new RaptorNodeSupplier(nodeManager, connectorId);
    shardManager = new DatabaseShardManager(dbi, nodeSupplier);
    metadata = new RaptorMetadata(connectorId.toString(), dbi, shardManager, SHARD_INFO_CODEC, SHARD_DELTA_CODEC);
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:18,代碼來源:TestRaptorMetadata.java

示例5: initialize

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
/**
 * データベースの初期化
 */
public static void initialize() {
	log.info("database initialize.");

	ds.set(createConnection());
	final DBI dbi = new DBI(ds.get());

	final RelationQueries relation = dbi.open(RelationQueries.class);
	relation.createRelationTable();
	relation.close();

	final BeginWord beginWord = dbi.open(BeginWord.class);
	beginWord.createBeginWordTable();
	beginWord.close();

	log.info("database initialized.");
}
 
開發者ID:chory-amam,項目名稱:slack-capybara,代碼行數:20,代碼來源:Database.java

示例6: before

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
@Before
public void before() throws IOException {
    tempLocation = Files.createTempDirectory("jpagen").toFile();
    System.out.println(tempLocation.getAbsolutePath());


    com.mysql.jdbc.jdbc2.optional.MysqlDataSource ds
            = new MysqlDataSource();
    ds.setUrl("jdbc:mysql://localhost/devopsplus");
    ds.setUser("devopsplus");
    ds.setPassword("devopsplus");
    DBI dbi = new DBI(ds);
    Handle handle = dbi.open();

    config = Configuration.fromStream(getClass().getResourceAsStream("/test-2.json"));
    reflector = new ReflectorMySql(config, handle);
}
 
開發者ID:realrunner,項目名稱:jpa-gen,代碼行數:18,代碼來源:GeneratorTestLocal.java

示例7: setupTests

import org.skife.jdbi.v2.DBI; //導入方法依賴的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);
}
 
開發者ID:dropwizard,項目名稱:dropwizard-java8,代碼行數:19,代碼來源:JDBIOptionalLocalDateTimeTest.java

示例8: getUserViaFacebook

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
public Optional<UserBean> getUserViaFacebook(String userId) {
	UserBean userBean = null;

	DBI dbConn;
	try {
		dbConn = DataSourceHandler.getInstance().getDataSource(
				JDBISetting.IMG_CONNECTION_SERVICE);
		UserJDBI userJDBI = dbConn.open(UserJDBI.class);
		userBean = userJDBI.selectViaFacebookId(userId);
		userJDBI.close();
		
	} catch (ExecutionException e) {
		log.error("Unable to retrieve user info via gmail", e);
	}

	return Optional.fromNullable(userBean);
}
 
開發者ID:yoonghan,項目名稱:selfservicedb,代碼行數:18,代碼來源:UserDAO.java

示例9: shouldFindSubAlarmMetricDefinitions

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
@Test(groups = "database")
public void shouldFindSubAlarmMetricDefinitions() {
  // This test won't work without the real mysql database so use mini-mon.
  // Warning, this will truncate your mini-mon database
  db = new DBI("jdbc:mysql://192.168.10.4/mon", "monapi", "password");
  handle = db.open();
  repo = new AlarmDefinitionMySqlRepoImpl(db, new PersistUtils());
  beforeMethod();

  assertEquals(
      repo.findSubAlarmMetricDefinitions("123").get("111"),
      new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
          .put("flavor_id", "777").put("image_id", "888").put("metric_name", "cpu")
          .put("device", "1").build()));

  assertEquals(
      repo.findSubAlarmMetricDefinitions("234").get("222"),
      new MetricDefinition("hpcs.compute", ImmutableMap.<String, String>builder()
          .put("flavor_id", "777").put("image_id", "888").put("metric_name", "mem").build()));

  assertTrue(repo.findSubAlarmMetricDefinitions("asdfasdf").isEmpty());
}
 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:23,代碼來源:AlarmDefinitionMySqlRepositoryImplTest.java

示例10: createTables

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
/**
 * execute the schemaCreationScript using JDBI library.
 */
public void createTables() {
	final DBI dbi = LocalRegistry.getDbi();
	final Handle handle = dbi.open();
	try {
		handle.execute(this.schemaCreationScript);
	} finally {
		handle.close();
	}
}
 
開發者ID:kiswanij,項目名稱:jk-drop-wizard-full-example,代碼行數:13,代碼來源:SchemaBuilder.java

示例11: dropTables

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
/**
 * execute the schemaDroppScript using JDBI library.
 */
public void dropTables() {
	final DBI dbi = LocalRegistry.getDbi();
	final Handle handle = dbi.open();
	try {
		handle.execute(this.schemaDroppScript);
	} finally {
		handle.close();
	}
}
 
開發者ID:kiswanij,項目名稱:jk-drop-wizard-full-example,代碼行數:13,代碼來源:SchemaBuilder.java

示例12: migrate

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
@Override
public void migrate(Connection connection) throws Exception {
	TempDataSource ds = new TempDataSource(connection);
	DBI dbi = new DBI(ds);
	dbi.registerContainerFactory(new OptionalContainerFactory());
	Handle handle = dbi.open();
	
	PostgresDataAccessLayer dataAccessLayer = new PostgresDataAccessLayer(
			handle.attach(EntryQueryDAO.class),
			handle.attach(IndexDAO.class),
			handle.attach(IndexQueryDAO.class),
			handle.attach(EntryDAO.class),
			handle.attach(EntryItemDAO.class),
			handle.attach(ItemQueryDAO.class),
			handle.attach(ItemDAO.class),
			connection.getSchema(),
			new IndexDriver(),
			ImmutableMap.of(EntryType.user, Arrays.asList(new LatestByKeyIndexFunction(IndexNames.RECORD))));

	IndexDriver indexDriver = new IndexDriver();

	Map<String, Entry> entries = new HashMap<>();
	int currentIndexEntryNumber = 0;

	dataAccessLayer.getEntryIterator().forEachRemaining(entry -> {
		indexDriver.indexEntry(dataAccessLayer, entry, new LatestByKeyIndexFunction(IndexNames.RECORD), entries, currentIndexEntryNumber);
	});
	
	dataAccessLayer.checkpoint();
}
 
開發者ID:openregister,項目名稱:openregister-java,代碼行數:31,代碼來源:R__11_Migrate_current_keys_to_index.java

示例13: handleFor

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
/**
 * provides a DBI Handle for the given register
 * the handle will automatically be closed by the RegisterRule
 */
public Handle handleFor(TestRegister register) {
    DBI dbi = new DBI(register.getDatabaseConnectionString("RegisterRule"));
    
    dbi.registerContainerFactory(new OptionalContainerFactory());
    Handle handle = dbi.open();
    handles.add(handle);
    return handle;
}
 
開發者ID:openregister,項目名稱:openregister-java,代碼行數:13,代碼來源:RegisterRule.java

示例14: setup

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
@Before
public void setup() {
    MDC.put("register", schema);
    dbi = new DBI(address.getDatabaseConnectionString("PGRegisterTxnFT"));
    dbi.registerContainerFactory(new OptionalContainerFactory());
    handle = dbi.open();
    dao = handle.attach(IndexQueryDAO.class);
}
 
開發者ID:openregister,項目名稱:openregister-java,代碼行數:9,代碼來源:IndexQueryDaoIntegrationTest.java

示例15: test

import org.skife.jdbi.v2.DBI; //導入方法依賴的package包/類
@Test
public void test() throws Exception {
  DBI dbi = new DBI(ds.getDataSource());
  dbi.registerMapper(new BeanMapperFactory());
  dbi.registerColumnMapper(new MoneyMapper());
  dbi.registerArgumentFactory(new MoneyArgumentFactory());

  try (Handle h = dbi.open()) {
    Money tenDollars = Money.of(USD, 10);
    Money fiveDollars = Money.of(USD, 5);

    h.execute("create table accounts (id int primary key, name varchar(100), balance decimal)");

    h.execute("insert into accounts (id, name, balance) values (?, ?, ?)", 1, "Alice", tenDollars);
    h.execute("insert into accounts (id, name, balance) values (?, ?, ?)", 2, "Bob", fiveDollars);

    List<Account> list = h.createQuery("select * from accounts order by id")
        .mapTo(Account.class)
        .list();
    assertThat(list)
        .extracting(Account::getId, Account::getName, Account::getBalance)
        .containsExactly(tuple(1, "Alice", tenDollars),
                         tuple(2, "Bob", fiveDollars));

    Account bob = h.createQuery("select * from accounts where id = :id")
        .bind("id", 2)
        .mapTo(Account.class)
        .first();
    assertThat(bob)
        .extracting(Account::getId, Account::getName, Account::getBalance)
        .containsExactly(2, "Bob", fiveDollars);
  }
}
 
開發者ID:qualidafial,項目名稱:jdbi-examples,代碼行數:34,代碼來源:Example04ColumnMapper.java


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