Ejemplo n.º 1
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()));
  }
Ejemplo n.º 2
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();
  }
Ejemplo n.º 3
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))");
  }
Ejemplo n.º 4
0
  @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))");
  }
Ejemplo n.º 6
0
 public void tearDown() throws Exception {
   handle.execute("drop table something");
   handle.close();
 }