/** * get history from database * * @param name history name * @param maxHistoryLength max. length of history or HISTORY_LENGTH_INFINTE * @param direction history direction order * @return list with history data */ public static LinkedList<String> getHistory( String name, int maxHistoryLength, Directions direction) { LinkedList<String> historyList = null; HistoryDatabase historyDatabase = null; try { // open database historyDatabase = openStringHistoryDatabase(name, maxHistoryLength, direction); // get history historyList = historyDatabase.getHistory(); // close database historyDatabase.close(); historyDatabase = null; } catch (SQLException exception) { Onzen.printWarning( "Cannot load history '%s' from database (error: %s)", name, exception.getMessage()); return new LinkedList<String>(); } finally { if (historyDatabase != null) historyDatabase.close(); } return historyList; }
/** * put history into database * * @param name history name * @param historyList history list * @param maxHistoryLength max. length of history or HISTORY_LENGTH_INFINTE * @param direction history direction order * @param addEntry entry to add or null */ public static void setHistory( String name, LinkedList<String> historyList, int maxHistoryLength, Directions direction, String addEntry) { HistoryDatabase historyDatabase = null; try { // open database historyDatabase = openStringHistoryDatabase(name, maxHistoryLength, direction); // set history historyDatabase.setHistory(historyList); // add entry if ((addEntry != null) && !addEntry.isEmpty()) add(historyList, maxHistoryLength, direction, addEntry); // close database historyDatabase.close(); historyDatabase = null; } catch (SQLException exception) { Onzen.printWarning( "Cannot save history '%s' into database (error: %s)", name, exception.getMessage()); return; } finally { if (historyDatabase != null) historyDatabase.close(); } }