public void testDeleteWithExpectedResultSizeOnCobarSqlMapClientTemplate() {
    Follower f = new Follower("fname");
    getSqlMapClientTemplate().insert("com.alibaba.cobar.client.entities.Follower.create", f);

    String confirmSQL = "select name from followers where name='fname'";
    verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt1m);
    verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt1s);
    verifyEntityExistenceOnSpecificDataSource(confirmSQL, jt2m);
    verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt2s);

    try {
      getSqlMapClientTemplate()
          .delete("com.alibaba.cobar.client.entities.Follower.deleteByName", f, 2);
      fail("only one row will be affected in fact.");
    } catch (DataAccessException e) {
      assertTrue(e instanceof JdbcUpdateAffectedIncorrectNumberOfRowsException);
      JdbcUpdateAffectedIncorrectNumberOfRowsException ex =
          (JdbcUpdateAffectedIncorrectNumberOfRowsException) e;
      assertEquals(1, ex.getActualRowsAffected());
    }
    // although JdbcUpdateAffectedIncorrectNumberOfRowsException is raised, but the delete does
    // performed successfully.
    verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt1m);
    verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt1s);
    verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt2m);
    verifyEntityNonExistenceOnSpecificDataSource(confirmSQL, jt2s);

    try {
      getSqlMapClientTemplate()
          .delete("com.alibaba.cobar.client.entities.Follower.deleteByName", f, 0);
    } catch (DataAccessException e) {
      fail();
    }
  }
コード例 #2
0
 public void testDeleteWithRequiredRowsAffectedAndInvalidRowCount() throws SQLException {
   TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
   template.executor.delete("myStatement", "myParameter");
   template.executorControl.setReturnValue(20, 1);
   template.executorControl.replay();
   try {
     template.delete("myStatement", "myParameter", 10);
     fail("Should have thrown JdbcUpdateAffectedIncorrectNumberOfRowsException");
   } catch (JdbcUpdateAffectedIncorrectNumberOfRowsException ex) {
     // expected
     assertEquals(10, ex.getExpectedRowsAffected());
     assertEquals(20, ex.getActualRowsAffected());
   }
   template.executorControl.verify();
 }