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; |
|
26 |
|
|
27 |
/** |
|
28 |
* |
|
29 |
*/ |
ceb15c
|
30 |
public class SenderApi extends DbApi { |
a0ec7b
|
31 |
|
U |
32 |
public static final String SQL_GET_SENDER = "getSender"; |
|
33 |
|
|
34 |
public static final String KEY_SENDER_ID = "sender_id"; |
|
35 |
|
|
36 |
|
|
37 |
public Sender neuerSender(Sender sender) { |
|
38 |
Sender neuerSender = null; |
|
39 |
PersistenceManager db = getDb(); |
|
40 |
Connection c = db.getConnection(); |
b1aeea
|
41 |
db.startTransaction(c); |
U |
42 |
int nextKey = getNextId(db, KEY_SENDER_ID); |
|
43 |
if(nextKey > -1) { |
a0ec7b
|
44 |
sender.setId(nextKey); |
U |
45 |
Object o = getDb().insert(sender, getMapper(Initialiser.MP_SENDER)); |
|
46 |
if(o instanceof Sender) { |
|
47 |
neuerSender = (Sender) o; |
8c352d
|
48 |
db.commit(c); |
U |
49 |
} else { |
|
50 |
db.rollback(c); |
a0ec7b
|
51 |
} |
U |
52 |
} |
|
53 |
return neuerSender; |
|
54 |
} |
|
55 |
|
ceb15c
|
56 |
public Sender senderAendern(Sender sender) { |
U |
57 |
Sender geaendert = null; |
|
58 |
Object o = getDb().update(sender, getMapper(Initialiser.MP_SENDER)); |
|
59 |
if(o instanceof Sender) { |
|
60 |
geaendert = (Sender) o; |
|
61 |
} |
|
62 |
return geaendert; |
|
63 |
} |
|
64 |
|
18af7c
|
65 |
public Sender senderLoeschen(Sender sender) { |
H |
66 |
Sender geloescht = null; |
|
67 |
Object o = getDb().delete(sender, getMapper(Initialiser.MP_SENDER)); |
|
68 |
if(o instanceof Sender) { |
|
69 |
geloescht = (Sender) o; |
|
70 |
} |
|
71 |
return geloescht; |
|
72 |
} |
|
73 |
|
a0ec7b
|
74 |
public List senderliste() { |
8c352d
|
75 |
return getDb().select(getSql(SQL_GET_SENDER), getMapper(Initialiser.MP_SENDER)); |
a0ec7b
|
76 |
} |
b1aeea
|
77 |
|
a0ec7b
|
78 |
} |