From 12e8f372d2255cb254eb874e1c39fa62eef894d9 Mon Sep 17 00:00:00 2001
From: Ulrich <undisclosed>
Date: Tue, 27 Feb 2018 15:48:51 +0000
Subject: [PATCH] Log-Eintraege fuer SenderApi hinzugefuegt

---
 src/java/de/uhilger/radiozentrale/api/SenderApi.java |   54 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/src/java/de/uhilger/radiozentrale/api/SenderApi.java b/src/java/de/uhilger/radiozentrale/api/SenderApi.java
index ac56940..1c6800e 100644
--- a/src/java/de/uhilger/radiozentrale/api/SenderApi.java
+++ b/src/java/de/uhilger/radiozentrale/api/SenderApi.java
@@ -18,49 +18,69 @@
 
 package de.uhilger.radiozentrale.api;
 
-import de.uhilger.baselink.GenericRecord;
 import de.uhilger.baselink.PersistenceManager;
 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;
+import java.util.logging.Logger;
 
 /**
  *
  */
-public class SenderApi extends Api {
+public class SenderApi extends DbApi {
+  
+  private static final Logger logger = Logger.getLogger(SenderApi.class.getName());
   
   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";
-  
   
   public Sender neuerSender(Sender sender) {
     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));
-      db.execute(getSql(SQL_INCREMENT_KEY), nextKey+1, KEY_SENDER_ID, nextKey);
+    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) {
         neuerSender = (Sender) o;
+        db.commit(c);
+        logger.fine("Sender erstellt: " + sender.getId() + " " + sender.getName());
+      } else {
+        db.rollback(c);
+        logger.info("Sender konnte nicht erstellt werden: " + sender.getName());
       } 
+    } else {
+      db.rollback(c);
+      logger.info("Sender konnte nicht erstellt werden, nextKey ist -1");
     }
-    db.commit(c);
     return neuerSender;  
   }
   
-  public List senderliste() {
-    String sql = getSql(SQL_GET_SENDER);
-    return getDb().select(sql, getMapper(Initialiser.MP_SENDER));
+  public Sender senderAendern(Sender sender) {
+    Sender geaendert = null; 
+    Object o = getDb().update(sender, getMapper(Initialiser.MP_SENDER));
+    if(o instanceof Sender) {
+      geaendert = (Sender) o;
+      logger.fine("Sender geaendert: " + sender.getId() + " " + sender.getName());
+    }
+    return geaendert;
   }
+  
+  public Sender senderLoeschen(Sender sender) {
+    Sender geloescht = null;
+    Object o = getDb().delete(sender, getMapper(Initialiser.MP_SENDER));
+    if(o instanceof Sender) {
+      geloescht = (Sender) o;
+      logger.fine("Sender geloescht: " + sender.getId() + " " + sender.getName());
+    }
+    return geloescht;
+  }
+  
+  public List senderliste() {
+    return getDb().select(getSql(SQL_GET_SENDER), getMapper(Initialiser.MP_SENDER));
+  }
+  
 }

--
Gitblit v1.9.3