List of usage examples for com.mongodb BasicDBObjectBuilder get
public DBObject get()
From source file:org.apache.rya.mongodb.document.visibility.DocumentVisibilityAdapter.java
License:Apache License
/** * Serializes a {@link DocumentVisibility} to a MongoDB {@link DBObject}. * @param documentVisibility the {@link DocumentVisibility} to be * serialized.//w ww . j av a2 s . c o m * @return The MongoDB {@link DBObject}. */ public static BasicDBObject toDBObject(final DocumentVisibility documentVisibility) { DocumentVisibility dv; if (documentVisibility == null) { dv = MongoDbRdfConstants.EMPTY_DV; } else { dv = documentVisibility; } Object[] dvArray = null; try { dvArray = DocumentVisibilityUtil.toMultidimensionalArray(dv); } catch (final DocumentVisibilityConversionException e) { log.error("Unable to convert document visibility"); } final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); builder.add(DOCUMENT_VISIBILITY_KEY, dvArray); return (BasicDBObject) builder.get(); }
From source file:org.apache.rya.mongodb.instance.MongoDetailsAdapter.java
License:Apache License
/** * Serializes {@link RyaDetails} to mongo {@link DBObject}. * @param details - The details to be serialized. * @return The mongo {@link DBObject}.// ww w . ja v a 2 s .com */ public static BasicDBObject toDBObject(final RyaDetails details) { Preconditions.checkNotNull(details); final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start() .add(INSTANCE_KEY, details.getRyaInstanceName()).add(VERSION_KEY, details.getRyaVersion()) .add(ENTITY_DETAILS_KEY, details.getEntityCentricIndexDetails().isEnabled()) //RYA-215 .add(GEO_DETAILS_KEY, details.getGeoIndexDetails().isEnabled()) .add(PCJ_DETAILS_KEY, toDBObject(details.getPCJIndexDetails())) .add(TEMPORAL_DETAILS_KEY, details.getTemporalIndexDetails().isEnabled()) .add(FREETEXT_DETAILS_KEY, details.getFreeTextIndexDetails().isEnabled()); if (details.getProspectorDetails().getLastUpdated().isPresent()) { builder.add(PROSPECTOR_DETAILS_KEY, details.getProspectorDetails().getLastUpdated().get()); } if (details.getJoinSelectivityDetails().getLastUpdated().isPresent()) { builder.add(JOIN_SELECTIVITY_DETAILS_KEY, details.getJoinSelectivityDetails().getLastUpdated().get()); } return (BasicDBObject) builder.get(); }
From source file:org.apache.rya.mongodb.instance.MongoDetailsAdapter.java
License:Apache License
private static DBObject toDBObject(final PCJIndexDetails pcjIndexDetails) { requireNonNull(pcjIndexDetails);/*from w w w .j a v a2 s .co m*/ final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); // Is Enabled builder.add(PCJ_ENABLED_KEY, pcjIndexDetails.isEnabled()); // Fluo Details if present. if (pcjIndexDetails.getFluoDetails().isPresent()) { builder.add(PCJ_FLUO_KEY, pcjIndexDetails.getFluoDetails().get().getUpdateAppName()); } // Add the PCJDetail objects. final List<DBObject> pcjDetailsList = new ArrayList<>(); for (final PCJDetails pcjDetails : pcjIndexDetails.getPCJDetails().values()) { pcjDetailsList.add(toDBObject(pcjDetails)); } builder.add(PCJ_PCJS_KEY, pcjDetailsList.toArray()); return builder.get(); }
From source file:org.apache.rya.mongodb.instance.MongoDetailsAdapter.java
License:Apache License
static DBObject toDBObject(final PCJDetails pcjDetails) { requireNonNull(pcjDetails);//from ww w .j av a 2s . c om final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); // PCJ ID builder.add(PCJ_ID_KEY, pcjDetails.getId()); // PCJ Update Strategy if present. if (pcjDetails.getUpdateStrategy().isPresent()) { builder.add(PCJ_UPDATE_STRAT_KEY, pcjDetails.getUpdateStrategy().get().name()); } // Last Update Time if present. if (pcjDetails.getLastUpdateTime().isPresent()) { builder.add(PCJ_LAST_UPDATE_KEY, pcjDetails.getLastUpdateTime().get()); } return builder.get(); }
From source file:org.apache.whirr.service.mongodb.MongoDBReplSetMemberClusterActionHandler.java
License:Apache License
/** * Returns a BasicDBObject containing a replica set config object, usable as param to rs.initiate(). * //ww w .ja v a2 s . c o m * @param memberInstances A set containing instances to be included in config object. * @throws IOException Thrown if the private IP of any instance is unavailable * */ private BasicDBObject generateReplicaSetConfig(Set<Cluster.Instance> memberInstances) throws IOException { BasicDBObject returnVal = new BasicDBObject(); if (this.replicaSetName != null) { returnVal.put("_id", this.replicaSetName); } else { returnVal.put("_id", "whirr"); } int counter = 0; ArrayList replicaSetMembers = new ArrayList(); for (Cluster.Instance member : memberInstances) { BasicDBObjectBuilder hostObj = BasicDBObjectBuilder.start().add("_id", counter); if (member.getRoles().contains(MongoDBArbiterClusterActionHandler.ROLE)) { //it's an arbiter, use port from config file hostObj.add("host", member.getPrivateAddress().getHostAddress() + ":" + this.arbiterPort); hostObj.add("arbiterOnly", true); } else { // it's a data member hostObj.add("host", member.getPrivateAddress().getHostAddress() + ":" + this.port); // throws an IOExc } replicaSetMembers.add(hostObj.get()); counter++; } returnVal.put("members", replicaSetMembers); return returnVal; }
From source file:org.axonframework.eventsourcing.eventstore.mongo.documentpercommit.CommitEntry.java
License:Apache License
/** * Returns the current CommitEntry as a mongo DBObject. * * @return DBObject representing the CommitEntry *///w w w .j a va 2 s. c o m public DBObject asDBObject(CommitEntryConfiguration commitConfiguration, EventEntryConfiguration eventConfiguration) { final BasicDBList events = new BasicDBList(); BasicDBObjectBuilder commitBuilder = BasicDBObjectBuilder.start() .add(eventConfiguration.aggregateIdentifierProperty(), aggregateIdentifier) .add(eventConfiguration.sequenceNumberProperty(), lastSequenceNumber) .add(commitConfiguration.firstSequenceNumberProperty(), firstSequenceNumber) .add(commitConfiguration.lastSequenceNumberProperty(), lastSequenceNumber) .add(eventConfiguration.timestampProperty(), lastTimestamp) .add(commitConfiguration.firstTimestampProperty(), firstTimestamp) .add(commitConfiguration.lastTimestampProperty(), lastTimestamp) .add(eventConfiguration.typeProperty(), aggregateType) .add(commitConfiguration.eventsProperty(), events); for (EventEntry eventEntry : eventEntries) { events.add(eventEntry.asDBObject(eventConfiguration)); } return commitBuilder.get(); }
From source file:org.envirocar.server.mongo.dao.MongoMeasurementDao.java
License:Open Source License
private Measurements getMongo(MeasurementFilter request) { BasicDBObjectBuilder q = new BasicDBObjectBuilder(); if (request.hasGeometry()) { q.add(MongoMeasurement.GEOMETRY, withinGeometry(request.getGeometry())); }/*from w w w . j av a 2 s .com*/ if (request.hasTrack()) { q.add(MongoMeasurement.TRACK, ref(request.getTrack())); } if (request.hasUser()) { q.add(MongoMeasurement.USER, ref(request.getUser())); } if (request.hasTemporalFilter()) { q.add(MongoMeasurement.TIME, MongoUtils.temporalFilter(request.getTemporalFilter())); } return query(q.get(), request.getPagination()); }
From source file:org.envirocar.server.mongo.dao.MongoStatisticsDao.java
License:Open Source License
private DBObject matches(StatisticsFilter request) { BasicDBObjectBuilder b = new BasicDBObjectBuilder(); BasicDBObjectBuilder match = b.push(Ops.MATCH); if (request.hasTrack()) { DBRef track = mongoDB.ref(request.getTrack()); match.add(MongoMeasurement.TRACK, track); }/*from w w w . j a va 2s . co m*/ if (request.hasUser()) { DBRef user = mongoDB.ref(request.getUser()); match.add(MongoMeasurement.USER, user); } if (request.hasSensor()) { MongoSensor sensor = (MongoSensor) request.getSensor(); match.add(SENSOR_ID_PATH, sensor.getId()); } return b.get(); }
From source file:org.forgerock.openidm.repo.mongodb.impl.DBHelper.java
License:Open Source License
private static void populateDefaultUser(DBCollection collection, JsonValue completeConfig, String user, String pwd, String roles) { DBObject query = (DBObject) JSON.parse("{\"_openidm_id\": \"" + user + "\"}"); if (collection.count(query) > 0) { return;/*from www. j ava 2s .co m*/ } Map<String, Object> defAdmin = new LinkedHashMap<String, Object>(); defAdmin.put("_id", user); defAdmin.put("_openidm_id", user); defAdmin.put("userName", user); try { defAdmin.put("password", JSON.parse(pwd)); } catch (com.mongodb.util.JSONParseException e) { defAdmin.put("password", pwd); } String[] role = roles.split(","); defAdmin.put("roles", role); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(defAdmin); DBObject o = builder.get(); collection.insert(o); }
From source file:org.forgerock.openidm.repo.mongodb.impl.MongoDBRepoService.java
License:Open Source License
/** * Creates a new object in the object set. * <p>//from ww w . jav a 2 s . c o m * This method sets the {@code _id} property to the assigned identifier for the object, * and the {@code _rev} property to the revised object version (For optimistic concurrency) * * @param fullId the client-generated identifier to use, or {@code null} if server-generated identifier is requested. * @param obj the contents of the object to create in the object set. * @throws NotFoundException if the specified id could not be resolved. * @throws ForbiddenException if access to the object or object set is forbidden. * @throws PreconditionFailedException if an object with the same ID already exists. */ @Override public void create(String fullId, Map<String, Object> obj) throws ObjectSetException { String localId = getLocalId(fullId); String type = getObjectType(fullId, false); if (fullId == null || localId == null) { throw new NotFoundException( "The repository requires clients to supply an identifier for the object to create. Full identifier: " + fullId + " local identifier: " + localId); } else if (type == null) { throw new NotFoundException( "The object identifier did not include sufficient information to determine the object type: " + fullId); } obj.put(DocumentUtil.TAG_ID, localId); obj.put(DocumentUtil.MONGODB_PRIMARY_KEY, localId); obj.put(DocumentUtil.TAG_REV, "0"); BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(obj); DBObject jo = builder.get(); jo = DocumentUtil.normalizeForWrite(jo); DBCollection collection = getCollection(type); collection.insert(jo); logger.debug("Completed create for id: {} revision: {}", fullId, jo.get(DocumentUtil.TAG_REV)); logger.trace("Create payload for id: {} doc: {}", fullId, jo); }