@Required public void setJongo(final Jongo jongo) { this.jongo = jongo; this.gridfs = new GridFS(jongo.getDatabase()); }
private List<String> generateTableList() { return new ArrayList<>(jongo.getDatabase().getCollectionNames()); }
private Map<String, Map<String, DataColumn>> generateTableMetaData() { int ordinalPosition = 1; Map<String, Map<String, DataColumn>> metaData = new HashMap<>(); HashMap<String, DataColumn> column = new HashMap<>(); for (String tableName : this.tableList) { DBCollection readResult = jongo.getDatabase().getCollection(tableName); Iterator<DBObject> cursor = readResult.find(); while (cursor.hasNext()) { DBObject doumentData = cursor.next(); String tempValue = doumentData.toString(); Iterator<?> keys = new JSONObject(tempValue).keys(); while (keys.hasNext()) { String columnName = (String) keys.next(); DataColumn dataColumn = new DataColumn(columnName, DataColumn.ODataDataType.STRING, ordinalPosition, true, 100, columnName.equals(DOCUMENT_ID)); column.put(columnName, dataColumn); ordinalPosition++; } metaData.put(tableName, column); } } return metaData; }
/** * This method reads the data for a given collection. * Returns a list of DataEntry objects. * * @param tableName Name of the table * @return EntityCollection * @see DataEntry */ @Override public List<ODataEntry> readTable(String tableName) { List<ODataEntry> entryList = new ArrayList<>(); DBCollection readResult = jongo.getDatabase().getCollection(tableName); Iterator<DBObject> cursor = readResult.find(); DBObject documentData; String tempValue; while (cursor.hasNext()) { ODataEntry dataEntry; documentData = cursor.next(); tempValue = documentData.toString(); Iterator<?> keys = new JSONObject(tempValue).keys(); dataEntry = createDataEntryFromResult(tempValue, keys); //Set Etag to the entity dataEntry.addValue(ETAG, ODataUtils.generateETag(this.configId, tableName, dataEntry)); entryList.add(dataEntry); } return entryList; }
jongo.getDatabase().getMongo().close();