/** Store databases on the disk */ @Override public void flush() { for (DB database : this.dbList) { System.out.println("Flushing data on disk."); database.flush(); } }
/** * Default constructor * * @throws DBNotFoundException */ public DBServerImpl() { this.dbList = new ArrayList<DB>(); // ///////////////////////////////// // Bootstrap databases // filter for .dbcsv file FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".dbcsv"); } }; File listDir = new File("./"); File[] listFiles = listDir.listFiles(filter); // for all files --> create database try { for (File file : listFiles) { String dbName = file.getName().replaceAll(".dbcsv", ""); DB database = new DB(dbName); database.loadDatabase(); // load database this.dbList.add(database); } } catch (DBNotFoundException e) { e.printStackTrace(); } }
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { User user = (User) req.getSession().getAttribute("user"); if (user != null) { DB db = new RealDB(); db.update("delete from userAnswers where userID=" + user.id + ";"); db.update("update users set lastQuestion=1 where id=" + user.id + ";"); } resp.sendRedirect("/"); }
/** Returns DB list */ @Override public String[] listDB() { int size = this.dbList.size(); String[] retStrList = new String[size]; for (int i = 0; i < size; i++) { DB tmpDB = this.dbList.get(i); retStrList[i] = tmpDB.getDbName(); } return retStrList; }
/** * Check if the database with dbname exists * * @param dbname * @return returns DB if exists */ private DB dbExists(String dbname) { DB retval = null; // doesn't exist by default for (DB db : this.dbList) { if (db.getDbName().equals(dbname)) { retval = db; break; } } return retval; }
/** Update database record */ @Override public int update(String dbname, Integer key, String message) throws DBNotFoundException, KeyNotFoundException { DB db = null; db = this.dbExists(dbname); if (db == null) throw new DBNotFoundException("<< ERROR - Database " + dbname + " does not exists."); // ////////////////////////////////////////////////////////////////// db.updateDbRec(key, message); // TODO ret hodnoty!! return 0; }
@Override public int insert(String dbname, Integer key, String message) throws DBNotFoundException, DuplicateKeyException { DB db = null; db = this.dbExists(dbname); if (db == null) throw new DBNotFoundException("<< ERROR - Database " + dbname + " does not exist."); // /////////////////////////////////// // db exists --> insert data db.insertNewRecord(key, message); // TODO - opravit returny return 0; }
/** Returns one record */ @Override public DBRecord get(String dbname, Integer key) throws DBNotFoundException, KeyNotFoundException { DB db = null; db = this.dbExists(dbname); if (db == null) throw new DBNotFoundException("<< ERROR - Database " + dbname + " does not exists."); // here db exists DBRecord dbr = db.findDbRec(key); if (dbr == null) { throw new KeyNotFoundException( "<< ERROR - Key: " + key + " wasn't found in the database.", key); } return dbr; }
@Override public void addObject(String id, Coverage o) { if (!this.database.containsKey(id)) super.addObject(id, o); else { Coverage prev = this.database.get(id); prev.addMatches(o); } }
@Override public DBRecord[] getA(String dbname, Integer[] key) throws DBNotFoundException, KeyNotFoundException { DB db = null; db = this.dbExists(dbname); if (db == null) throw new DBNotFoundException("<< ERROR - Database " + dbname + " does not exists."); // //////////////////////////// // here exists database int size = key.length; DBRecord[] dbRecords = new DBRecord[size]; for (int i = 0; i < size; i++) { int keyNum = key[i]; DBRecord tmpRec = db.findDbRec(keyNum); if (tmpRec == null) { throw new KeyNotFoundException( "<< ERROR - Key:" + keyNum + " wasn't found in the database.", keyNum); } dbRecords[i] = tmpRec; } return dbRecords; }
private void downloadToDB(String timePeriod) { db.insertUser(tableName, timePeriod, total.toString()); }
private void downloadToDB(String timePeriod, String pvBytime) { db.insertUser(tableName, timePeriod, pvBytime); }