List of usage examples for com.mongodb BasicDBObject append
@Override public BasicDBObject append(final String key, final Object val)
From source file:com.cognitive.cds.invocation.mongo.WorkProductDao.java
License:Apache License
public DeleteResult deleteWorkProduct(String id) throws JsonProcessingException { mongoDbDao.setDatabase("work"); MongoClient mongo = mongoDbDao.getMongoClient(); MongoDatabase db = mongo.getDatabase("work"); MongoCollection<Document> collection = db.getCollection("work"); BasicDBObject query = new BasicDBObject(); query.append("_id", new ObjectId(id)); DeleteResult result = collection.deleteOne(query); return result; }
From source file:com.cognitive.cds.invocation.mongo.WorkProductSubscriptionDao.java
License:Apache License
public String deleteWorkProductSubscription(WorkProductSubscription wps) throws JsonProcessingException { mongoDbDao.setDatabase("work"); MongoClient mongo = mongoDbDao.getMongoClient(); MongoDatabase db = mongo.getDatabase("work"); MongoCollection<Document> collection = db.getCollection("subscriptions"); BasicDBObject query = new BasicDBObject(); query.append("user", wps.getUser()); DeleteResult result = collection.deleteOne(query); return result.toString(); }
From source file:com.crosstreelabs.cognitio.service.mongo.MongoCatalogueService.java
License:Apache License
protected DBObject toMongoObject(final CatalogueEntry entry) { if (entry == null) { throw new IllegalArgumentException("Entry cannot be null"); }//ww w . j a v a2 s. c om if (entry.host == null || StringUtils.isBlank(entry.host.id)) { throw new IllegalArgumentException("Cannot persist catalogue entry without host ref"); } BasicDBObject obj = new BasicDBObject(/*"_id", entry.id*/).append("status", entry.status.toString()) .append("status_reason", StringUtils.defaultIfBlank(entry.status_reason, "")) .append("location", entry.location).append("location_hash", DigestUtils.md5(entry.location)) .append("host", new ObjectId(entry.host.id)) .append("path", StringUtils.defaultIfBlank(entry.path, "")) .append("relocated", entry.relocated.toString()) .append("new_location", StringUtils.defaultIfBlank(entry.newLocation, "")) .append("initial_parent", StringUtils.defaultIfBlank(entry.initialParent, "")) .append("initial_depth", entry.initialDepth) .append("initial_parent_title", StringUtils.defaultIfBlank(entry.initialParentTitle, "")); if (entry.firstSeen != null) { obj.append("first_seen", entry.firstSeen.toDate()); } if (entry.lastVisit != null) { obj.append("last_visit", entry.lastVisit.toDate()); } return obj; }
From source file:com.crosstreelabs.cognitio.service.mongo.MongoHostService.java
License:Apache License
protected DBObject toMongoObject(final Host host) { BasicDBObject result = new BasicDBObject(); result.append("host", host.host); if (host.lastRequest != null) { result.append("last_request", host.lastRequest.toDate()); }//from w ww .j ava2 s. c o m result.append("robots_txt", host.robotsTxt); return result; }
From source file:com.datatorrent.contrib.mongodb.MongoDBPOJOOutputOperator.java
License:Apache License
@Override public void processTuple(Object tuple) { tableToDocument.clear();// w w w .j a v a 2 s . com BasicDBObject doc; BasicDBObject nestedDoc = null; if (getterValues.isEmpty()) { processFirstTuple(tuple); } for (int i = 0; i < keys.size(); i++) { String key = keys.get(i); String table = tablenames.get(i); //nested object are stored in a new document in mongo db. if (key.contains(".")) { String[] subKeys = nestedKeys.get(key); if (nestedDoc == null) { nestedDoc = new BasicDBObject(); } nestedDoc.put(subKeys[1], (getterValues.get(i)).get(tuple)); if ((doc = tableToDocument.get(table)) == null) { doc = new BasicDBObject(); } if (doc.containsField(subKeys[0])) { doc.append(subKeys[0], nestedDoc); } else { doc.put(subKeys[0], nestedDoc); } } else { if ((doc = tableToDocument.get(table)) == null) { doc = new BasicDBObject(); } doc.put(key, (getterValues.get(i)).get(tuple)); } tableToDocument.put(table, doc); } processTupleCommon(); }
From source file:com.davidsalter.cappedcollection.JavaDriverCappedCollection.java
License:Apache License
/** * @param args the command line arguments *//*from w ww .j av a 2 s. c o m*/ public static void main(String[] args) throws UnknownHostException { MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost")); DB db = mongoClient.getDB("test"); DBCollection collection; if (!db.collectionExists("cappedLogsJavaDriver")) { BasicDBObject options = new BasicDBObject("capped", true); options.append("size", 4096); options.append("max", 5); collection = db.createCollection("cappedLogsJavaDriver", options); } else { collection = db.getCollection("cappedLogsJavaDriver"); } for (int i = 0; i < 8; i++) { BasicDBObject logEntry = new BasicDBObject("logId", i); collection.insert(logEntry); } }
From source file:com.deliveronthego.DbConnection.java
public String customerSignup(String firstName, String lastName, String emailId, String password, int phoneNumber, String regId) { mongoclient = getConnection();//www . ja v a 2 s .co m @SuppressWarnings("deprecation") DB database = mongoclient.getDB("deliveronthego"); DBCollection customerSignUpInfo = database.getCollection("login"); if (emailId.contains("@") && (password.length() <= 8) && (String.valueOf(phoneNumber).length() == 10)) { BasicDBObject customerSignUpInfoObj = new BasicDBObject("emailId", emailId).append("password", password); DBCursor customerSignUpInfoCur = customerSignUpInfo.find(customerSignUpInfoObj); if (customerSignUpInfoCur.hasNext()) { return "Customer Sign Up Info Already Exists"; } else { customerSignUpInfoObj.append("firstName", firstName).append("lastName", lastName) .append("phoneNumber", phoneNumber).append("userType", "User").append("regId", regId); customerSignUpInfo.insert(customerSignUpInfoObj); return "Customer Signup Info inserted successfully"; } } else { return "Customer SignUp Info failed to insert"; } }
From source file:com.deliveronthego.DbConnection.java
public String driverSignup(String firstName, String lastName, String driverLicense, String emailId, String password, int phoneNumber, String regId) { mongoclient = getConnection();/* www .j a v a 2 s .c om*/ DB db = mongoclient.getDB("deliveronthego"); DBCollection driverSignUpInfo = db.getCollection("login"); if (emailId.contains("@") && (password.length() <= 8) && (String.valueOf(phoneNumber).length() == 10) && !driverLicense.isEmpty()) { BasicDBObject driverSignUpInfoObj = new BasicDBObject("driverLicense", driverLicense) .append("emailId", emailId).append("password", password); DBCursor driverSignUpInfoCur = driverSignUpInfo.find(driverSignUpInfoObj); if (driverSignUpInfoCur.hasNext()) { return "Driver Sign Up Info Already Exists"; } else { driverSignUpInfoObj.append("firstName", firstName).append("lastName", lastName) .append("phoneNumber", phoneNumber).append("userType", "Driver").append("regId", regId); driverSignUpInfo.insert(driverSignUpInfoObj); return "Driver Sign Up Info Inserted Successfully"; } } else { return "Driver SignUp Info failed to insert"; } }
From source file:com.deliveronthego.DbConnection.java
public String transcationNotification(String driverID, Boolean pickedUp, Boolean delivered) { mongoclient = getConnection();//from w w w.j av a 2 s . c o m @SuppressWarnings("deprecation") DB db = mongoclient.getDB("deliveronthego"); DBCollection notification = db.getCollection("notification"); BasicDBObject notificationObj = new BasicDBObject(); notificationObj.append("driverID", driverID); Date date = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(date); DBCursor notificationCursor = notification.find(notificationObj); if (pickedUp && !delivered) { notificationObj.append("pickedUp", pickedUp.toString()).append("delivered", delivered.toString()) .append("date", cal.toString()); notification.insert(notificationObj); return "New Transaction Data inserted"; } else { if (notificationCursor.hasNext()) { notificationCursor.next(); DBObject notifyObj = notificationCursor.curr(); Date currentDateInDatabase = (Date) notifyObj.get("date"); if (!(boolean) notifyObj.get("delivered") && currentDateInDatabase.before(date)) { notification.update(new BasicDBObject("driverID", driverID), new BasicDBObject("$set", new BasicDBObject("delivered", delivered.toString()))); return "Transaction Completed"; } else { return "Transaction failed to update"; } } else { return "Transaction failed"; } } }
From source file:com.dilmus.dilshad.scabi.deprecated.DBackFileOld.java
License:Open Source License
public int updateMetaData(String fileName, ObjectId fileID, String type, String contentType) throws IOException, DScabiException, ParseException { int n = 0;//from www. j a va 2 s. c o m String uploadDate = null; Date datefromDB = null; BasicDBObject documentWhere = new BasicDBObject(); documentWhere.put("_id", fileID); DBCursor cursorExist = m_table.find(documentWhere); n = cursorExist.count(); if (1 == n) { log.debug("updateMetaData() Inside 1 == n"); while (cursorExist.hasNext()) { DBObject ob = cursorExist.next(); log.debug("updateMetaData() result from ob {}", ob.toString()); //datefromDB = (String) ((BasicBSONObject) ob).getString("uploadDate"); datefromDB = ((BasicBSONObject) ob).getDate("uploadDate"); if (null == datefromDB) { throw new DScabiException("updateMetaData() Unable to get uploadDate for file : " + fileName + " fileID : " + fileID.toHexString(), "DBF.UMD.1"); } log.debug("datefromDB : {}", datefromDB); } } else if (0 == n) { log.debug("updateMetaData() No matches for file : " + fileName + " fileID : " + fileID.toHexString()); throw new DScabiException( "updateMetaData() No matches for file : " + fileName + " fileID : " + fileID.toHexString(), "DBF.UMD.2"); } else { log.debug("updateMetaData() Multiple matches for file : " + fileName + " fileID : " + fileID.toHexString()); throw new DScabiException("updateMetaData() Multiple matches for file : " + fileName + " fileID : " + fileID.toHexString(), "DBF.UMD.3"); } Date date = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); dateFormat.setTimeZone(TimeZone.getTimeZone("ISO")); String putClientDateTime = dateFormat.format(date); // To parse from string : Date date2 = dateFormat.parse(putDateTime); // Uses java.time java 8 : ZonedDateTime now = ZonedDateTime.now( ZoneOffset.UTC ); String millisTime = "" + System.currentTimeMillis(); String nanoTime = "" + System.nanoTime(); /* If datefromDB is String SimpleDateFormat dateFormatFromDB = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); dateFormatFromDB.setTimeZone(TimeZone.getTimeZone("ISO")); CharSequence cs1 = "T"; CharSequence cs2 = "Z"; String s1 = datefromDB.replace(cs1, " "); String s2 = s1.replace(cs2, ""); Date date2 = dateFormatFromDB.parse(s2); uploadDate = dateFormat.format(date2); */ uploadDate = dateFormat.format(datefromDB); log.debug("uploadDate : {}", uploadDate); BasicDBObject documentUpdate = new BasicDBObject(); documentUpdate.append("PutFileName", fileName); documentUpdate.append("PutServerFileID", fileID.toHexString()); documentUpdate.append("PutServerUploadDateTime", uploadDate); documentUpdate.append("PutType", type); documentUpdate.append("PutContentType", contentType); documentUpdate.append("PutClientDateTime", putClientDateTime); documentUpdate.append("PutClientDateTimeInMillis", millisTime); documentUpdate.append("PutClientDateTimeInNano", nanoTime); documentUpdate.append("PutStatus", "Completed"); documentUpdate.append("PutLatestNumber", "1"); BasicDBObject updateObj = new BasicDBObject(); updateObj.put("$set", documentUpdate); WriteResult result = m_table.update(documentWhere, updateObj); if (1 != result.getN()) throw new DScabiException( "Update meta data failed for file : " + fileName + " fileID : " + fileID.toHexString(), "DBF.UMD.4"); handlePreviousVersions(fileName, fileID.toHexString(), uploadDate); return result.getN(); }