List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject(final String key, final Object value)
From source file:applango.common.services.DB.mongo.mongoDB.java
public static DBObject getRollupValue(DBCollection coll, String userId) { logger.info("Getting today's rollup record for user " + userId); DBCursor cursor;/*w w w. java2 s . c om*/ int maxWait = 10; try { DateTime jsonToday = new DateTime(); DateTime yesterday = new DateTime().minusDays(1); Date yesterdayDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(yesterday.toString()); BasicDBObject dateQueryObj = new BasicDBObject("beginDate", new BasicDBObject("$gt", yesterdayDate)); dateQueryObj.append("userId", userId); dateQueryObj.append("customerId", "automationCustomer"); dateQueryObj.append("appName", "salesforce"); cursor = coll.find(dateQueryObj); while ((cursor.count() == 0) && maxWait > 0) { sleep(1000); maxWait--; } } catch (Exception ex) { cursor = null; logger.error(ex.getMessage()); } return cursor.next(); }
From source file:at.ac.tuwien.dsg.smartcom.services.dao.MongoDBMessageInfoDAO.java
License:Apache License
@Override public void insert(MessageInformation information) { BasicDBObject doc = serializeMessageInfo(information); coll.update(new BasicDBObject("_id", serializeKey(information.getKey())), doc, true, false); log.trace("Inserted/Updated document for MessageInformation: {}", doc); }
From source file:at.ac.tuwien.dsg.smartcom.services.dao.MongoDBMessageInfoDAO.java
License:Apache License
@Override public MessageInformation find(MessageInformation.Key key) { BasicDBObject query = new BasicDBObject("_id", serializeKey(key)); MessageInformation info = null;/*from w w w . j a va 2 s .c o m*/ DBObject one = coll.findOne(query); if (one != null) { info = deserializeMessageInfo(one); } log.trace("Found message info for query {}: {}", query, info); return info; }
From source file:at.ac.tuwien.dsg.smartcom.services.dao.MongoDBMessageInfoDAO.java
License:Apache License
BasicDBObject serializeKey(MessageInformation.Key key) {
return new BasicDBObject("type", key.getType()).append("subtype", key.getSubtype());
}
From source file:at.oneminutedistraction.mongodbrealm.UserCollection.java
public BasicDBObject find(String username) { return ((BasicDBObject) users.findOne(new BasicDBObject(ATTR_USERNAME, username))); }
From source file:at.oneminutedistraction.mongodbrealm.UserCollection.java
public void update(BasicDBObject updateUser) throws MongoDBRealmException { String username = updateUser.getString(ATTR_USERNAME); verify(updateUser, "Cannot find user: " + username); try {/*from w w w . j a v a 2 s . c o m*/ users.update(new BasicDBObject(ATTR_USERNAME, username), updateUser); } catch (MongoException ex) { throw new MongoDBRealmException("Updating user " + username, ex); } }
From source file:at.oneminutedistraction.mongodbrealm.UserCollection.java
public void remove(String username) throws MongoDBRealmException { remove(new BasicDBObject(ATTR_USERNAME, username)); }
From source file:backend.facades.UserController.java
public List<UserEntity> getUserList() { List<UserEntity> userList = new ArrayList<UserEntity>(); String sort = "registeredDate"; String order = "desc"; DBObject sortCriteria = new BasicDBObject(sort, "desc".equals(order) ? -1 : 1); BasicDBObject query = new BasicDBObject(); DBCursor cursor = userCollection.find(query).sort(sortCriteria); try {/*from ww w . j a va 2s . co m*/ while (cursor.hasNext()) { DBObject document = cursor.next(); UserEntity userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); Integer value = (Integer) document.get("subscribe"); userEntity.setPersonalWebPage((String) document.get("webpage")); if (value != null && value.equals(StatusTypes.ACCEPT_LICENSE)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } userList.add(userEntity); } } finally { cursor.close(); } return userList; }
From source file:bank_server.Task.java
@Override public void run() { try {/*from ww w . j a v a 2 s . co m*/ oos = new ObjectOutputStream(cSock.getOutputStream()); ois = new ObjectInputStream(cSock.getInputStream()); if (ois == null || oos == null) System.exit(1); else System.out.println("Flux crs"); List names = collection.distinct("banque.name"); List idsTMP = collection.distinct("_id"); Set<Integer> ids = new HashSet<>(); for (Object id : idsTMP) ids.add(Integer.parseInt(id.toString().replace(".0", ""))); Request req = (Request) ois.readObject(); Response rep = new Response(); rep.setName(req.getName()); Boolean fin = null; String banque = null; int IDBanque = 0; if (names.contains(req.getContent())) { rep.setStatus(true); oos.writeObject(rep); fin = false; banque = req.getContent(); DBObject proj = new BasicDBObject("banque._id", 1); DBObject query = new BasicDBObject("banque.name", banque); DBObject doc = collection.findOne(query, proj); String str1[] = doc.toString().split("\"banque\" : \\{ \"_id\" : "); String str2[] = str1[1].split(".0}"); IDBanque = Integer.parseInt(str2[0]); System.out.println(banque + " : " + IDBanque); } else { rep.setStatus(false); oos.writeObject(rep); fin = true; } while (fin != true) { req = (Request) ois.readObject(); DBObject document = new BasicDBObject(); Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String date = sdf.format(d); switch (req.getName()) { case "END": { System.out.println("Closing Connection"); fin = true; } break; case "credit": { Integer id = 0; while (ids.contains(id)) id++; ids.add(id); System.out.println("id choisi : " + id); document.put("_id", id); document.put("type", "credit"); document.put("montant", req.getMontant()); document.put("valide", "false"); document.put("date", date); document.put("banque", new BasicDBObject("_id", IDBanque).append("name", banque)); collection.insert(document); rep = new Response(); rep.setName(req.getName()); rep.setStatus(true); } break; case "debit": { Integer id = 0; while (ids.contains(id)) id++; ids.add(id); System.out.println("id choisi : " + id); document.put("_id", id); document.put("type", "debit"); document.put("montant", req.getMontant()); document.put("valide", "false"); document.put("date", date); document.put("banque", new BasicDBObject("_id", IDBanque).append("name", banque)); collection.insert(document); rep = new Response(); rep.setName(req.getName()); rep.setStatus(true); } break; case "etat": { rep = new Response(); rep.setName(req.getName()); try { Integer id = Integer.parseInt(req.getContent()); if (!ids.contains(id)) throw new NumberFormatException(); document = collection.findOne(new BasicDBObject("_id", id)); System.out.println(document); String[] str1 = document.toString().split("\"name\" : \""); String[] str2 = str1[1].split("\""); if (banque.equalsIgnoreCase(str2[0])) { rep.setStatus(true); str1 = document.toString().split("\"montant\" : "); str2 = str1[1].split(" , "); rep.setMontant(Integer.parseInt(str2[0].replace(".0", ""))); str1 = document.toString().split("\"valide\" : \""); str2 = str1[1].split("\""); if (str2[0].equalsIgnoreCase("true")) rep.setValide(true); else rep.setValide(false); } else { rep.setStatus(false); rep.setValide(false); } } catch (NumberFormatException ex) { //System.out.println("Etat : bad id request"); rep.setStatus(false); rep.setValide(true); } } break; } oos.writeObject(rep); } oos.close(); ois.close(); cSock.close(); } catch (IOException | ClassNotFoundException ex) { Logger.getLogger(Task.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:bd.DArticulo.java
@Override public String eliminar(Object o) { CArticulo x = (CArticulo) o;/* ww w . j a v a2 s.c o m*/ conecion con = new conecion(table); BasicDBObject datos = new BasicDBObject("_id", x.getId()); con.get_colletion().remove(datos); con.end(); return datos.getString("_id"); }