List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start()
From source file:org.envirocar.server.mongo.convert.DimensionedNumberConverter.java
License:Open Source License
@Override public Object encode(Object value, MappedField optionalExtraInfo) { if (value == null) { return null; }/*from w ww .java 2 s . c o m*/ DimensionedNumber dn = (DimensionedNumber) value; return BasicDBObjectBuilder.start().add("value", dn.value().toString()).add("unit", dn.unit()).get(); }
From source file:org.ff4j.store.PropertyStoreMongoDB.java
License:Apache License
/** {@inheritDoc} */ public void clear() { collection.remove(BasicDBObjectBuilder.start().get()); }
From source file:org.fusesource.bai.backend.mongo.MongoDBBackend.java
License:Apache License
private void digestExchangeCreatedEvent(AuditEvent ev) { // filter: { _id : <breadcrumbId> } // updateObj: { $push : { exchanges: { in: <inmessage>, inTimestamp: <inTimestamp> } } } // an exchange has been created (by a consumer or by an EIP - we probably don't want to track the latter, so we need to find a way) // perhaps: if an exchange already exists with the same unit of work, of if an exchange with created='yes' already exists for that route, discard this message // ExchangeCreated will create a record in the per-route collection, *ONLY IF* a record doesn't already exist // if a record exists, it means that an EIP or processor has created a new Exchange, which will be sent later on, so we'll intercept it at that event Object inMessage = null;/*from www. j av a2 s . c o m*/ try { inMessage = convertPayload(ev.getExchange().getIn().getBody(), ev.getExchange()); } catch (Exception e) { // nothing } DBObject exchObj = BasicDBObjectBuilder.start().append("endpointUri", ev.getEndpointURI()) .append("startTimestamp", ev.getTimestamp()).append("status", "in_progress") .append("exchangeId", ev.getEvent().getExchange().getExchangeId()) .append("exchangePattern", ev.getEvent().getExchange().getPattern().toString()) .append("in", inMessage).append("dispatchId", ev.getEvent().getExchange().getProperty(AuditConstants.DISPATCH_ID, String.class)) .get(); DBObject toInsert = BasicDBObjectBuilder.start().append("_id", ev.getBreadCrumbId()) .append("input", Arrays.asList(exchObj)).get(); addCurrentRouteIdIfNeeded(ev, exchObj); // insert the record => if it already exists, Mongo will ignore the insert collectionFor(ev).insert(toInsert); }
From source file:org.fusesource.bai.backend.mongo.MongoDBBackend.java
License:Apache License
private void digestExchangeCompletedEvent(AuditEvent ev) { DBObject filter = BasicDBObjectBuilder.start().append("_id", ev.getBreadCrumbId()) .append("input.endpointUri", ev.getEndpointURI()) .append("input.exchangeId", ev.getExchange().getExchangeId()).append("exchanges.dispatchId", ev.getEvent().getExchange().getProperty(AuditConstants.DISPATCH_ID, String.class)) .get();/*from w ww .j a v a 2 s. com*/ DBObject toApply = new BasicDBObject(); toApply.put("$set", new BasicDBObject()); DBObject toSet = (BasicDBObject) toApply.get("$set"); toSet.put("input.$.endTimestamp", ev.getTimestamp()); toSet.put("input.$.status", "finished"); // TODO: what if the exchange pattern changed while routing? // if the exchange pattern is InOut, first check if there's an out message, if not, dump the in message as the out (since this is what Camel's PipelineProcessor // will do internally anyway) if (ev.getEvent().getExchange().getPattern() == ExchangePattern.InOut) { Object outBody = null; try { outBody = ev.getExchange().hasOut() ? ev.getExchange().getOut().getBody() : ev.getExchange().getIn().getBody(); // it's okay to insert a null value if the he pattern was InOut toSet.put("input.$.out", convertPayload(outBody, ev.getExchange())); toSet.put("input.$.originalOut", typeConverter.convertTo(String.class, outBody)); } catch (Exception e) { // nothing } } // update the record, only if the filter criteria is met collectionFor(ev).update(filter, toApply); }
From source file:org.fusesource.bai.backend.mongo.MongoDBBackend.java
License:Apache License
private void digestExchangeSentEvent(AuditEvent ev) { DBObject filter = BasicDBObjectBuilder.start().append("_id", ev.getBreadCrumbId()) .append("exchanges.endpointUri", ev.getEndpointURI()) .append("exchanges.exchangeId", ev.getExchange().getExchangeId()).append("exchanges.dispatchId", ev.getEvent().getExchange().getProperty(AuditConstants.DISPATCH_ID, String.class)) .get();/*from ww w . jav a 2s . com*/ DBObject toApply = BasicDBObjectBuilder.start().push("$set") .append("exchanges.$.endTimestamp", ev.getTimestamp()).append("exchanges.$.status", "finished") .get(); // if the exchange pattern is InOut, first check if there's an out message, if not, dump the in message as the out (since this is what Camel's PipelineProcessor // will do internally anyway) if (ev.getEvent().getExchange().getPattern() == ExchangePattern.InOut) { Object outBody = null; try { outBody = ev.getExchange().hasOut() ? ev.getExchange().getOut().getBody() : ev.getExchange().getIn().getBody(); // it's okay to insert a null value if the he pattern was InOut ((BasicDBObject) toApply.get("$set")).put("exchanges.$.out", convertPayload(outBody, ev.getExchange())); } catch (Exception e) { // nothing } } // update the record, only if the filter criteria is met collectionFor(ev).update(filter, toApply); }
From source file:org.fusesource.bai.backend.mongo.MongoDBBackend.java
License:Apache License
private void digestEndpointFailureEvent(AuditEvent ev) { DBObject filter = new BasicDBObject("_id", ev.getBreadCrumbId()); // 1. push the failure into endpointFailures DBObject toUpdate = BasicDBObjectBuilder.start().push("$push").push("endpointFailures") .append("endpointUri", ev.getEndpointURI()).append("exception", ev.getException().toString()) .append("timestamp", ev.getTimestamp()).get(); collectionFor(ev).update(filter, toUpdate); addCurrentRouteIdIfNeeded(ev, (DBObject) ((DBObject) toUpdate.get("$push")).get("endpointFailures")); // 2. Then set the status of the exchange to failed - if it was an exchange sent from this route filter.put("exchanges.endpointUri", ev.getEndpointURI()); filter.put("exchanges.exchangeId", ev.getEvent().getExchange().getExchangeId()); filter.put("exchanges.dispatchId", ev.getEvent().getExchange().getProperty(AuditConstants.DISPATCH_ID, String.class)); toUpdate = BasicDBObjectBuilder.start().push("$set").append("exchanges.$.status", "failed") .append("exchanges.$.failTimestamp", ev.getTimestamp()).get(); // if an exception is informed, we add it too if (ev.getException() != null) { ((BasicDBObject) toUpdate.get("$set")).put("exchanges.$.exception", ev.getException().toString()); }//from ww w .j a v a 2 s. c om collectionFor(ev).update(filter, toUpdate); // 3. Then set the status of the exchange to failed - if it was the incoming exchange into the route filter.put("in.endpointUri", ev.getEndpointURI()); filter.put("in.exchangeId", ev.getEvent().getExchange().getExchangeId()); filter.put("in.dispatchId", ev.getEvent().getExchange().getProperty(AuditConstants.DISPATCH_ID, String.class)); toUpdate = BasicDBObjectBuilder.start().push("$set").append("in.$.status", "failed") .append("in.$.failTimestamp", ev.getTimestamp()).get(); // if an exception is informed, we add it too if (ev.getException() != null) { ((BasicDBObject) toUpdate.get("$set")).put("in.$.exception", ev.getException().toString()); } collectionFor(ev).update(filter, toUpdate); }
From source file:org.fusesource.bai.backend.mongo.MongoDBBackend.java
License:Apache License
private void digestEndpointRedeliveryEvent(AuditEvent ev) { DBObject filter = new BasicDBObject("_id", ev.getBreadCrumbId()); // we don't know what processor caused it, because this info is not on the event, so just push an element into the processorRedeliveries array for the time being DBObject toPush = BasicDBObjectBuilder.start().push("$push").push("endpointRedeliveries") .append("exchangeId", ev.getExchange().getExchangeId()).append("endpointURI", ev.getEndpointURI()) .append("timestamp", ev.getTimestamp()).append("exception", ev.getException().toString()) .append("attempt", ev.getExchange().getProperty(Exchange.REDELIVERY_COUNTER)).get(); collectionFor(ev).update(filter, toPush); }
From source file:org.fusesource.bai.backend.mongo.MongoDBBackend.java
License:Apache License
private void digestProcessorRedeliveryEvent(AuditEvent ev) { DBObject filter = new BasicDBObject("_id", ev.getBreadCrumbId()); // we don't know what processor caused it, because this info is not on the event, so just push an element into the processorRedeliveries array for the time being DBObject toPush = BasicDBObjectBuilder.start().push("$push").push("processorRedeliveries") .append("exchangeId", ev.getExchange().getExchangeId()).append("timestamp", ev.getTimestamp()) .append("exception", ev.getException().toString()) .append("attempt", ev.getExchange().getProperty(Exchange.REDELIVERY_COUNTER)).get(); collectionFor(ev).update(filter, toPush); }
From source file:org.geogit.storage.mongo.MongoGraph.java
License:Open Source License
public Edge addEdge(Object id, Vertex out, Vertex in, String label) { if (label == null) { throw new IllegalArgumentException("Edge label may not be null"); }/*from w ww . j ava2 s . co m*/ final BasicDBObjectBuilder builder; if (id == null) { builder = BasicDBObjectBuilder.start(); } else { builder = BasicDBObjectBuilder.start("_id", id); } DBObject edge = builder.append("_out", out.getId()).append("_in", in.getId()).append("_label", label).get(); WriteResult result = collection.save(edge); if (result.getLastError().ok()) { return new MEdge(edge); } else { throw new RuntimeException("Storing edge to mongo failed: " + result.getError()); } }
From source file:org.geogit.storage.mongo.MongoGraph.java
License:Open Source License
public Iterable<Edge> getEdges() { DBObject query = BasicDBObjectBuilder.start().push("_in").append("$exists", 1).pop().push("_out") .append("$exists", 1).pop().get(); return getEdges(query); }