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.PersistenceManager; |
|
22 |
import de.uhilger.radiozentrale.daten.Sender; |
|
23 |
import de.uhilger.radiozentrale.web.Initialiser; |
|
24 |
import java.sql.Connection; |
|
25 |
import java.util.List; |
12e8f3
|
26 |
import java.util.logging.Logger; |
a0ec7b
|
27 |
|
U |
28 |
/** |
|
29 |
* |
|
30 |
*/ |
ceb15c
|
31 |
public class SenderApi extends DbApi { |
a0ec7b
|
32 |
|
12e8f3
|
33 |
private static final Logger logger = Logger.getLogger(SenderApi.class.getName()); |
U |
34 |
|
74f15b
|
35 |
public static final String SQL_GET_SENDER_LIST = "getSenderList"; |
a0ec7b
|
36 |
public static final String KEY_SENDER_ID = "sender_id"; |
U |
37 |
|
|
38 |
public Sender neuerSender(Sender sender) { |
|
39 |
Sender neuerSender = null; |
|
40 |
PersistenceManager db = getDb(); |
|
41 |
Connection c = db.getConnection(); |
b1aeea
|
42 |
db.startTransaction(c); |
U |
43 |
int nextKey = getNextId(db, KEY_SENDER_ID); |
|
44 |
if(nextKey > -1) { |
a0ec7b
|
45 |
sender.setId(nextKey); |
U |
46 |
Object o = getDb().insert(sender, getMapper(Initialiser.MP_SENDER)); |
|
47 |
if(o instanceof Sender) { |
|
48 |
neuerSender = (Sender) o; |
8c352d
|
49 |
db.commit(c); |
12e8f3
|
50 |
logger.fine("Sender erstellt: " + sender.getId() + " " + sender.getName()); |
8c352d
|
51 |
} else { |
U |
52 |
db.rollback(c); |
12e8f3
|
53 |
logger.info("Sender konnte nicht erstellt werden: " + sender.getName()); |
a0ec7b
|
54 |
} |
12e8f3
|
55 |
} else { |
U |
56 |
db.rollback(c); |
|
57 |
logger.info("Sender konnte nicht erstellt werden, nextKey ist -1"); |
a0ec7b
|
58 |
} |
U |
59 |
return neuerSender; |
|
60 |
} |
|
61 |
|
ceb15c
|
62 |
public Sender senderAendern(Sender sender) { |
U |
63 |
Sender geaendert = null; |
|
64 |
Object o = getDb().update(sender, getMapper(Initialiser.MP_SENDER)); |
|
65 |
if(o instanceof Sender) { |
|
66 |
geaendert = (Sender) o; |
12e8f3
|
67 |
logger.fine("Sender geaendert: " + sender.getId() + " " + sender.getName()); |
ceb15c
|
68 |
} |
U |
69 |
return geaendert; |
|
70 |
} |
|
71 |
|
18af7c
|
72 |
public Sender senderLoeschen(Sender sender) { |
H |
73 |
Sender geloescht = null; |
|
74 |
Object o = getDb().delete(sender, getMapper(Initialiser.MP_SENDER)); |
|
75 |
if(o instanceof Sender) { |
|
76 |
geloescht = (Sender) o; |
12e8f3
|
77 |
logger.fine("Sender geloescht: " + sender.getId() + " " + sender.getName()); |
18af7c
|
78 |
} |
H |
79 |
return geloescht; |
|
80 |
} |
|
81 |
|
a0ec7b
|
82 |
public List senderliste() { |
74f15b
|
83 |
return getDb().select(getSql(SQL_GET_SENDER_LIST), getMapper(Initialiser.MP_SENDER)); |
a0ec7b
|
84 |
} |
b1aeea
|
85 |
|
a0ec7b
|
86 |
} |