RDBURIReferences implements URIReferences, Closeable { public synchronized void add(CrawleableUri uri, List<CrawleableUri> urisFound) { if (!connector.tableExists(DATABASE_NAME, TABLE_NAME)) { LOGGER.warn("Table \"" + TABLE_NAME + "\" doesn't maybe exist until yet. Create it now..."); open(); } Cursor<List<String>> cursor = r.db(DATABASE_NAME) .table(TABLE_NAME) .getAll(utils.convertURI(uri)) .optArg("index", COLUMN_URI) .g(COLUMN_FOUNDURIS) .run(connector.connection); if (cursor.hasNext()) { String convertedURI = utils.convertURI(uri); try { List<String> updateList = utils.mergeLists(cursor.next(), urisFound); r.db(DATABASE_NAME).table(TABLE_NAME).getAll(convertedURI).optArg("index", COLUMN_URI).update(r.hashMap(COLUMN_FOUNDURIS, r.expr(updateList.toArray()))).run(connector.connection); LOGGER.info("There was already a row in the database table \"" + TABLE_NAME + "\" for " + convertedURI + ". We updated the value regarding that to a size of " + updateList.size()); } catch (OutOfMemoryError e) { LOGGER.error("List of references URIs was getting too long! Insert a new line (maybe leads to inconsistencies)", e); insertDBLine(uri, urisFound); } catch (Exception e) { LOGGER.error("Failed to extend/update the database " + DATABASE_NAME + "->" + TABLE_NAME + " with the URI " + convertedURI, e); } } else { insertDBLine(uri, urisFound); } try { cursor.close(); } catch (Exception e) { LOGGER.debug(e.getMessage()); } } RDBURIReferences(String hostname, Integer port);  RDBURIReferences(String hostname, Integer port, URIShortcutMode mode); void open(); synchronized void add(CrawleableUri uri, List<CrawleableUri> urisFound); @Override void close(); Iterator<AbstractMap.SimpleEntry<String, List<String>>> walkThroughCrawledGraph(int offset, boolean latest, boolean onlyCrawledUris); static final String DATABASE_NAME; static final String TABLE_NAME; static final String COLUMN_URI; static final String COLUMN_FOUNDURIS; }
@Test @SuppressWarnings("all") public void add() { Cursor cursor = r.db(RDBURIReferences.DATABASE_NAME).table(RDBURIReferences.TABLE_NAME).run(connection); while (cursor.hasNext()) { HashMap row = (HashMap) cursor.next(); List<String> listInDB = ((ArrayList<String>) row.get(RDBURIReferences.COLUMN_FOUNDURIS)); if (row.get(RDBURIReferences.COLUMN_URI).equals(mainURI1)) assertEquals("Prove for the first index (" + row.get(RDBURIReferences.COLUMN_URI) + ") the founded URI list. Should have a size of 2 because of the update. Current list: " + listInDB.toArray(), 2, listInDB.size()); else if (row.get(RDBURIReferences.COLUMN_URI).equals(mainURI2)) assertEquals("Prove for the second index (" + row.get(RDBURIReferences.COLUMN_URI) + ") the founded URI list. Should have a size of 1 because of no update. Current list: " + listInDB.toArray(), 1, listInDB.size()); } }