예제 #1
0
 @Override
 public boolean update(int id, Category category) {
   try {
     Connection connection = PoolConnection.getConnection();
     try {
       connection.setAutoCommit(false);
       //                assertTransaction(cdao.update(connection, id, category));
       //                assertTransaction(chtdao.deleteByCategoryId(connection, id));
       //                for (Task task : category.getTasks()) {
       //                    assertTransaction(chtdao.insert(connection, id, task.getId()));
       //                }
       cdao.update(connection, id, category);
       chtdao.deleteByCategoryId(connection, id);
       for (Task task : category.getTasks()) {
         chtdao.insert(connection, id, task.getId());
       }
       connection.commit();
     } catch (SQLTransactionException e) {
       connection.rollback();
       return false;
     } finally {
       if (connection != null) {
         connection.setAutoCommit(true);
         connection.close();
       }
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return true;
 }
예제 #2
0
 @Override
 public boolean delete(int id) {
   try {
     Connection connection = PoolConnection.getConnection();
     try {
       connection.setAutoCommit(false);
       chtdao.deleteByCategoryId(connection, id);
       udao.deleteByCatID(connection, id);
       chpdao.deleteByCategoryId(connection, id);
       cdao.delete(connection, id);
       connection.commit();
     } catch (SQLTransactionException e) {
       connection.rollback();
       return false;
     } finally {
       if (connection != null) {
         connection.setAutoCommit(true);
         connection.close();
       }
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return true;
 }