Exemplo n.º 1
0
  public void setUp() throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test;MVCC=TRUE");
    dbi = new DBI(ds);
    handle = dbi.open();

    handle.execute("create table something (id int primary key, name varchar(100))");
  }
  @Before
  public void setUp() throws Exception {
    UUID uuid = UUID.randomUUID();
    dbi = new DBI("jdbc:h2:mem:" + uuid);
    handle = dbi.open();

    handle.execute("create table something (id int primary key, name varchar(100))");
  }
  @Before
  public void setUp() throws Exception {
    dbi = new DBI("jdbc:h2:mem:" + UUID.randomUUID());
    dbi.registerMapper(new SomethingMapper());
    handle = dbi.open();

    handle.execute("create table something (id int primary key, name varchar(100))");
  }
Exemplo n.º 4
0
  @BeforeMethod
  public void setup() throws Exception {
    H2EmbeddedDataSourceConfig dataSourceConfig =
        new H2EmbeddedDataSourceConfig().setFilename("mem:");
    DataSource dataSource = new H2EmbeddedDataSource(dataSourceConfig);
    DBI h2Dbi = new DBI(dataSource);
    handle = h2Dbi.open();
    dao = handle.attach(ShardManagerDao.class);

    ShardManagerDao.Utils.createShardTablesWithRetry(dao);
  }
Exemplo n.º 5
0
  @Ignore
  @Test
  public void testGetGeneratedKeys() throws Exception {
    DAO dao = dbi.open(DAO.class);

    Long fooId = dao.insert("Foo");
    long barId = dao.insert("Bar");

    assertThat(dao.findNameById(fooId), equalTo("Foo"));
    assertThat(dao.findNameById(barId), equalTo("Bar"));
  }
Exemplo n.º 6
0
  public H2QueryRunner() {
    handle = DBI.open("jdbc:h2:mem:test" + System.nanoTime());
    TpchMetadata tpchMetadata = new TpchMetadata("");

    handle.execute(
        "CREATE TABLE orders (\n"
            + "  orderkey BIGINT PRIMARY KEY,\n"
            + "  custkey BIGINT NOT NULL,\n"
            + "  orderstatus CHAR(1) NOT NULL,\n"
            + "  totalprice DOUBLE NOT NULL,\n"
            + "  orderdate DATE NOT NULL,\n"
            + "  orderpriority CHAR(15) NOT NULL,\n"
            + "  clerk CHAR(15) NOT NULL,\n"
            + "  shippriority BIGINT NOT NULL,\n"
            + "  comment VARCHAR(79) NOT NULL\n"
            + ")");
    handle.execute("CREATE INDEX custkey_index ON orders (custkey)");
    TpchTableHandle ordersHandle =
        tpchMetadata.getTableHandle(
            null, new SchemaTableName(TINY_SCHEMA_NAME, ORDERS.getTableName()));
    insertRows(
        tpchMetadata.getTableMetadata(ordersHandle),
        handle,
        createTpchRecordSet(ORDERS, ordersHandle.getScaleFactor()));

    handle.execute(
        "CREATE TABLE lineitem (\n"
            + "  orderkey BIGINT,\n"
            + "  partkey BIGINT NOT NULL,\n"
            + "  suppkey BIGINT NOT NULL,\n"
            + "  linenumber BIGINT,\n"
            + "  quantity BIGINT NOT NULL,\n"
            + "  extendedprice DOUBLE NOT NULL,\n"
            + "  discount DOUBLE NOT NULL,\n"
            + "  tax DOUBLE NOT NULL,\n"
            + "  returnflag CHAR(1) NOT NULL,\n"
            + "  linestatus CHAR(1) NOT NULL,\n"
            + "  shipdate DATE NOT NULL,\n"
            + "  commitdate DATE NOT NULL,\n"
            + "  receiptdate DATE NOT NULL,\n"
            + "  shipinstruct VARCHAR(25) NOT NULL,\n"
            + "  shipmode VARCHAR(10) NOT NULL,\n"
            + "  comment VARCHAR(44) NOT NULL,\n"
            + "  PRIMARY KEY (orderkey, linenumber)"
            + ")");
    TpchTableHandle lineItemHandle =
        tpchMetadata.getTableHandle(
            null, new SchemaTableName(TINY_SCHEMA_NAME, LINE_ITEM.getTableName()));
    insertRows(
        tpchMetadata.getTableMetadata(lineItemHandle),
        handle,
        createTpchRecordSet(LINE_ITEM, lineItemHandle.getScaleFactor()));
  }
Exemplo n.º 7
0
  public boolean insert(Template template) {
    if (template == null) {
      return false;
    }

    Handle handle = dbi.open();
    try {
      TemplateDao db = handle.attach(TemplateDao.class);
      return db.insertBean(template) > 0;
    } finally {
      handle.close();
    }
  }
  @Test
  public void testTxActuallyCommits() throws Exception {
    Handle h2 = dbi.open();
    Dao one = handle.attach(Dao.class);
    Dao two = h2.attach(Dao.class);

    // insert in @Transaction method
    Something inserted = one.insertAndFetch(1, "Brian");

    // fetch from another connection
    Something fetched = two.findById(1);
    assertThat(fetched, equalTo(inserted));
  }
Exemplo n.º 9
0
  public void testJustJdbiTransactions() throws Exception {
    Handle h1 = dbi.open();
    Handle h2 = dbi.open();

    h1.execute("insert into something (id, name) values (8, 'Mike')");

    h1.begin();
    h1.execute("update something set name = 'Miker' where id = 8");

    assertEquals(
        "Mike",
        h2.createQuery("select name from something where id = 8").map(StringMapper.FIRST).first());
    h1.commit();
    h1.close();
    h2.close();
  }