Beispiel #1
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();
  }
 @AfterMethod(alwaysRun = true)
 public void tearDown() throws Exception {
   if (dummyHandle != null) {
     dummyHandle.close();
   }
   deleteRecursively(temporary);
 }
  private void verifyAccountEmailAuditAndHistoryCount(
      final UUID accountId, final int expectedCount) {
    final Handle handle = dbi.open();

    // verify audit
    StringBuilder sb = new StringBuilder();
    sb.append("select * from audit_log a ");
    sb.append("inner join account_email_history aeh on a.record_id = aeh.history_record_id ");
    sb.append("where a.table_name = 'account_email_history' ");
    sb.append(String.format("and aeh.account_id='%s'", accountId.toString()));
    List<Map<String, Object>> result = handle.select(sb.toString());
    assertEquals(result.size(), expectedCount);

    // ***** NOT IDEAL
    // ... but this works after the email record has been deleted; will likely fail when multiple
    // emails exist for the same account
    // verify history table
    sb = new StringBuilder();
    sb.append("select * from account_email_history aeh ");
    sb.append(String.format("where aeh.account_id='%s'", accountId.toString()));
    result = handle.select(sb.toString());
    assertEquals(result.size(), expectedCount);

    handle.close();
  }
Beispiel #4
0
 @Override
 public synchronized void unlock() {
   if (handle != null) {
     handle
         .createQuery("select release_lock(:name)")
         .bind("name", name)
         .map(IntegerMapper.FIRST)
         .first();
     handle.close();
     handle = null;
   }
 }
  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();
    }
  }
 /**
  * @param entitySqlDaoTransactionWrapper transaction to execute
  * @param <ReturnType> object type to return from the transaction
  * @return result from the transaction fo type ReturnType
  */
 public <ReturnType> ReturnType execute(
     final EntitySqlDaoTransactionWrapper<ReturnType> entitySqlDaoTransactionWrapper) {
   final Handle handle = dbi.open();
   try {
     final EntitySqlDao<EntityModelDao<Entity>, Entity> entitySqlDao =
         handle.attach(InitialEntitySqlDao.class);
     return entitySqlDao.inTransaction(
         TransactionIsolationLevel.READ_COMMITTED,
         new JdbiTransaction<ReturnType, EntityModelDao<Entity>, Entity>(
             handle, entitySqlDaoTransactionWrapper));
   } finally {
     handle.close();
   }
 }
Beispiel #7
0
 private boolean _lock(long duration, TimeUnit unit) {
   if (handle == null) {
     handle = dbi.open();
     int got_lock =
         handle
             .createQuery("select get_lock(:name, :time)")
             .bind("name", name)
             .bind("time", unit.toSeconds(duration))
             .map(IntegerMapper.FIRST)
             .first();
     if (got_lock == 1) {
       return true;
     } else {
       handle.close();
       handle = null;
       return false;
     }
   } else {
     // we already have the lock!
     return true;
   }
 }
 @AfterMethod
 public void teardown() {
   dummyHandle.close();
   FileUtils.deleteRecursively(dataDir);
 }
Beispiel #9
0
 public void tearDown() throws Exception {
   handle.execute("drop table something");
   handle.close();
 }
 @AfterMethod
 public void teardown() {
   handle.close();
 }
Beispiel #11
0
 public void close() {
   handle.close();
 }
 @After
 public void tearDown() {
   handle.createStatement("DROP TABLE " + tableName).setQueryTimeout(1).execute();
   handle.close();
 }
Beispiel #13
0
 @AfterMethod(alwaysRun = true)
 public void teardown() {
   dummyHandle.close();
 }