List of usage examples for com.mongodb BasicDBObject getString
public String getString(final String key)
From source file:rapture.sheet.mongodb.MongoMetaSheetStore.java
License:Open Source License
public List<RaptureSheetScript> getSheetScripts(final String name) { MongoRetryWrapper<List<RaptureSheetScript>> wrapper = new MongoRetryWrapper<List<RaptureSheetScript>>() { public DBCursor makeCursor() { DBCollection collection = MongoDBFactory.getDB(instanceName).getCollection(tableName); BasicDBObject query = new BasicDBObject(); query.append(TYPE, SCRIPT);/*from ww w.j av a2 s . c o m*/ query.append(KEY, name); BasicDBObject values = new BasicDBObject(); values.append(VALUE, 1); return collection.find(query, values); } public List<RaptureSheetScript> action(DBCursor cursor) { List<RaptureSheetScript> ret = new ArrayList<RaptureSheetScript>(); while (cursor.hasNext()) { BasicDBObject obj = (BasicDBObject) cursor.next(); String content = obj.getString(VALUE); RaptureSheetScript script = JacksonUtil.objectFromJson(content, RaptureSheetScript.class); ret.add(script); } return ret; } }; return wrapper.doAction(); }
From source file:rapture.sheet.mongodb.MongoMetaSheetStore.java
License:Open Source License
public List<RaptureSheetRange> getSheetNamedSelections(final String name) { MongoRetryWrapper<List<RaptureSheetRange>> wrapper = new MongoRetryWrapper<List<RaptureSheetRange>>() { public DBCursor makeCursor() { DBCollection collection = MongoDBFactory.getDB(instanceName).getCollection(tableName); BasicDBObject query = new BasicDBObject(); query.append(TYPE, RANGE);/* w w w.j a v a 2 s. co m*/ query.append(KEY, name); BasicDBObject values = new BasicDBObject(); values.append(VALUE, 1); return collection.find(query, values); } public List<RaptureSheetRange> action(DBCursor cursor) { List<RaptureSheetRange> ret = new ArrayList<RaptureSheetRange>(); while (cursor.hasNext()) { BasicDBObject obj = (BasicDBObject) cursor.next(); String content = obj.getString(VALUE); RaptureSheetRange range = JacksonUtil.objectFromJson(content, RaptureSheetRange.class); ret.add(range); } return ret; } }; return wrapper.doAction(); }
From source file:rapture.sheet.mongodb.MongoMetaSheetStore.java
License:Open Source License
public RaptureSheetScript getSheetScript(String name, String scriptName) { DBCollection collection = MongoDBFactory.getDB(instanceName).getCollection(tableName); BasicDBObject query = new BasicDBObject(); query.append(TYPE, SCRIPT);//from w w w . j av a 2s. c o m query.append(KEY, name); query.append(NAME, scriptName); BasicDBObject values = new BasicDBObject(); values.append(VALUE, 1); BasicDBObject value = (BasicDBObject) collection.findOne(query, values); if (value != null) { String content = value.getString(VALUE); RaptureSheetScript script = JacksonUtil.objectFromJson(content, RaptureSheetScript.class); return script; } return null; }
From source file:rapture.sheet.mongodb.MongoMetaSheetStore.java
License:Open Source License
public RaptureSheetRange getSheetNamedSelection(String name, String rangeName) { DBCollection collection = MongoDBFactory.getDB(instanceName).getCollection(tableName); BasicDBObject query = new BasicDBObject(); query.append(TYPE, RANGE);/*from w w w . ja va 2s . com*/ query.append(KEY, name); query.append(NAME, rangeName); BasicDBObject values = new BasicDBObject(); values.append(VALUE, 1); BasicDBObject value = (BasicDBObject) collection.findOne(query, values); if (value != null) { String content = value.getString(VALUE); RaptureSheetRange range = JacksonUtil.objectFromJson(content, RaptureSheetRange.class); return range; } return null; }
From source file:rapture.sheet.mongodb.MongoMetaSheetStore.java
License:Open Source License
public List<RaptureSheetNote> getSheetNotes(final String name) { MongoRetryWrapper<List<RaptureSheetNote>> wrapper = new MongoRetryWrapper<List<RaptureSheetNote>>() { public DBCursor makeCursor() { DBCollection collection = MongoDBFactory.getDB(instanceName).getCollection(tableName); BasicDBObject query = new BasicDBObject(); query.append(TYPE, NOTE);/*from www . j a v a 2 s.com*/ query.append(KEY, name); BasicDBObject values = new BasicDBObject(); values.append(VALUE, 1); return collection.find(query, values); } public List<RaptureSheetNote> action(DBCursor cursor) { List<RaptureSheetNote> ret = new ArrayList<RaptureSheetNote>(); while (cursor.hasNext()) { BasicDBObject obj = (BasicDBObject) cursor.next(); String content = obj.getString(VALUE); RaptureSheetNote note = JacksonUtil.objectFromJson(content, RaptureSheetNote.class); ret.add(note); } return ret; } }; return wrapper.doAction(); }
From source file:Server.Service.java
private void check_query(query order) { try {/*from ww w.java 2s.c o m*/ Date time = new Date(); double money = 0; try { if ((order.getAmount() != null) && (!order.getAmount().equals(""))) money = Double.parseDouble(new String(decrypty(order.getAmount()))); } catch (NumberFormatException e) { output.writeObject(new query(false, "INVALID")); output.flush(); return; } DBCollection users = db.getCollection("users"); DBCollection clients = db.getCollection("clients"); DBCollection records = db.getCollection("records"); BasicDBObject userQ = new BasicDBObject().append("name", currentUser.getString("name")); DBObject user = users.findOne(userQ); BasicDBObject clientQ = new BasicDBObject().append("ipAddr", ipAddr); DBObject client = clients.findOne(clientQ); //DEAL THE QUERY PART if (order.type == method.WITHDRAW) { double user_money = Double.parseDouble(new String(decrypty(user.get("money").toString()))); double client_money = Double.parseDouble(new String(decrypty(client.get("money").toString()))); user_money -= money; client_money -= money; if (checkNegative(user_money, client_money, money)) { String user_money_tmp = encrypt(user_money + ""); String client_money_tmp = encrypt(client_money + ""); String user_tmp = "-" + money; users.update(userQ, new BasicDBObject().append("$set", new BasicDBObject().append("money", user_money_tmp))); records.insert(new BasicDBObject().append("ipAddr", this.ipAddr) .append("serial", this.serialNum).append("name", userQ.getString("name")) .append("type", "WITHDRAW").append("delta", encrypt(user_tmp)) .append("remains", user_money_tmp).append("time", formatter.format(time))); clients.update(new BasicDBObject().append("ipAddr", ipAddr), new BasicDBObject().append("$set", new BasicDBObject().append("money", client_money_tmp))); output.writeObject(new query(true, user_money_tmp)); output.flush(); } } else if (order.type == method.DEPOSIT) { double user_money = Double.parseDouble(new String(decrypty(user.get("money").toString()))); double client_money = Double.parseDouble(new String(decrypty(client.get("money").toString()))); user_money += money; client_money += money; if (checkNegative(user_money, client_money, money)) { String user_money_tmp = encrypt(user_money + ""); String client_money_tmp = encrypt(client_money + ""); String user_tmp = "+" + money; users.update(userQ, new BasicDBObject().append("$set", new BasicDBObject().append("money", user_money_tmp))); records.insert(new BasicDBObject().append("ipAddr", this.ipAddr) .append("serial", this.serialNum).append("name", userQ.getString("name")) .append("type", "DEPOSIT").append("delta", encrypt(user_tmp)) .append("remains", user_money_tmp).append("time", formatter.format(time))); clients.update(new BasicDBObject().append("ipAddr", ipAddr), new BasicDBObject().append("$set", new BasicDBObject().append("money", client_money_tmp))); output.writeObject(new query(true, user_money_tmp)); output.flush(); } } else if (order.type == method.TRANSFORM) { BasicDBObject targetQ = new BasicDBObject().append("name", order.getTarget()); DBObject target = users.findOne(targetQ); if (target == null) { output.writeObject(new query(false, "NO_SUCH_USER")); output.flush(); } else if (target.get("name").toString().equals(currentUser.getString("name"))) { output.writeObject(new query(false, "NOT_ALLOWED")); output.flush(); } else { double user_money = Double.parseDouble(new String(decrypty(user.get("money").toString()))); double target_money = Double.parseDouble(new String(decrypty(target.get("money").toString()))); double client_money = Double.parseDouble(new String(decrypty(client.get("money").toString()))); target_money += money; user_money -= money; if (checkNegative(user_money, target_money, money)) { String target_money_tmp = encrypt(target_money + ""); String user_money_tmp = encrypt(user_money + ""); String client_money_tmp = encrypt(client_money + ""); String target_tmp = "+" + money; String user_tmp = "-" + money; users.update(userQ, new BasicDBObject().append("$set", new BasicDBObject().append("money", user_money_tmp))); users.update(targetQ, new BasicDBObject().append("$set", new BasicDBObject().append("money", target_money_tmp))); records.insert(new BasicDBObject().append("ipAddr", this.ipAddr) .append("serial", this.serialNum).append("name", userQ.getString("name")) .append("type", "TRANSFORM").append("delta", encrypt(user_tmp)) .append("remains", user_money_tmp).append("time", formatter.format(time))); records.insert(new BasicDBObject().append("ipAddr", this.ipAddr) .append("serial", this.serialNum).append("name", targetQ.getString("name")) .append("type", "TRANSFORM").append("delta", encrypt(target_tmp)) .append("remains", target_money_tmp).append("time", formatter.format(time))); clients.update(new BasicDBObject().append("ipAddr", ipAddr), new BasicDBObject() .append("$set", new BasicDBObject().append("money", client_money_tmp))); output.writeObject(new query(true, user_money_tmp)); output.flush(); } } } else if (order.type == method.LOOKUP) { DBCursor cursor = records.find(userQ); ArrayList<tradeD> details = new ArrayList<>(); while (cursor.hasNext()) { DBObject tmp = cursor.next(); tradeD obj = new tradeD(tmp.get("serial").toString(), tmp.get("ipAddr").toString(), tmp.get("name").toString(), tmp.get("type").toString(), tmp.get("delta").toString(), tmp.get("remains").toString(), tmp.get("time").toString()); details.add(obj); } output.writeObject(new query(true, "", details)); output.flush(); } else if (order.type == method.RESET) { String pwd = user.get("pwd").toString(); if (order.getPwd0().equals(pwd) && (order.getPwd1() != null)) { users.update(currentUser, new BasicDBObject().append("$set", new BasicDBObject().append("pwd", order.getPwd1()))); output.writeObject(new query(true, "Success")); output.flush(); } else { output.writeObject(new query(false, "wrongPwd")); output.flush(); } } } catch (java.lang.NullPointerException ex) { Logger.getLogger(Service.class.getName()).log(Level.SEVERE, null, ex); this.DBShutdown(); } catch (IOException ex) { this.DBShutdown(); Logger.getLogger(Service.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:stirling.fix.session.store.MongoSessionStore.java
License:Apache License
private FixMessage message(BasicDBObject doc) { return FixMessage.fromString(doc.getString("data"), doc.getString("msgType")); }
From source file:tad.grupo7.ccamistadeslargas.DAO.EventoDAO.java
/** * Devuelve un Evento que coincida con un ID. * * @param id ObjectId del evento./*from w ww .j av a 2 s . co m*/ * @return Evento */ public static Evento read(ObjectId id) { BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("_id", id); BasicDBObject document = (BasicDBObject) eventos.findOne(whereQuery); String nombre = document.getString("nombre"); String divisa = document.getString("divisa"); ObjectId idCreador = document.getObjectId("idCreador"); Evento e = new Evento(id, nombre, divisa, idCreador, ParticipanteDAO.readAllFromEvento(id)); return e; }
From source file:tad.grupo7.ccamistadeslargas.DAO.EventoDAO.java
/** * Devuelve un listado con todos los eventos del usuario. * * @param idUsuario ObjectId del usuario. * @return List//w ww. j a v a2 s . c o m */ public static List<Evento> readAll(ObjectId idUsuario) { BasicDBObject whereQuery = new BasicDBObject(); whereQuery.put("idCreador", idUsuario); DBCursor cursor = eventos.find(whereQuery); List<Evento> eventos = new ArrayList<>(); while (cursor.hasNext()) { BasicDBObject e = (BasicDBObject) cursor.next(); eventos.add(new Evento(e.getObjectId("_id"), e.getString("nombre"), e.getString("divisa"), e.getObjectId("idCreador"), ParticipanteDAO.readAllFromEvento(e.getObjectId("_id")))); } return eventos; }
From source file:tad.grupo7.ccamistadeslargas.DAO.EventoDAO.java
/** * Lee todos los eventos de la BD/*from w ww.j av a 2 s . co m*/ * @return List */ public static List<Evento> readAll() { DBCursor cursor = eventos.find(); List<Evento> eventos = new ArrayList<>(); while (cursor.hasNext()) { BasicDBObject e = (BasicDBObject) cursor.next(); eventos.add(new Evento(e.getObjectId("_id"), e.getString("nombre"), e.getString("divisa"), e.getObjectId("idCreador"), ParticipanteDAO.readAllFromEvento(e.getObjectId("_id")))); } return eventos; }