From 8c352d59e8d9de9c53d70c2327330022a1d658b7 Mon Sep 17 00:00:00 2001 From: ulrich <undisclosed> Date: Sun, 25 Feb 2018 18:12:03 +0000 Subject: [PATCH] SenderApi aufgeraeumt --- src/java/de/uhilger/radiozentrale/api/SenderApi.java | 16 +++++++--------- 1 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/java/de/uhilger/radiozentrale/api/SenderApi.java b/src/java/de/uhilger/radiozentrale/api/SenderApi.java index ac56940..5493629 100644 --- a/src/java/de/uhilger/radiozentrale/api/SenderApi.java +++ b/src/java/de/uhilger/radiozentrale/api/SenderApi.java @@ -23,9 +23,6 @@ import de.uhilger.radiozentrale.daten.Sender; import de.uhilger.radiozentrale.web.Initialiser; import java.sql.Connection; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; import java.util.List; /** @@ -44,23 +41,24 @@ Sender neuerSender = null; PersistenceManager db = getDb(); Connection c = db.getConnection(); - db.startTransaction(c); List<List<String>> list = db.select(getSql(SQL_GET_NEXT_KEY), GenericRecord.WITHOUT_BLOBS, KEY_SENDER_ID); - if(list != null && list.size() > 0) { - int nextKey = Integer.parseInt(list.get(1).get(0)); + if(list != null && list.size() > 1) { + int nextKey = Integer.parseInt(list.get(1).get(0)); // erster Datensatz ist Ueberschrift + db.startTransaction(c); db.execute(getSql(SQL_INCREMENT_KEY), nextKey+1, KEY_SENDER_ID, nextKey); sender.setId(nextKey); Object o = getDb().insert(sender, getMapper(Initialiser.MP_SENDER)); if(o instanceof Sender) { neuerSender = (Sender) o; + db.commit(c); + } else { + db.rollback(c); } } - db.commit(c); return neuerSender; } public List senderliste() { - String sql = getSql(SQL_GET_SENDER); - return getDb().select(sql, getMapper(Initialiser.MP_SENDER)); + return getDb().select(getSql(SQL_GET_SENDER), getMapper(Initialiser.MP_SENDER)); } } -- Gitblit v1.9.3