commit | author | age
|
ceb15c
|
1 |
/* |
U |
2 |
* To change this license header, choose License Headers in Project Properties. |
|
3 |
* To change this template file, choose Tools | Templates |
|
4 |
* and open the template in the editor. |
|
5 |
*/ |
|
6 |
package de.uhilger.radiozentrale.api; |
|
7 |
|
|
8 |
import de.uhilger.baselink.GenericRecord; |
|
9 |
import de.uhilger.baselink.PersistenceManager; |
|
10 |
import java.util.List; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
*/ |
|
15 |
public abstract class DbApi extends Api { |
|
16 |
|
|
17 |
public static final String SQL_GET_NEXT_KEY = "getNextKey"; |
|
18 |
public static final String SQL_INCREMENT_KEY = "incrementKey"; |
|
19 |
|
|
20 |
protected int getNextId(PersistenceManager db, String key) { |
|
21 |
int nextKey = -1; |
|
22 |
List<List<String>> list = db.select(getSql(SQL_GET_NEXT_KEY), GenericRecord.WITHOUT_BLOBS, key); |
|
23 |
if(list != null && list.size() > 1) { |
|
24 |
nextKey = Integer.parseInt(list.get(1).get(0)); // erster Datensatz ist Ueberschrift |
|
25 |
if(nextKey > -1) { |
|
26 |
db.execute(getSql(SQL_INCREMENT_KEY), nextKey+1, key, nextKey); |
|
27 |
} |
|
28 |
} |
|
29 |
return nextKey; |
|
30 |
} |
|
31 |
} |