commit | author | age
|
a0ec7b
|
1 |
/* |
U |
2 |
* Radiozentrale - Webradio App |
|
3 |
* Copyright (C) 2018 Ulrich Hilger, http://uhilger.de |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
|
8 |
* (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program. If not, see http://www.gnu.org/licenses/ |
|
17 |
*/ |
|
18 |
|
|
19 |
package de.uhilger.radiozentrale.api; |
|
20 |
|
|
21 |
import de.uhilger.baselink.GenericRecord; |
|
22 |
import de.uhilger.baselink.PersistenceManager; |
|
23 |
import de.uhilger.radiozentrale.daten.Sender; |
|
24 |
import de.uhilger.radiozentrale.web.Initialiser; |
|
25 |
import java.sql.Connection; |
|
26 |
import java.util.List; |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
public class SenderApi extends Api { |
|
32 |
|
|
33 |
public static final String SQL_GET_SENDER = "getSender"; |
|
34 |
public static final String SQL_GET_NEXT_KEY = "getNextKey"; |
|
35 |
public static final String SQL_INCREMENT_KEY = "incrementKey"; |
|
36 |
|
|
37 |
public static final String KEY_SENDER_ID = "sender_id"; |
|
38 |
|
|
39 |
|
|
40 |
public Sender neuerSender(Sender sender) { |
|
41 |
Sender neuerSender = null; |
|
42 |
PersistenceManager db = getDb(); |
|
43 |
Connection c = db.getConnection(); |
|
44 |
List<List<String>> list = db.select(getSql(SQL_GET_NEXT_KEY), GenericRecord.WITHOUT_BLOBS, KEY_SENDER_ID); |
8c352d
|
45 |
if(list != null && list.size() > 1) { |
U |
46 |
int nextKey = Integer.parseInt(list.get(1).get(0)); // erster Datensatz ist Ueberschrift |
|
47 |
db.startTransaction(c); |
a0ec7b
|
48 |
db.execute(getSql(SQL_INCREMENT_KEY), nextKey+1, KEY_SENDER_ID, nextKey); |
U |
49 |
sender.setId(nextKey); |
|
50 |
Object o = getDb().insert(sender, getMapper(Initialiser.MP_SENDER)); |
|
51 |
if(o instanceof Sender) { |
|
52 |
neuerSender = (Sender) o; |
8c352d
|
53 |
db.commit(c); |
U |
54 |
} else { |
|
55 |
db.rollback(c); |
a0ec7b
|
56 |
} |
U |
57 |
} |
|
58 |
return neuerSender; |
|
59 |
} |
|
60 |
|
|
61 |
public List senderliste() { |
8c352d
|
62 |
return getDb().select(getSql(SQL_GET_SENDER), getMapper(Initialiser.MP_SENDER)); |
a0ec7b
|
63 |
} |
U |
64 |
} |