From b1aeea7790097ad8edea15dcadf375fac7b23121 Mon Sep 17 00:00:00 2001 From: ulrich <undisclosed> Date: Sun, 25 Feb 2018 20:29:08 +0000 Subject: [PATCH] Eigene Methode fuer ID-Inkrement --- src/java/de/uhilger/radiozentrale/api/SenderApi.java | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/java/de/uhilger/radiozentrale/api/SenderApi.java b/src/java/de/uhilger/radiozentrale/api/SenderApi.java index 5493629..728ffad 100644 --- a/src/java/de/uhilger/radiozentrale/api/SenderApi.java +++ b/src/java/de/uhilger/radiozentrale/api/SenderApi.java @@ -41,11 +41,9 @@ Sender neuerSender = null; PersistenceManager db = getDb(); Connection c = db.getConnection(); - List<List<String>> list = db.select(getSql(SQL_GET_NEXT_KEY), GenericRecord.WITHOUT_BLOBS, KEY_SENDER_ID); - 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); + db.startTransaction(c); + int nextKey = getNextId(db, KEY_SENDER_ID); + if(nextKey > -1) { sender.setId(nextKey); Object o = getDb().insert(sender, getMapper(Initialiser.MP_SENDER)); if(o instanceof Sender) { @@ -61,4 +59,16 @@ public List senderliste() { return getDb().select(getSql(SQL_GET_SENDER), getMapper(Initialiser.MP_SENDER)); } + + private int getNextId(PersistenceManager db, String key) { + int nextKey = -1; + List<List<String>> list = db.select(getSql(SQL_GET_NEXT_KEY), GenericRecord.WITHOUT_BLOBS, key); + if(list != null && list.size() > 1) { + nextKey = Integer.parseInt(list.get(1).get(0)); // erster Datensatz ist Ueberschrift + if(nextKey > -1) { + db.execute(getSql(SQL_INCREMENT_KEY), nextKey+1, key, nextKey); + } + } + return nextKey; + } } -- Gitblit v1.9.3