From ceb15c426f081e89608c31d625d71759aff5e072 Mon Sep 17 00:00:00 2001 From: ulrich <undisclosed> Date: Mon, 26 Feb 2018 22:37:12 +0000 Subject: [PATCH] Sender aendern und DbApi --- src/java/de/uhilger/radiozentrale/api/SenderApi.java | 22 ++++++++++++++-------- 1 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/java/de/uhilger/radiozentrale/api/SenderApi.java b/src/java/de/uhilger/radiozentrale/api/SenderApi.java index 5493629..3b8616a 100644 --- a/src/java/de/uhilger/radiozentrale/api/SenderApi.java +++ b/src/java/de/uhilger/radiozentrale/api/SenderApi.java @@ -28,11 +28,9 @@ /** * */ -public class SenderApi extends Api { +public class SenderApi extends DbApi { public static final String SQL_GET_SENDER = "getSender"; - public static final String SQL_GET_NEXT_KEY = "getNextKey"; - public static final String SQL_INCREMENT_KEY = "incrementKey"; public static final String KEY_SENDER_ID = "sender_id"; @@ -41,11 +39,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) { @@ -58,7 +54,17 @@ return neuerSender; } + public Sender senderAendern(Sender sender) { + Sender geaendert = null; + Object o = getDb().update(sender, getMapper(Initialiser.MP_SENDER)); + if(o instanceof Sender) { + geaendert = (Sender) o; + } + return geaendert; + } + public List senderliste() { return getDb().select(getSql(SQL_GET_SENDER), getMapper(Initialiser.MP_SENDER)); } + } -- Gitblit v1.9.3