diff --git a/modules/dbsupport/src/main/java/org/jpos/ee/DB.java b/modules/dbsupport/src/main/java/org/jpos/ee/DB.java index 665fce87ae..21651059cf 100644 --- a/modules/dbsupport/src/main/java/org/jpos/ee/DB.java +++ b/modules/dbsupport/src/main/java/org/jpos/ee/DB.java @@ -31,6 +31,7 @@ import org.jpos.util.LogEvent; import org.jpos.util.Logger; +import java.io.Closeable; import java.util.Set; /** @@ -41,8 +42,7 @@ * to Hibernate O/R mapping engine */ @SuppressWarnings({"UnusedDeclaration"}) -public class DB -{ +public class DB implements Closeable { Session session; Log log; @@ -229,6 +229,22 @@ public synchronized void setLog(Log log) this.log = log; } + public static Object exec (DBAction action) { + try (DB db = new DB()) { + db.open(); + return action.exec(db); + } + } + public static Object execWithTransaction (DBAction action) { + try (DB db = new DB()) { + db.open(); + db.beginTransaction(); + Object obj = action.exec(db); + db.commit(); + return obj; + } + } + @SuppressWarnings({"unchecked"}) public void printStats() { diff --git a/modules/dbsupport/src/main/java/org/jpos/ee/DBAction.java b/modules/dbsupport/src/main/java/org/jpos/ee/DBAction.java new file mode 100644 index 0000000000..e481a95b5e --- /dev/null +++ b/modules/dbsupport/src/main/java/org/jpos/ee/DBAction.java @@ -0,0 +1,24 @@ +/* + * jPOS Project [http://jpos.org] + * Copyright (C) 2000-2015 Alejandro P. Revilla + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.jpos.ee; + +@FunctionalInterface +public interface DBAction { + Object exec (DB db); +} diff --git a/modules/testbed/build.gradle b/modules/testbed/build.gradle index a5df606382..6c58a0bbfd 100644 --- a/modules/testbed/build.gradle +++ b/modules/testbed/build.gradle @@ -2,6 +2,12 @@ description = 'jPOS-EE :: Testbed' dependencies { compile project(':modules:core') + compile project(':modules:logback') + compile project(':modules:dbsupport') + compile project(':modules:db-h2') + compile project(':modules:sysconfig') + compile project(':modules:eeuser') + compile project(':modules:syslog') } apply from: '../../jpos-app.gradle'