List of usage examples for com.mongodb BasicDBList get
public Object get(final String key)
From source file:org.jeo.mongo.GeoJSON.java
License:Open Source License
static Polygon toPolygon(BasicDBList list) { GeometryFactory gf = new GeometryFactory(); LinearRing shell = gf.createLinearRing(toCoordinates((BasicDBList) list.get(0))); LinearRing[] holes = list.size() > 1 ? new LinearRing[list.size() - 1] : null; for (int i = 1; i < list.size(); i++) { holes[i - 1] = gf.createLinearRing(toCoordinates((BasicDBList) list.get(i))); }/*from ww w. ja va 2 s . c om*/ return new GeometryFactory().createPolygon(shell, holes); }
From source file:org.jivesoftware.openfire.roster.DefaultRosterItemProvider.java
License:Open Source License
public Iterator<RosterItem> getItems(String username) { LinkedList<RosterItem> itemList = new LinkedList<RosterItem>(); try {//www . j a v a 2 s. c o m init(); DBCollection coll = db.getCollection("gUser"); BasicDBObject doc = new BasicDBObject("friends", 1); BasicDBObject q = new BasicDBObject("himId", username); DBCursor res = coll.find(q, doc); Iterator<DBObject> iter = res.iterator(); while (iter.hasNext()) { BasicDBList o = (BasicDBList) iter.next().get("friends"); for (int i = 0; i < o.size(); i++) { BasicDBObject dbo = (BasicDBObject) o.get(i); // information // SELECT jid, rosterID, sub, ask, recv, nick,version FROM // ofRoster WHERE username=? RosterItem item = new RosterItem(i + 1, new JID(dbo.getString("jid")), RosterItem.SubType.getTypeFromInt(dbo.getInt("sub")), RosterItem.AskType.getTypeFromInt(dbo.getInt("ask")), RosterItem.RecvType.getTypeFromInt(dbo.getInt("recv")), dbo.getString("name"), null); item.setCurrVersion(dbo.getLong("ver")); // Add the loaded RosterItem (ie. user contact) to the // result itemList.add(item); } System.out.println("sdsd"); } } catch (Exception e) { Log.warn("Error trying to get rows in ofRoster", e); } return itemList.iterator(); }
From source file:org.knowrob.knowrob_robcog.MongoRobcogQueries.java
License:Open Source License
/** * Query the Poses of the actor bones at the given timepoint (or the most recent one) */// w ww . ja va2 s . c o m public double[][] GetBonesPosesAt(String actorName, String timestampStr) { // transform the knowrob time to double with 3 decimal precision final double timestamp = (double) Math.round(parseTime_d(timestampStr) * 1000) / 1000; // $and list for querying the $match in the aggregation BasicDBList time_and_name = new BasicDBList(); // add the timestamp and the actor name time_and_name.add(new BasicDBObject("timestamp", new BasicDBObject("$lte", timestamp))); time_and_name.add(new BasicDBObject("actors.name", actorName)); // create the pipeline operations, first the $match DBObject match_time_and_name = new BasicDBObject("$match", new BasicDBObject("$and", time_and_name)); // sort the results in descending order on the timestamp (keep most recent result first) DBObject sort_desc = new BasicDBObject("$sort", new BasicDBObject("timestamp", -1)); // $limit the result to 1, we only need one pose DBObject limit_result = new BasicDBObject("$limit", 1); // $unwind actors in order to output only the queried actor DBObject unwind_actors = new BasicDBObject("$unwind", "$actors"); // $match for the given actor name from the unwinded actors DBObject match_actor = new BasicDBObject("$match", new BasicDBObject("actors.name", actorName)); // build the $projection operation DBObject proj_fields = new BasicDBObject("_id", 0); proj_fields.put("timestamp", 1); proj_fields.put("bones_pos", "$actors.bones.pos"); proj_fields.put("bones_rot", "$actors.bones.rot"); DBObject project = new BasicDBObject("$project", proj_fields); // run aggregation List<DBObject> pipeline = Arrays.asList(match_time_and_name, sort_desc, limit_result, unwind_actors, match_actor, project); AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100) .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build(); // get results Cursor cursor = this.MongoRobcogConn.coll.aggregate(pipeline, aggregationOptions); // Poses as dynamic array ArrayList<double[]> pose_list = new ArrayList<double[]>(); // if query has a response, return the pose if (cursor.hasNext()) { // get the first document as the next cursor and append the metadata to it BasicDBObject first_doc = (BasicDBObject) cursor.next(); // close cursor since we only care about one value cursor.close(); // get the pose BasicDBList pos_list = (BasicDBList) first_doc.get("bones_pos"); BasicDBList rot_list = (BasicDBList) first_doc.get("bones_rot"); // pos_list and rot_list length should be always the same for (int i = 0; i < pos_list.size(); ++i) { pose_list.add(new double[] { ((BasicDBObject) pos_list.get(i)).getDouble("x"), ((BasicDBObject) pos_list.get(i)).getDouble("y"), ((BasicDBObject) pos_list.get(i)).getDouble("z"), ((BasicDBObject) rot_list.get(i)).getDouble("w"), ((BasicDBObject) rot_list.get(i)).getDouble("x"), ((BasicDBObject) rot_list.get(i)).getDouble("y"), ((BasicDBObject) rot_list.get(i)).getDouble("z") }); } // cast from dynamic array to standard array return pose_list.toArray(new double[pose_list.size()][7]); } else { System.out.println("Java - GetBonesPoses - No results found, returning empty list.."); return new double[0][0]; } }
From source file:org.knowrob.knowrob_robcog.MongoRobcogQueries.java
License:Open Source License
/** * Query the Trajectories of the actor bones at the given timepoint (or the most recent one) *//*from w ww.j a va2s.co m*/ public double[][][] GetBonesTrajs(String actorName, String start, String end, double deltaT) { // transform the knowrob time to double with 3 decimal precision final double start_ts = (double) Math.round(parseTime_d(start) * 1000) / 1000; final double end_ts = (double) Math.round(parseTime_d(end) * 1000) / 1000; // create the pipeline operations, first with the $match check the times DBObject match_time = new BasicDBObject("$match", new BasicDBObject("timestamp", new BasicDBObject("$gte", start_ts).append("$lte", end_ts))); // $unwind actors in order to output only the queried actor DBObject unwind_actors = new BasicDBObject("$unwind", "$actors"); // $match for the given actor name from the unwinded actors DBObject match_actor = new BasicDBObject("$match", new BasicDBObject("actors.name", actorName)); // build the $projection operation DBObject proj_fields = new BasicDBObject("_id", 0); proj_fields.put("timestamp", 1); proj_fields.put("bones_pos", "$actors.bones.pos"); proj_fields.put("bones_rot", "$actors.bones.rot"); DBObject project = new BasicDBObject("$project", proj_fields); // run aggregation List<DBObject> pipeline = Arrays.asList(match_time, unwind_actors, match_actor, project); AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100) .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build(); // get results Cursor cursor = this.MongoRobcogConn.coll.aggregate(pipeline, aggregationOptions); // Trajectories as dynamic array (dynamic on the time part) ArrayList<double[][]> bone_trajs = new ArrayList<double[][]>(); // the number of bones int nr_bones = 0; // if the query returned nothing, get the most recent pose if (!cursor.hasNext()) { System.out.println("Java - GetBonesTrajs - No results found, returning most recent poses.."); // get the most recent pose bone_trajs.add(this.GetBonesPosesAt(actorName, start)); // set the nr of bones nr_bones = bone_trajs.get(0).length; // cast from dynamic array to standard array return bone_trajs.toArray(new double[bone_trajs.size()][nr_bones][7]); } // timestamp used for deltaT double prev_ts = 0; // if query has a response, return the pose while (cursor.hasNext()) { // get the first document as the next cursor and append the metadata to it BasicDBObject curr_doc = (BasicDBObject) cursor.next(); // get the curr timestamp double curr_ts = curr_doc.getDouble("timestamp"); // if time diff > then deltaT add position to trajectory if (curr_ts - prev_ts > deltaT) { // get the list of bones pos and rot BasicDBList pos_list = (BasicDBList) curr_doc.get("bones_pos"); BasicDBList rot_list = (BasicDBList) curr_doc.get("bones_rot"); // set the nr of bones nr_bones = pos_list.size(); // Poses as dynamic array (dynamic on the nr of bones part) ArrayList<double[]> pose_list = new ArrayList<double[]>(); // pos_list and rot_list length should be always the same for (int i = 0; i < nr_bones; ++i) { pose_list.add(new double[] { ((BasicDBObject) pos_list.get(i)).getDouble("x"), ((BasicDBObject) pos_list.get(i)).getDouble("y"), ((BasicDBObject) pos_list.get(i)).getDouble("z"), ((BasicDBObject) rot_list.get(i)).getDouble("w"), ((BasicDBObject) rot_list.get(i)).getDouble("x"), ((BasicDBObject) rot_list.get(i)).getDouble("y"), ((BasicDBObject) rot_list.get(i)).getDouble("z") }); } // cast from dynamic array to standard array bone_trajs.add(pose_list.toArray(new double[nr_bones][7])); prev_ts = curr_ts; } } // close cursor cursor.close(); // return the actor bones trajectories as float[][][] return bone_trajs.toArray(new double[bone_trajs.size()][nr_bones][7]); }
From source file:org.knowrob.knowrob_sim_games.MongoSimGames.java
License:Open Source License
/** * Get the poses of the model links meshes at the given timestamp * view results as rviz markers//from w w w. j a v a 2s .c o m */ public void ViewNestedMeshesAt(double timestamp, String model_name, String meshFolderPath, String markerID) { // $and list for querying the $match in the aggregation BasicDBList time_and_name = new BasicDBList(); // add the timestamp and the model name time_and_name.add(new BasicDBObject("timestamp", new BasicDBObject("$lte", timestamp))); time_and_name.add(new BasicDBObject("models.name", model_name)); // create the pipeline operations, first the $match DBObject match_time_and_name = new BasicDBObject("$match", new BasicDBObject("$and", time_and_name)); // sort the results in descending order on the timestamp (keep most recent result first) DBObject sort_desc = new BasicDBObject("$sort", new BasicDBObject("timestamp", -1)); // $limit the result to 1, we only need one pose DBObject limit_result = new BasicDBObject("$limit", 1); // $unwind models in order to output only the queried model DBObject unwind_models = new BasicDBObject("$unwind", "$models"); // $match for the given model name from the unwinded models DBObject match_model = new BasicDBObject("$match", new BasicDBObject("models.name", model_name)); // build the $projection operation DBObject proj_fields = new BasicDBObject("_id", 0); proj_fields.put("timestamp", 1); proj_fields.put("links_pos", "$models.links.pos"); proj_fields.put("links_rot", "$models.links.rot"); proj_fields.put("links_name", "$models.links.name"); DBObject project = new BasicDBObject("$project", proj_fields); // run aggregation List<DBObject> pipeline = Arrays.asList(match_time_and_name, sort_desc, limit_result, unwind_models, match_model, project); AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100) .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build(); Cursor cursor = this.coll.aggregate(pipeline, aggregationOptions); // get the result of the query if (cursor.hasNext()) { // get the first document as the next cursor BasicDBObject curr_doc = (BasicDBObject) cursor.next(); System.out.println(curr_doc); // get the list of links pos BasicDBList pos_list = (BasicDBList) curr_doc.get("links_pos"); BasicDBList rot_list = (BasicDBList) curr_doc.get("links_rot"); BasicDBList names_list = (BasicDBList) curr_doc.get("links_name"); // Dynamic arrays of the links positions, rotations and names List<double[]> translations = new ArrayList<double[]>(); List<double[]> orientations = new ArrayList<double[]>(); List<String> names = new ArrayList<String>(); // pos_list and rot_list and names_list length should be always the same for (int i = 0; i < pos_list.size(); ++i) { // add the pos's translations.add(new double[] { ((BasicDBObject) pos_list.get(i)).getDouble("x"), ((BasicDBObject) pos_list.get(i)).getDouble("y"), ((BasicDBObject) pos_list.get(i)).getDouble("z") }); // add the rots orientations.add(this.quatFromEulerRad(((BasicDBObject) rot_list.get(i)).getDouble("x"), ((BasicDBObject) rot_list.get(i)).getDouble("y"), ((BasicDBObject) rot_list.get(i)).getDouble("z"))); // add the names names.add((String) names_list.get(i)); } // create the nested mesh markers this.CreateNestedMeshMarkers(translations, orientations, names, meshFolderPath, markerID); } }
From source file:org.knowrob.knowrob_sim_games.MongoSimGames.java
License:Open Source License
/** * Get the positions of the model links at the given timestamp * view results as rviz markers/*from w w w.j a va 2s. c om*/ */ public void ViewLinksPositionsAt(String ts_str, String model_name, String markerID, String markerType, String color, float scale) { // transform the knowrob time to double with 3 decimal precision double timestamp = (double) Math.round((parseTime_d(ts_str) - TIME_OFFSET) * 1000) / 1000; // $and list for querying the $match in the aggregation BasicDBList time_and_name = new BasicDBList(); // add the timestamp and the model name time_and_name.add(new BasicDBObject("timestamp", new BasicDBObject("$lte", timestamp))); time_and_name.add(new BasicDBObject("models.name", model_name)); // create the pipeline operations, first the $match DBObject match_time_and_name = new BasicDBObject("$match", new BasicDBObject("$and", time_and_name)); // sort the results in descending order on the timestamp (keep most recent result first) DBObject sort_desc = new BasicDBObject("$sort", new BasicDBObject("timestamp", -1)); // $limit the result to 1, we only need one pose DBObject limit_result = new BasicDBObject("$limit", 1); // $unwind models in order to output only the queried model DBObject unwind_models = new BasicDBObject("$unwind", "$models"); // $match for the given model name from the unwinded models DBObject match_model = new BasicDBObject("$match", new BasicDBObject("models.name", model_name)); // build the $projection operation DBObject proj_fields = new BasicDBObject("_id", 0); proj_fields.put("timestamp", 1); proj_fields.put("links_pos", "$models.links.pos"); DBObject project = new BasicDBObject("$project", proj_fields); // run aggregation List<DBObject> pipeline = Arrays.asList(match_time_and_name, sort_desc, limit_result, unwind_models, match_model, project); AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100) .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build(); Cursor cursor = this.coll.aggregate(pipeline, aggregationOptions); // Traj as dynamic array ArrayList<Vector3d> positions = new ArrayList<Vector3d>(); // if cursor not empty, append matadata to the first doc if (cursor.hasNext()) { // get the first document as the next cursor BasicDBObject first_doc = (BasicDBObject) cursor.next(); // get the list of links pos BasicDBList pos_list = (BasicDBList) first_doc.get("links_pos"); // pos_list and rot_list length should be always the same for (int i = 0; i < pos_list.size(); ++i) { positions.add(new Vector3d(((BasicDBObject) pos_list.get(i)).getDouble("x"), ((BasicDBObject) pos_list.get(i)).getDouble("y"), ((BasicDBObject) pos_list.get(i)).getDouble("z"))); } } // if query returned no values for these timestamps, get the pose at the nearest timestamp else { System.out.println("Java - ViewLinksPositionsAt Query returned no results!'"); } // create the markers this.CreateMarkers(positions, markerID, markerType, color, scale); }
From source file:org.knowrob.knowrob_sim_games.MongoSimGames.java
License:Open Source License
/** * Get the positions of the model links at the given timestamp * view as rviz markers//from w w w .j av a 2s . c o m */ public void ViewLinksTrajs(String start_str, String end_str, String model_name, String markerID) { // transform the knowrob time to double with 3 decimal precision double start_ts = (double) Math.round((parseTime_d(start_str) - TIME_OFFSET) * 1000) / 1000; double end_ts = (double) Math.round((parseTime_d(end_str) - TIME_OFFSET) * 1000) / 1000; // create the pipeline operations, first with the $match check the times DBObject match_time = new BasicDBObject("$match", new BasicDBObject("timestamp", new BasicDBObject("$gte", start_ts).append("$lte", end_ts))); // $unwind models in order to output only the queried model DBObject unwind_models = new BasicDBObject("$unwind", "$models"); // $match for the given model name from the unwinded models DBObject match_model = new BasicDBObject("$match", new BasicDBObject("models.name", model_name)); // build the $projection operation DBObject proj_fields = new BasicDBObject("_id", 0); proj_fields.put("timestamp", 1); proj_fields.put("links_pos", "$models.links.pos"); DBObject project = new BasicDBObject("$project", proj_fields); // run aggregation List<DBObject> pipeline = Arrays.asList(match_time, unwind_models, match_model, project); AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100) .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build(); Cursor cursor = this.coll.aggregate(pipeline, aggregationOptions); // Traj as dynamic array ArrayList<Vector3d> trajs = new ArrayList<Vector3d>(); // if cursor not empty, append matadata to the first doc if (cursor.hasNext()) { // get the first document as the next cursor BasicDBObject first_doc = (BasicDBObject) cursor.next(); // get the list of links pos BasicDBList pos_list = (BasicDBList) first_doc.get("links_pos"); // pos_list and rot_list length should be always the same for (int i = 0; i < pos_list.size(); ++i) { trajs.add(new Vector3d(((BasicDBObject) pos_list.get(i)).getDouble("x"), ((BasicDBObject) pos_list.get(i)).getDouble("y"), ((BasicDBObject) pos_list.get(i)).getDouble("z"))); } } // if query returned no values for these timestamps, get the pose at the nearest timestamp else { this.ViewLinksPositionsAt(start_str, model_name, markerID); } // insert rest of trajectory while (cursor.hasNext()) { // get the current document BasicDBObject curr_doc = (BasicDBObject) cursor.next(); // get the list of links pos BasicDBList pos_list = (BasicDBList) curr_doc.get("links_pos"); // pos_list and rot_list length should be always the same for (int i = 0; i < pos_list.size(); ++i) { trajs.add(new Vector3d(((BasicDBObject) pos_list.get(i)).getDouble("x"), ((BasicDBObject) pos_list.get(i)).getDouble("y"), ((BasicDBObject) pos_list.get(i)).getDouble("z"))); } } // create the markers this.CreateMarkers(trajs, markerID); }
From source file:org.knowrob.knowrob_sim_games.MongoSimGames.java
License:Open Source License
/** * Get the positions of the model links at the given timestamp * view as rviz markers//w ww . jav a 2 s . c om */ public void ViewLinksTrajs(String start_str, String end_str, String model_name, String markerID, String markerType, String color, float scale, double deltaT) { // transform the knowrob time to double with 3 decimal precision double start_ts = (double) Math.round((parseTime_d(start_str) - TIME_OFFSET) * 1000) / 1000; double end_ts = (double) Math.round((parseTime_d(end_str) - TIME_OFFSET) * 1000) / 1000; // create the pipeline operations, first with the $match check the times DBObject match_time = new BasicDBObject("$match", new BasicDBObject("timestamp", new BasicDBObject("$gte", start_ts).append("$lte", end_ts))); // $unwind models in order to output only the queried model DBObject unwind_models = new BasicDBObject("$unwind", "$models"); // $match for the given model name from the unwinded models DBObject match_model = new BasicDBObject("$match", new BasicDBObject("models.name", model_name)); // build the $projection operation DBObject proj_fields = new BasicDBObject("_id", 0); proj_fields.put("timestamp", 1); proj_fields.put("links_pos", "$models.links.pos"); DBObject project = new BasicDBObject("$project", proj_fields); // run aggregation List<DBObject> pipeline = Arrays.asList(match_time, unwind_models, match_model, project); AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100) .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build(); Cursor cursor = this.coll.aggregate(pipeline, aggregationOptions); // Traj as dynamic array ArrayList<Vector3d> trajs = new ArrayList<Vector3d>(); double prev_ts = 0; // if cursor not empty, append matadata to the first doc if (cursor.hasNext()) { // get the first document as the next cursor BasicDBObject first_doc = (BasicDBObject) cursor.next(); // get the list of links pos BasicDBList pos_list = (BasicDBList) first_doc.get("links_pos"); // get the timestamp prev_ts = first_doc.getDouble("timestamp"); // pos_list and rot_list length should be always the same for (int i = 0; i < pos_list.size(); ++i) { trajs.add(new Vector3d(((BasicDBObject) pos_list.get(i)).getDouble("x"), ((BasicDBObject) pos_list.get(i)).getDouble("y"), ((BasicDBObject) pos_list.get(i)).getDouble("z"))); } } // if query returned no values for these timestamps, get the pose at the nearest timestamp else { this.ViewLinksPositionsAt(start_str, model_name, markerID, markerType, color, scale); } // insert rest of trajectory while (cursor.hasNext()) { // get the current document BasicDBObject curr_doc = (BasicDBObject) cursor.next(); // get the list of links pos BasicDBList pos_list = (BasicDBList) curr_doc.get("links_pos"); double curr_ts = curr_doc.getDouble("timestamp"); // if time diff > then deltaT add position to trajectory if (curr_ts - prev_ts > deltaT) { // pos_list and rot_list length should be always the same for (int i = 0; i < pos_list.size(); ++i) { trajs.add(new Vector3d(((BasicDBObject) pos_list.get(i)).getDouble("x"), ((BasicDBObject) pos_list.get(i)).getDouble("y"), ((BasicDBObject) pos_list.get(i)).getDouble("z"))); } prev_ts = curr_ts; } } // create the markers this.CreateMarkers(trajs, markerID, markerType, color, scale); }
From source file:org.knowrob.knowrob_sim_games.MongoSimGames.java
License:Open Source License
/** * Get the positions of the model links at the given timestamp *//* w w w .j a va2 s. c om*/ public List<Point3d> GetLinksPositions(String ts_str, String model_name) { // list of all the links positions List<Point3d> links_positions = new ArrayList<Point3d>(); // transform the knowrob time to double with 3 decimal precision double timestamp = (double) Math.round((parseTime_d(ts_str) - TIME_OFFSET) * 1000) / 1000; // remove the knowrob namespace (http://knowrob.org/kb/knowrob.owl#) form the model // String model_name = kr_model_name.split("#")[1]; //System.out.println("Java - timestamp: " + timestamp + " model name: " + model_name); // $and list for querying the $match in the aggregation BasicDBList time_and_name = new BasicDBList(); // add the timestamp and the model name time_and_name.add(new BasicDBObject("timestamp", new BasicDBObject("$lte", timestamp))); time_and_name.add(new BasicDBObject("models.name", model_name)); // create the pipeline operations, first the $match DBObject match_time_and_name = new BasicDBObject("$match", new BasicDBObject("$and", time_and_name)); // sort the results in descending order on the timestamp (keep most recent result first) DBObject sort_desc = new BasicDBObject("$sort", new BasicDBObject("timestamp", -1)); // $limit the result to 1, we only need one pose DBObject limit_result = new BasicDBObject("$limit", 1); // $unwind models in order to output only the queried model DBObject unwind_models = new BasicDBObject("$unwind", "$models"); // $match for the given model name from the unwinded models DBObject match_model = new BasicDBObject("$match", new BasicDBObject("models.name", model_name)); // build the $projection operation DBObject proj_fields = new BasicDBObject("_id", 0); proj_fields.put("timestamp", 1); proj_fields.put("links_pos", "$models.links.pos"); DBObject project = new BasicDBObject("$project", proj_fields); // run aggregation List<DBObject> pipeline = Arrays.asList(match_time_and_name, sort_desc, limit_result, unwind_models, match_model, project); AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100) .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build(); Cursor cursor = this.coll.aggregate(pipeline, aggregationOptions); // if query has a response, append metadata to it if (cursor.hasNext()) { // get the first doc BasicDBObject first_doc = (BasicDBObject) cursor.next(); // get the positions array BasicDBList links_pos_arr = (BasicDBList) first_doc.get("links_pos"); // iterate the results for (int i = 0; i < links_pos_arr.size(); i++) { // current position Point3d pos = new Point3d(); // set the positions pos.x = ((BasicDBObject) links_pos_arr.get(i)).getDouble("x"); pos.y = ((BasicDBObject) links_pos_arr.get(i)).getDouble("y"); pos.z = ((BasicDBObject) links_pos_arr.get(i)).getDouble("z"); // add position to the list links_positions.add(pos); } } return links_positions; }
From source file:org.mongodb.morphia.mapping.Mapper.java
License:Open Source License
/** * <p> Converts a java object to a mongo-compatible object (possibly a DBObject for complex mappings). Very similar to {@link * Mapper#toDBObject} </p> <p> Used (mainly) by query/update operations </p> *///from ww w . j a v a 2 s.c o m public Object toMongoObject(final MappedField mf, final MappedClass mc, final Object value) { Object mappedValue = value; //convert the value to Key (DBRef) if the field is @Reference or type is Key/DBRef, or if the destination class is an @Entity if (isAssignable(mf, value) || isEntity(mc)) { try { if (value instanceof Iterable) { MappedClass mapped = getMappedClass(mf.getSubClass()); if (mapped != null && (Key.class.isAssignableFrom(mapped.getClazz()) || mapped.getEntityAnnotation() != null)) { mappedValue = getDBRefs(mf, (Iterable) value); } else { if (mf.hasAnnotation(Reference.class)) { mappedValue = getDBRefs(mf, (Iterable) value); } else { mappedValue = toMongoObject(value, false); } } } else { final Key<?> key = (value instanceof Key) ? (Key<?>) value : getKey(value); if (key == null) { mappedValue = toMongoObject(value, false); } else { mappedValue = keyToRef(key); if (mappedValue == value) { throw new ValidationException("cannot map to @Reference/Key<T>/DBRef field: " + value); } } } } catch (Exception e) { LOG.error("Error converting value(" + value + ") to reference.", e); mappedValue = toMongoObject(value, false); } } else if (mf != null && mf.hasAnnotation(Serialized.class)) { //serialized try { mappedValue = Serializer.serialize(value, !mf.getAnnotation(Serialized.class).disableCompression()); } catch (IOException e) { throw new RuntimeException(e); } } else if (value instanceof DBObject) { //pass-through mappedValue = value; } else { mappedValue = toMongoObject(value, EmbeddedMapper.shouldSaveClassName(value, mappedValue, mf)); if (mappedValue instanceof BasicDBList) { final BasicDBList list = (BasicDBList) mappedValue; if (list.size() != 0) { if (!EmbeddedMapper.shouldSaveClassName(extractFirstElement(value), list.get(0), mf)) { for (Object o : list) { if (o instanceof DBObject) { ((DBObject) o).removeField(CLASS_NAME_FIELDNAME); } } } } } else if (mappedValue instanceof DBObject && !EmbeddedMapper.shouldSaveClassName(value, mappedValue, mf)) { ((DBObject) mappedValue).removeField(CLASS_NAME_FIELDNAME); } } return mappedValue; }