Exemplo n.º 1
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;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 public List<Category> getByPostId(int postId) {
   try (Connection connection = PoolConnection.getConnection()) {
     return cdao.getByPostId(connection, postId);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return null;
 }
Exemplo n.º 4
0
 public int getCountAllWithSearch(String categoryToSearch) {
   try (Connection connection = PoolConnection.getConnection()) {
     return cdao.getCountWithSearch(connection, categoryToSearch);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return 0;
 }
Exemplo n.º 5
0
 public int getCountAll() {
   try (Connection connection = PoolConnection.getConnection()) {
     return cdao.getCount(connection);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return 0;
 }
Exemplo n.º 6
0
 public List<Category> getAllWithSearchLimited(String nameToSearch, int start, int ammount) {
   try (Connection connection = PoolConnection.getConnection()) {
     return cdao.getAllWithSearchLimited(connection, nameToSearch, start, ammount);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return null;
 }
Exemplo n.º 7
0
 @Override
 public Category getById(int id) {
   try (Connection connection = PoolConnection.getConnection()) {
     return cdao.getById(connection, id);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return null;
 }
Exemplo n.º 8
0
 @Override
 public List<Category> getAll() {
   try (Connection connection = PoolConnection.getConnection()) {
     return cdao.getAll(connection);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return null;
 }