From 1cba4569e9cad8d94933e9b4860582a4742519ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 15 Apr 2017 23:02:15 +0200 Subject: java : MyMyBatis remove useless commit param to DAOOperations --- java/MyMyBatis/src/AbstractDAO.java | 15 ++++++++------- java/MyMyBatis/src/AbstractDAOOperations.java | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/java/MyMyBatis/src/AbstractDAO.java b/java/MyMyBatis/src/AbstractDAO.java index 142b69f..22b4dce 100644 --- a/java/MyMyBatis/src/AbstractDAO.java +++ b/java/MyMyBatis/src/AbstractDAO.java @@ -26,7 +26,12 @@ public abstract class AbstractDAO public TRet call(TMapper m); } - protected int execInt(boolean commit, CallBack cb) + protected int execInt(CallBack cb) + { + return execInt(cb, false); + } + + protected int execInt(CallBack cb, boolean commit) { int status = DAO_ERROR; SqlSession session = conn.openSqlSession(); @@ -42,32 +47,28 @@ public abstract class AbstractDAO return status; } - protected TObject execObject(boolean commit, CallBack cb) + protected TObject execObject(CallBack cb) { TObject obj = null; SqlSession session = conn.openSqlSession(); try { obj = cb.call(session.getMapper(mapperClass)); - if (commit) session.commit(); } catch(PersistenceException e) { - if (commit) session.rollback(); if (logErrors) conn.error(e); } finally { session.close(); } return obj; } - protected List execObjects(boolean commit, CallBack, TMapper> cb) + protected List execObjects(CallBack, TMapper> cb) { List list = null; SqlSession session = conn.openSqlSession(); try { list = cb.call(session.getMapper(mapperClass)); - if (commit) session.commit(); } catch(PersistenceException e) { - if (commit) session.rollback(); if (logErrors) conn.error(e); } finally { session.close(); } diff --git a/java/MyMyBatis/src/AbstractDAOOperations.java b/java/MyMyBatis/src/AbstractDAOOperations.java index 6fcd6e4..5307641 100644 --- a/java/MyMyBatis/src/AbstractDAOOperations.java +++ b/java/MyMyBatis/src/AbstractDAOOperations.java @@ -7,31 +7,31 @@ public abstract class AbstractDAOOperations m.insert(obj)); + return execInt(m -> m.insert(obj), true); } public int update(final TObject obj) { - return execInt(true, m -> m.update(obj)); + return execInt(m -> m.update(obj), true); } public int delete(final TObject obj) { - return execInt(true, m -> m.delete(obj)); + return execInt(m -> m.delete(obj), true); } public int count() { - return execInt(false, m -> m.count()); + return execInt(m -> m.count()); } public List select() { - return execObjects(false, m -> m.select()); + return execObjects(m -> m.select()); } public TObject selectOne(final TIdentity id) { - return execObject(false, m -> m.selectOne(id)); + return execObject(m -> m.selectOne(id)); } } -- cgit v1.1-2-g2b99