List of usage examples for com.mongodb DBRef getId
public Object getId()
From source file:com.amertkara.tinkerpop.blueprints.impl.mongodb.MongoDBEdge.java
License:Apache License
public MongoDBVertex getOutV() { DBRef outV = (DBRef) this.rawElement.get(MongoDBConstants.FIELD_OUTV); Document vertex;/*from w w w.j a va 2s . co m*/ try { vertex = this.graph.getVertexCollection().find(new Document(MongoDBConstants.FIELD_ID, outV.getId())) .iterator().next(); } catch (NoSuchElementException nsee) { logger.warn("outV of the edge " + getId() + " doesn't exist. Vertex id is " + outV.getId()); return null; } return new MongoDBVertex(vertex, graph); }
From source file:com.amertkara.tinkerpop.blueprints.impl.mongodb.MongoDBEdge.java
License:Apache License
public MongoDBVertex getinV() { DBRef inV = (DBRef) this.rawElement.get(MongoDBConstants.FIELD_INV); Document vertex;//from w w w . j a va 2s .com try { vertex = this.graph.getVertexCollection().find(new Document(MongoDBConstants.FIELD_ID, inV.getId())) .iterator().next(); } catch (NoSuchElementException nsee) { logger.warn("inV of the edge " + getId() + " doesn't exist. Vertex id is " + inV.getId()); return null; } return new MongoDBVertex(vertex, graph); }
From source file:com.amertkara.tinkerpop.blueprints.impl.mongodb.MongoDBVertex.java
License:Apache License
@Override public Iterable<Vertex> getVertices(Direction direction, String... labels) { List<Integer> ids = new ArrayList<Integer>(); Iterator<Document> it; FindIterable<Document> result; if (direction.equals(Direction.OUT)) { Document query = new Document(MongoDBConstants.FIELD_INV, new DBRef(MongoDBConstants.DEFAULT_VERTEX_COLLECTION, getId())) .append(MongoDBConstants.FIELD_LABEL, new Document("$in", Arrays.asList(labels))); result = this.graph.getEdgeCollection().find(query); it = result.iterator();//from w ww. j ava2s .c o m while (it.hasNext()) { Document document = (Document) it.next(); DBRef inV = (DBRef) document.get(MongoDBConstants.FIELD_OUTV); ids.add((Integer) inV.getId()); } } else if (direction.equals(Direction.IN)) { Document query = new Document(MongoDBConstants.FIELD_OUTV, new DBRef(MongoDBConstants.DEFAULT_VERTEX_COLLECTION, getId())) .append(MongoDBConstants.FIELD_LABEL, new Document("$in", Arrays.asList(labels))); result = this.graph.getEdgeCollection().find(query); it = result.iterator(); while (it.hasNext()) { Document document = (Document) it.next(); DBRef outV = (DBRef) document.get(MongoDBConstants.FIELD_INV); ids.add((Integer) outV.getId()); } } else { Document query = new Document("$or", Arrays.asList( new Document(MongoDBConstants.FIELD_OUTV, new DBRef(MongoDBConstants.DEFAULT_VERTEX_COLLECTION, getId())).append( MongoDBConstants.FIELD_LABEL, new Document("$in", Arrays.asList(labels))), new Document(MongoDBConstants.FIELD_INV, new DBRef(MongoDBConstants.DEFAULT_VERTEX_COLLECTION, getId())).append( MongoDBConstants.FIELD_LABEL, new Document("$in", Arrays.asList(labels))))); result = this.graph.getEdgeCollection().find(query); it = result.iterator(); while (it.hasNext()) { Document document = (Document) it.next(); DBRef inV = (DBRef) document.get(MongoDBConstants.FIELD_INV); DBRef outV = (DBRef) document.get(MongoDBConstants.FIELD_OUTV); if (inV.getId() != getId()) { ids.add((Integer) inV.getId()); } else { ids.add((Integer) outV.getId()); } } } return new MongoDBVertexIterable(this.graph.getVertexCollection() .find(new Document(MongoDBConstants.FIELD_ID, new Document("$in", ids))), graph); }
From source file:com.bugull.mongo.utils.ReferenceUtil.java
License:Apache License
public static String fromDbReference(Ref ref, Object value) { String result = null;//from w w w.ja v a 2 s .c o m if (ref.reduced()) { result = value.toString(); } else { DBRef dbRef = (DBRef) value; result = dbRef.getId().toString(); } return result; }
From source file:com.bugull.mongo.utils.ReferenceUtil.java
License:Apache License
public static String fromDbReference(RefList refList, Object value) { String result = null;/* w w w. ja va 2 s . co m*/ if (refList.reduced()) { result = value.toString(); } else { DBRef dbRef = (DBRef) value; result = dbRef.getId().toString(); } return result; }
From source file:com.github.jmkgreen.morphia.mapping.DefaultMapper.java
License:Open Source License
public <T> Key<T> refToKey(DBRef ref) { if (ref == null) return null; return new Key<T>(ref.getRef(), ref.getId()); }
From source file:com.google.code.morphia.mapping.Mapper.java
License:Open Source License
public <T> Key<T> refToKey(DBRef ref) { if (ref == null) return null; Key<T> key = new Key<T>(ref.getRef(), ref.getId()); return key;/* w w w . j a v a2s.c o m*/ }
From source file:com.restfeel.controller.rest.EntityDataController.java
License:Apache License
private DBObject dbRefToRel(DBRef obj) { return new BasicDBObject().append("_rel", new BasicDBObject().append("entity", (obj.toString()).split("_")[1]).append("_id", ((ObjectId) obj.getId()).toHexString())); }
From source file:com.restfeel.controller.rest.EntitySessionController.java
License:Apache License
private DBObject dbRefToRel(DBRef obj) { return new BasicDBObject().append("_rel", new BasicDBObject().append("entity", ((String) obj.getId()).split("_")[1]).append("_id", ((ObjectId) obj.getId()).toHexString())); }
From source file:com.sonyericsson.jenkins.plugins.bfa.db.MongoDBKnowledgeBase.java
License:Open Source License
@Override public List<ObjectCountPair<String>> getNbrOfFailureCausesPerId(GraphFilterBuilder filter, int maxNbr) { List<ObjectCountPair<String>> nbrOfFailureCausesPerId = new ArrayList<ObjectCountPair<String>>(); DBObject matchFields = generateMatchFields(filter); DBObject match = new BasicDBObject("$match", matchFields); DBObject unwind = new BasicDBObject("$unwind", "$failureCauses"); DBObject groupFields = new BasicDBObject(); groupFields.put("_id", "$failureCauses.failureCause"); groupFields.put("number", new BasicDBObject("$sum", 1)); DBObject group = new BasicDBObject("$group", groupFields); DBObject sort = new BasicDBObject("$sort", new BasicDBObject("number", -1)); DBObject limit = null;/*from w w w.j a v a2s . co m*/ if (maxNbr > 0) { limit = new BasicDBObject("$limit", maxNbr); } AggregationOutput output; try { if (limit == null) { output = getStatisticsCollection().aggregate(match, unwind, group, sort); } else { output = getStatisticsCollection().aggregate(match, unwind, group, sort, limit); } for (DBObject result : output.results()) { DBRef failureCauseRef = (DBRef) result.get("_id"); if (failureCauseRef != null) { Integer number = (Integer) result.get("number"); String id = failureCauseRef.getId().toString(); nbrOfFailureCausesPerId.add(new ObjectCountPair<String>(id, number)); } } } catch (Exception e) { logger.fine("Unable to get failure causes per id"); e.printStackTrace(); } return nbrOfFailureCausesPerId; }