From 08f161e0f370e91ee4e0cacbe3fec6c6bd9316cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 15 Apr 2017 17:57:58 +0200 Subject: java : MyMyBatis goes functional interface --- java/MyMyBatis/src/AbstractDAO.java | 5 +++-- java/MyMyBatis/src/AbstractDAOOperations.java | 25 +++++++------------------ 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/java/MyMyBatis/src/AbstractDAO.java b/java/MyMyBatis/src/AbstractDAO.java index 916d511..142b69f 100644 --- a/java/MyMyBatis/src/AbstractDAO.java +++ b/java/MyMyBatis/src/AbstractDAO.java @@ -20,9 +20,10 @@ public abstract class AbstractDAO static public SqlConnection getSqlConnection() { return conn; } - protected abstract class CallBack + @FunctionalInterface + public interface CallBack { - public abstract TRet call(TMapper m); + public TRet call(TMapper m); } protected int execInt(boolean commit, CallBack cb) diff --git a/java/MyMyBatis/src/AbstractDAOOperations.java b/java/MyMyBatis/src/AbstractDAOOperations.java index e39f680..6fcd6e4 100644 --- a/java/MyMyBatis/src/AbstractDAOOperations.java +++ b/java/MyMyBatis/src/AbstractDAOOperations.java @@ -4,45 +4,34 @@ import java.util.List; public abstract class AbstractDAOOperations> extends AbstractDAO { + public int insert(final TObject obj) { - return execInt(true, new CallBack() { - public Integer call(TMapper m) { return m.insert(obj); } - }); + return execInt(true, m -> m.insert(obj)); } public int update(final TObject obj) { - return execInt(true, new CallBack() { - public Integer call(TMapper m) { return m.update(obj); } - }); + return execInt(true, m -> m.update(obj)); } public int delete(final TObject obj) { - return execInt(true, new CallBack() { - public Integer call(TMapper m) { return m.delete(obj); } - }); + return execInt(true, m -> m.delete(obj)); } public int count() { - return execInt(false, new CallBack() { - public Integer call(TMapper m) { return m.count(); } - }); + return execInt(false, m -> m.count()); } public List select() { - return execObjects(false, new CallBack, TMapper>() { - public List call(TMapper m) { return m.select(); } - }); + return execObjects(false, m -> m.select()); } public TObject selectOne(final TIdentity id) { - return execObject(false, new CallBack() { - public TObject call(TMapper m) { return m.selectOne(id); } - }); + return execObject(false, m -> m.selectOne(id)); } } -- cgit v1.1-2-g2b99