New file |
| | |
| | | /* |
| | | * 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.Abspieler; |
| | | import de.uhilger.radiozentrale.web.Initialiser; |
| | | import java.sql.Connection; |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | public class AbspielerApi extends DbApi { |
| | | |
| | | private static final Logger logger = Logger.getLogger(AbspielerApi.class.getName()); |
| | | |
| | | public static final String KEY_ABSPIELER_ID = "abs_id"; |
| | | |
| | | /** |
| | | * TODO selected bei anderen Abspielern entfernen, wenn der neue Abspieler |
| | | * selected sein soll |
| | | * @param abspieler |
| | | * @return |
| | | */ |
| | | public Abspieler neuerAbspieler(Abspieler abspieler) { |
| | | Abspieler neuerAbspieler = null; |
| | | PersistenceManager db = getDb(); |
| | | Connection c = db.getConnection(); |
| | | db.startTransaction(c); |
| | | int nextKey = getNextId(db, KEY_ABSPIELER_ID); |
| | | if(nextKey > -1) { |
| | | abspieler.setId(nextKey); |
| | | Object o = getDb().insert(abspieler, getMapper(Initialiser.MP_ABSPIELER)); |
| | | if(o instanceof Abspieler) { |
| | | neuerAbspieler = (Abspieler) o; |
| | | db.commit(c); |
| | | logger.fine("Abspieler erstellt: " + abspieler.getId() + " " + abspieler.getName()); |
| | | } else { |
| | | db.rollback(c); |
| | | logger.info("Abspieler konnte nicht erstellt werden: " + abspieler.getName()); |
| | | } |
| | | } else { |
| | | db.rollback(c); |
| | | logger.info("Abspieler konnte nicht erstellt werden, nextKey ist -1"); |
| | | } |
| | | return neuerAbspieler; |
| | | |
| | | } |
| | | } |