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.ArrayList; |
|
27 |
import java.util.Collections; |
|
28 |
import java.util.Iterator; |
|
29 |
import java.util.List; |
|
30 |
|
|
31 |
/** |
|
32 |
* |
|
33 |
*/ |
|
34 |
public class SenderApi extends Api { |
|
35 |
|
|
36 |
public static final String SQL_GET_SENDER = "getSender"; |
|
37 |
public static final String SQL_GET_NEXT_KEY = "getNextKey"; |
|
38 |
public static final String SQL_INCREMENT_KEY = "incrementKey"; |
|
39 |
|
|
40 |
public static final String KEY_SENDER_ID = "sender_id"; |
|
41 |
|
|
42 |
|
|
43 |
public Sender neuerSender(Sender sender) { |
|
44 |
Sender neuerSender = null; |
|
45 |
PersistenceManager db = getDb(); |
|
46 |
Connection c = db.getConnection(); |
|
47 |
db.startTransaction(c); |
|
48 |
List<List<String>> list = db.select(getSql(SQL_GET_NEXT_KEY), GenericRecord.WITHOUT_BLOBS, KEY_SENDER_ID); |
|
49 |
if(list != null && list.size() > 0) { |
|
50 |
int nextKey = Integer.parseInt(list.get(1).get(0)); |
|
51 |
db.execute(getSql(SQL_INCREMENT_KEY), nextKey+1, KEY_SENDER_ID, nextKey); |
|
52 |
sender.setId(nextKey); |
|
53 |
Object o = getDb().insert(sender, getMapper(Initialiser.MP_SENDER)); |
|
54 |
if(o instanceof Sender) { |
|
55 |
neuerSender = (Sender) o; |
|
56 |
} |
|
57 |
} |
|
58 |
db.commit(c); |
|
59 |
return neuerSender; |
|
60 |
} |
|
61 |
|
|
62 |
public List senderliste() { |
|
63 |
String sql = getSql(SQL_GET_SENDER); |
|
64 |
return getDb().select(sql, getMapper(Initialiser.MP_SENDER)); |
|
65 |
} |
|
66 |
} |