List of usage examples for com.mongodb DBObject removeField
Object removeField(String key);
From source file:v7db.files.mongodb.V7GridFS.java
License:Open Source License
private void updateContents(DBObject metaData, InputStream contents) throws IOException { Object fileId = metaData.get("_id"); ContentPointer oldContents = getContentPointer(metaData); String filename = (String) metaData.get("filename"); String contentType = (String) metaData.get("contentType"); BSONObject newContent = storage.insertContentsAndBackRefs(contents, fileId, filename, contentType); // check if it has changed ContentPointer newContents = getContentPointer(newContent); if (newContents.contentEquals(oldContents)) return;//from www . jav a 2 s. c o m metaData.removeField("sha"); metaData.removeField("length"); metaData.removeField("in"); metaData.putAll(newContent); updateMetaData(metaData); }
From source file:v7db.files.mongodb.V7GridFS.java
License:Open Source License
private void updateContents(DBObject metaData, byte[] contents, int offset, int len) throws IOException { Object fileId = metaData.get("_id"); ContentPointer oldContents = getContentPointer(metaData); String filename = (String) metaData.get("filename"); String contentType = (String) metaData.get("contentType"); // for up to 55 bytes, storing the complete file inline // takes less space than just storing the SHA-1 and length // 20 (SHA-1) + 1 (sha - in) + 6 (length) + 4 (int32) + 2*12 // (ObjectId back-references) BSONObject newContent = storage.inlineOrInsertContentsAndBackRefs(55, contents, offset, len, fileId, filename, contentType);//from www . j av a2 s .c o m // check if it has changed ContentPointer newContents = getContentPointer(newContent); if (newContents.contentEquals(oldContents)) return; metaData.removeField("sha"); metaData.removeField("length"); metaData.removeField("in"); metaData.putAll(newContent); updateMetaData(metaData); }
From source file:xbdd.webapp.resource.feature.AdminUtils.java
License:Apache License
@DELETE @Path("/delete/{product}") @Produces("application/json") public Response softDeleteEntireProduct(@PathParam("product") final String product, @Context final HttpServletRequest req, @Context final HttpServletResponse response) throws IOException { final DB db = this.client.getDB("bdd"); final DBCollection collection = db.getCollection("summary"); final DBCollection targetCollection = db.getCollection("deletedSummary"); final BasicDBObject query = new BasicDBObject("coordinates.product", product); final DBCursor cursor = collection.find(query); DBObject doc; while (cursor.hasNext()) { doc = cursor.next();/*from w w w .j a v a 2 s .co m*/ //kill the old id doc.removeField("_id"); try { targetCollection.insert(doc); } catch (Throwable e) { return Response.status(500).build(); } } collection.remove(query); return Response.ok().build(); }
From source file:xbdd.webapp.resource.feature.AdminUtils.java
License:Apache License
@DELETE @Path("/delete/{product}/{version}") @Produces("application/json") public Response softDeleteSingleVersion(@PathParam("product") final String product, @PathParam("version") final String version, @Context final HttpServletRequest req, @Context final HttpServletResponse response) throws IOException { final DB db = this.client.getDB("bdd"); final DBCollection collection = db.getCollection("summary"); final DBCollection targetCollection = db.getCollection("deletedSummary"); final Pattern productReg = java.util.regex.Pattern.compile("^" + product + "/" + version + "$"); final BasicDBObject query = new BasicDBObject("_id", productReg); final DBCursor cursor = collection.find(query); DBObject doc; while (cursor.hasNext()) { doc = cursor.next();//from www.j ava 2 s . c o m //kill the old id doc.removeField("_id"); try { targetCollection.insert(doc); } catch (Throwable e) { return Response.status(500).build(); } } collection.remove(query); return Response.ok().build(); }
From source file:xbdd.webapp.resource.feature.Feature.java
License:Apache License
@SuppressWarnings("unchecked") protected void updateTestingTips(final DB db, final Coordinates coordinates, final String featureId, final DBObject feature) { final DBCollection tips = db.getCollection("testingTips"); final List<DBObject> elements = (List<DBObject>) feature.get("elements"); for (final DBObject scenario : elements) { if (scenario.get("testing-tips") != null) { final String tipText = (String) scenario.get("testing-tips"); final String scenarioId = (String) scenario.get("id"); final BasicDBObject tipQuery = coordinates.getTestingTipsCoordinatesQueryObject(featureId, scenarioId);/*from w w w.j a v a 2s. c om*/ DBObject oldTip = null; // get the most recent tip that is LTE to the current coordinates. i.e. sort in reverse chronological order and take the // first item (if one exists). final DBCursor oldTipCursor = tips.find(tipQuery) .sort(new BasicDBObject("coordinates.major", -1).append("coordinates.minor", -1) .append("coordinates.servicePack", -1).append("coordinates.build", -1)) .limit(1); try { if (oldTipCursor.hasNext()) { oldTip = oldTipCursor.next(); } } finally { oldTipCursor.close(); } if (oldTip != null) { // if there is an old tip... final String oldTipText = (String) oldTip.get("testing-tips"); // get it and... if (!tipText.equals(oldTipText)) {// compare it to the current tip to it, if they're not the same... final DBObject newTip = new BasicDBObject("testing-tips", tipText) .append("coordinates", coordinates.getTestingTipsCoordinates(featureId, scenarioId)) .append("_id", coordinates.getTestingTipsId(featureId, scenarioId)); tips.save(newTip);// then save this as a new tip. } } else { // no prior tip exists, add this one. final DBObject newTip = new BasicDBObject("testing-tips", tipText) .append("coordinates", coordinates.getTestingTipsCoordinates(featureId, scenarioId)) .append("_id", coordinates.getTestingTipsId(featureId, scenarioId)); tips.save(newTip);// then save this as a new tip. } } scenario.removeField("testing-tips"); } }