/* * Radiozentrale - Webradio App * Copyright (C) 2018 Ulrich Hilger, http://uhilger.de * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/ */ package de.uhilger.radiozentrale.api; import de.uhilger.baselink.PersistenceManager; import de.uhilger.radiozentrale.daten.Sender; import de.uhilger.radiozentrale.web.Initialiser; import java.sql.Connection; import java.util.List; import java.util.logging.Logger; /** * */ public class SenderApi extends DbApi { private static final Logger logger = Logger.getLogger(SenderApi.class.getName()); public static final String SQL_GET_SENDER_LIST = "getSenderList"; 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); 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"); } 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; 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_LIST), getMapper(Initialiser.MP_SENDER)); } }