List of usage examples for com.mongodb DBObject toMap
Map toMap();
From source file:org.apache.metamodel.mongodb.common.MongoDBUtils.java
License:Apache License
private static Object toValue(Column column, Object value) { if (value instanceof List) { return value; }/*from ww w . jav a 2 s . com*/ if (value instanceof DBObject) { DBObject basicDBObject = (DBObject) value; return basicDBObject.toMap(); } return value; }
From source file:org.apache.metamodel.mongodb.MongoDBUtils.java
License:Apache License
/** * Converts a MongoDB data object {@link DBObject} into MetaModel * {@link Row}./* w w w .ja v a 2 s. c om*/ * * @param dbObject * a MongoDB object storing data. * @param header * a header describing the columns of the data stored. * @return the MetaModel {@link Row} result object. */ public static Row toRow(DBObject dbObject, DataSetHeader header) { if (dbObject == null) { return null; } final Map<?, ?> map = dbObject.toMap(); final int size = header.size(); final Object[] values = new Object[size]; for (int i = 0; i < values.length; i++) { final SelectItem selectItem = header.getSelectItem(i); final String key = selectItem.getColumn().getName(); final Object value = CollectionUtils.find(map, key); values[i] = toValue(selectItem.getColumn(), value); } return new DefaultRow(header, values); }
From source file:org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage.java
License:Apache License
@Override public Collection<Event> search(final Optional<RyaURI> subject, final Optional<Collection<IndexingExpr>> geoFilters, final Optional<Collection<IndexingExpr>> temporalFilters) throws EventStorageException { requireNonNull(subject);/*from w ww . ja va 2 s . c om*/ try { final Collection<IndexingExpr> geos = (geoFilters.isPresent() ? geoFilters.get() : new ArrayList<>()); final Collection<IndexingExpr> tempos = (temporalFilters.isPresent() ? temporalFilters.get() : new ArrayList<>()); final DBObject filterObj = queryAdapter.getFilterQuery(geos, tempos); final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(filterObj.toMap()); if (subject.isPresent()) { builder.append(EventDocumentConverter.SUBJECT, subject.get().getData()); } final MongoCursor<Document> results = mongo.getDatabase(ryaInstanceName).getCollection(COLLECTION_NAME) .find(BsonDocument.parse(builder.get().toString())).iterator(); final List<Event> events = new ArrayList<>(); while (results.hasNext()) { events.add(EVENT_CONVERTER.fromDocument(results.next())); } return events; } catch (final MongoException | DocumentConverterException | GeoTemporalIndexException e) { throw new EventStorageException("Could not get the Event.", e); } }
From source file:org.apache.rya.indexing.mongodb.temporal.TemporalMongoDBStorageStrategy.java
License:Apache License
@Override public DBObject serialize(final RyaStatement ryaStatement) { final BasicDBObject base = (BasicDBObject) super.serialize(ryaStatement); final DBObject time = getTimeValue(ryaStatement.getObject().getData()); base.putAll(time.toMap()); return base;/* w ww . j av a 2s. co m*/ }
From source file:org.apache.rya.mongodb.dao.SimpleMongoDBNamespaceManager.java
License:Apache License
@Override public String getNamespace(final String prefix) throws RyaDAOException { final DBObject query = new BasicDBObject().append(PREFIX, prefix); final DBCursor cursor = nsColl.find(query); String nameSpace = prefix;//from ww w.j a v a 2s . co m while (cursor.hasNext()) { final DBObject obj = cursor.next(); nameSpace = (String) obj.toMap().get(NAMESPACE); } return nameSpace; }
From source file:org.apache.rya.mongodb.dao.SimpleMongoDBStorageStrategy.java
License:Apache License
@Override public RyaStatement deserializeDBObject(final DBObject queryResult) { final Map<?, ?> result = queryResult.toMap(); final String subject = (String) result.get(SUBJECT); final String object = (String) result.get(OBJECT); final String objectType = (String) result.get(OBJECT_TYPE); final String predicate = (String) result.get(PREDICATE); final String context = (String) result.get(CONTEXT); DocumentVisibility documentVisibility = null; try {/* www .ja va 2s . co m*/ documentVisibility = DocumentVisibilityAdapter.toDocumentVisibility(queryResult); } catch (final MalformedDocumentVisibilityException e) { LOG.error("Unable to convert document visibility"); } final Long timestamp = (Long) result.get(TIMESTAMP); final String statementMetadata = (String) result.get(STATEMENT_METADATA); RyaType objectRya = null; if (objectType.equalsIgnoreCase(ANYURI.stringValue())) { objectRya = new RyaURI(object); } else { objectRya = new RyaType(factory.createURI(objectType), object); } final RyaStatement statement; if (!context.isEmpty()) { statement = new RyaStatement(new RyaURI(subject), new RyaURI(predicate), objectRya, new RyaURI(context)); } else { statement = new RyaStatement(new RyaURI(subject), new RyaURI(predicate), objectRya); } statement.setColumnVisibility(documentVisibility.flatten()); if (timestamp != null) { statement.setTimestamp(timestamp); } if (statementMetadata != null) { try { final StatementMetadata metadata = new StatementMetadata(statementMetadata); statement.setStatementMetadata(metadata); } catch (final Exception ex) { LOG.debug("Error deserializing metadata for statement", ex); } } return statement; }
From source file:org.aw20.mongoworkbench.eclipse.view.table.QueryData.java
License:Open Source License
public QueryData(FindMongoCommand fmcmd) { if (!fmcmd.isSuccess()) return;// w w w . j av a2s .c om findCommand = fmcmd; count = findCommand.getCount(); rightJustified = new HashSet<String>(); Set<String> columnSet = new HashSet<String>(); data = new ArrayList<Map>(); DBCursor cursor = fmcmd.getCursor(); while (cursor.hasNext()) { DBObject dbo = cursor.next(); columnSet.addAll(dbo.keySet()); if (dbo instanceof GridFSDBFile) { Map map = new HashMap(); map.put("_id", ((GridFSDBFile) dbo).getId()); map.put("chunkSize", ((GridFSDBFile) dbo).getChunkSize()); map.put("md5", ((GridFSDBFile) dbo).getMD5()); map.put("length", ((GridFSDBFile) dbo).getLength()); map.put("filename", ((GridFSDBFile) dbo).getFilename()); map.put("contentType", ((GridFSDBFile) dbo).getContentType()); if (((GridFSDBFile) dbo).getAliases() != null) map.put("aliases", ((GridFSDBFile) dbo).getAliases()); if (((GridFSDBFile) dbo).getMetaData() != null) map.put("metadata", ((GridFSDBFile) dbo).getMetaData()); map.put("uploadDate", ((GridFSDBFile) dbo).getUploadDate()); data.add(map); } else data.add(dbo.toMap()); } findCommand.close(); setColumns(columnSet, "_id"); }
From source file:org.datanucleus.store.mongodb.MongoDBSchemaHandler.java
License:Open Source License
private DBObject getIndexObjectForIndex(List<DBObject> indices, String idxName, DBObject idxObj, boolean unique) { if (indices == null || indices.isEmpty()) { return null; }//from w w w . j a v a 2 s . com Iterator<DBObject> idxIter = indices.iterator(); while (idxIter.hasNext()) { DBObject index = idxIter.next(); DBObject obj = null; String name = (String) index.get("name"); if (name.equals(idxName)) { obj = index; if (unique) { boolean flag = (Boolean) index.get("unique"); if (!flag) { continue; } } boolean equal = true; DBObject key = (DBObject) index.get("key"); if (key.toMap().size() != idxObj.toMap().size()) { equal = false; } else { Iterator<String> indicKeyIter = key.keySet().iterator(); while (indicKeyIter.hasNext()) { String fieldKey = indicKeyIter.next(); Object fieldValue = key.get(fieldKey); if (!idxObj.containsField(fieldKey)) { equal = false; } else { Object idxObjValue = idxObj.get(fieldKey); if (!idxObjValue.equals(fieldValue)) { equal = false; } } } } if (equal) { return obj; } } } return null; }
From source file:org.eclipse.birt.report.engine.emitter.mongodb.MongoDbEmitter.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w w w. j a v a2s . co m public void endTableGroup(ITableGroupContent arg0) throws BirtException { DBObject groupObj = groupObjStack.pop(); BasicDBList valueArray = new ArrayList<BasicDBList>(groupObj.toMap().values()).get(0); valueArray.addAll(dbObjectList); dbObjectList.clear(); if (groupObjStack.size() != 0) { DBObject parentGrpObj = groupObjStack.pop(); valueArray = new ArrayList<BasicDBList>(parentGrpObj.toMap().values()).get(0); valueArray.add(groupObj); groupObjStack.push(parentGrpObj); } else { groupObjectList.add(groupObj); } }
From source file:org.eclipselabs.restlet.mongo.MongoResource.java
License:Open Source License
@Get public JSONObject getJSON() throws MongoException, UnknownHostException { DBCollection collection = getCollection(); DBObject dbObject = collection .findOne(new BasicDBObject("_id", new ObjectId((String) getRequestAttributes().get("id")))); if (dbObject != null) return new JSONObject(dbObject.toMap()); else {/*from ww w . j a v a 2 s . c o m*/ getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return null; } }