/*
|
* 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.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;
|
|
/**
|
*
|
*/
|
public class SenderApi extends Api {
|
|
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);
|
sender.setId(nextKey);
|
Object o = getDb().insert(sender, getMapper(Initialiser.MP_SENDER));
|
if(o instanceof Sender) {
|
neuerSender = (Sender) o;
|
}
|
}
|
db.commit(c);
|
return neuerSender;
|
}
|
|
public List senderliste() {
|
String sql = getSql(SQL_GET_SENDER);
|
return getDb().select(sql, getMapper(Initialiser.MP_SENDER));
|
}
|
}
|