| | |
| | | |
| | | import de.uhilger.baselink.GenericRecord; |
| | | import de.uhilger.baselink.PersistenceManager; |
| | | import de.uhilger.radiozentrale.daten.Abspieler; |
| | | import de.uhilger.radiozentrale.daten.Sender; |
| | | import de.uhilger.radiozentrale.web.Initialiser; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.util.List; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | | * |
| | | */ |
| | | public abstract class DbApi extends Api { |
| | | |
| | | private static final Logger logger = Logger.getLogger(DbApi.class.getName()); |
| | | |
| | | public static final String SQL_GET_NEXT_KEY = "getNextKey"; |
| | | public static final String SQL_INCREMENT_KEY = "incrementKey"; |
| | | public static final String SQL_GET_ABSPIELER = "getAbspieler"; |
| | | public static final String SQL_GET_SENDER = "getSender"; |
| | | |
| | | protected int getNextId(PersistenceManager db, String key) { |
| | | int nextKey = -1; |
| | |
| | | } |
| | | return nextKey; |
| | | } |
| | | |
| | | protected Abspieler getAbspieler(int id) { |
| | | Abspieler a = null; |
| | | List list = getDb().select(getSql(SQL_GET_ABSPIELER), getMapper(Initialiser.MP_ABSPIELER), true, id); |
| | | if(list != null && list.size() > 0) { |
| | | Object o = list.get(0); |
| | | if(o instanceof Abspieler) { |
| | | a = (Abspieler) o; |
| | | } |
| | | } |
| | | return a; |
| | | } |
| | | |
| | | protected Sender getSender(int id) { |
| | | Sender s = null; |
| | | List list = getDb().select(getSql(SQL_GET_SENDER), getMapper(Initialiser.MP_SENDER), true, id); |
| | | if(list != null && list.size() > 0) { |
| | | Object o = list.get(0); |
| | | if(o instanceof Sender) { |
| | | s = (Sender) o; |
| | | } |
| | | } |
| | | return s; |
| | | } |
| | | |
| | | protected String abspielerKommandoSenden(String kommando) { |
| | | String antwort = null; |
| | | logger.info(kommando); |
| | | try { |
| | | HttpURLConnection conn = (HttpURLConnection) new URL(kommando).openConnection(); |
| | | conn.setRequestMethod("GET"); |
| | | conn.connect(); |
| | | int status = conn.getResponseCode(); |
| | | String msg = conn.getResponseMessage(); |
| | | antwort = "Kommando " + kommando + " mit Status " + status + " " + msg + " gesendet."; |
| | | logger.log(Level.INFO, antwort); |
| | | } catch(Exception ex) { |
| | | logger.log(Level.INFO, ex.getMessage(), ex); |
| | | } |
| | | return antwort; |
| | | } |
| | | } |