List of usage examples for com.mongodb BasicDBObjectBuilder append
public BasicDBObjectBuilder append(final String key, final Object val)
From source file:com.conventus.mongodb.converter.ContentConverter.java
public DBObject toDBObject(Content content) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("name", content.getName()) .append("source", content.getSource()).append("file", content.getFile()); if (content.getId() != null) builder = builder.append("_id", new ObjectId(content.getId())); return builder.get(); }
From source file:com.conventus.mongodb.converter.FilmConverter.java
public DBObject toDBObject(Film film) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("name", film.getName()) .append("source", film.getSource()).append("file", film.getFile()).append("title", film.getTitle()) .append("genre", film.getGenre()).append("size", film.getSize()) .append("quality", film.getQuality()).append("resolution", film.getResolution()) .append("frameRate", film.getFrameRate()).append("language", film.getLanguage()) .append("duration", film.getDuration()).append("imdbRating", film.getImdbRating()) .append("mpr", film.getMpr()).append("peersSeeds", film.getPeersSeeds()); if (film.getId() != null) builder = builder.append("_id", new ObjectId(film.getId())); return builder.get(); }
From source file:com.databank.mongodb.converter.UserConverter.java
public static DBObject toDBObject(User u) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("firstname", u.getFirstname()) .append("lastname", u.getLastname()).append("email", u.getEmail()) .append("username", u.getUsername()).append("location", u.getLocation()) .append("password1", u.getPassword1()); if (u.getID() != null) { builder = builder.append("_id", new ObjectId(u.getID())); }//from w ww. jav a 2 s . c om return builder.get(); }
From source file:com.ejbmongoembeddedtomcat.converter.CustomerConverter.java
public static DBObject toDBObject(Customer cus) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("name", cus.getName()) .append("address", cus.getAddress()).append("kota", cus.getKota()); if (cus.getId() != null) { builder = builder.append("_id", new ObjectId(cus.getId())); }/*from w w w. j av a 2 s.c o m*/ return builder.get(); }
From source file:com.exorath.service.connector.service.MongoDatabaseProvider.java
License:Apache License
@Override public ServerInfo getServerInfo(Filter filter, Long minLastUpdate) { //Fingers crossed BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); if (filter.getGameId() != null) builder.append("gameId", filter.getGameId()); if (filter.getMapId() != null) builder.append("mapId", filter.getMapId()); if (filter.getFlavorId() != null) builder.append("flavorId", filter.getFlavorId()); builder.append("expiry", new BasicDBObject("$gte", System.currentTimeMillis())); MapReduceCommand mapReduceCommand = new MapReduceCommand(datastore.getDB().getCollection(collectionName), "function(){" + "var ret = {pc:0, opc:0, sc:0, osc:0};" + "ret.pc = this.pc; ret.sc = 1;" + "if(this.joinable && this.pc < this.mpc){ ret.opc = this.mpc - this.pc; ret.osc = 1;}" + "emit('server', ret);}", "function(key, values){" + "var ret = {pc:0, opc:0, sc:0, osc:0};" + "values.forEach( function(value) {" + " ret.pc+= value.pc; ret.sc++;" + " ret.osc+= value.osc; ret.opc+= value.opc" + " });" + "return ret;" + "}", null, MapReduceCommand.OutputType.INLINE, builder.get()); MapReduceOutput results = datastore.getDB().getCollection(collectionName).mapReduce(mapReduceCommand); if (results.getOutputCount() == 0) return new ServerInfo(0, 0, 0, 0, System.currentTimeMillis()); if (results.getOutputCount() > 1) throw new IllegalStateException("mapReduce returned multiple results."); for (DBObject res : results.results()) { DBObject val = (DBObject) res.get("value"); return new ServerInfo(((Double) val.get("pc")).intValue(), ((Double) val.get("sc")).intValue(), ((Double) val.get("osc")).intValue(), ((Double) val.get("opc")).intValue(), System.currentTimeMillis()); }/* w w w. j av a 2 s . c o m*/ //// MapreduceResults<ServerInfo> results = datastore.mapReduce(MapreduceType.INLINE, getFilterQuery(filter), ServerInfo.class, mapReduceCommand); //// if(results.getCounts().getOutputCount() == 0) { //// System.out.println("output 0 :*"); // return null; // } // System.out.println("ms: " + results.getElapsedMillis()); // results.forEach(info -> System.out.println(info.getOpenSlotCount())); return null; }
From source file:com.github.nlloyd.hornofmongo.MongoScope.java
License:Open Source License
public static Object listFiles(Context cx, Scriptable thisObj, Object[] args, Function funObj) { File path = null;//from ww w . j a va 2 s. c o m if (args.length == 0) path = ((MongoScope) thisObj).getCwd(); else if (args.length > 1) Context.throwAsScriptRuntimeEx(new MongoScriptException("need to specify 1 argument to listFiles")); else { try { path = resolveFilePath((MongoScope) thisObj, Context.toString(args[0])); } catch (IOException e) { Context.throwAsScriptRuntimeEx(new MongoScriptException("listFiles: " + e.getMessage())); } } // mongo only checks if the path exists, so we will do the same here if (!path.exists()) Context.throwAsScriptRuntimeEx( new MongoScriptException("listFiles: no such directory: " + path.getAbsolutePath())); if (!path.isDirectory()) Context.throwAsScriptRuntimeEx( new MongoScriptException("listFiles: not a directory: " + path.getAbsolutePath())); List<DBObject> files = new ArrayList<DBObject>(); for (File file : path.listFiles()) { BasicDBObjectBuilder fileObj = new BasicDBObjectBuilder(); fileObj.append("name", file.getPath()).append("isDirectory", file.isDirectory()); if (!file.isDirectory()) fileObj.append("size", file.length()); files.add(fileObj.get()); } Object jsResult = BSONizer.convertBSONtoJS((MongoScope) thisObj, files); return jsResult; }
From source file:com.github.sakserv.storm.bolt.SimpleMongoBolt.java
License:Apache License
@Override public DBObject getDBObjectForInput(Tuple input) { BasicDBObjectBuilder dbObjectBuilder = new BasicDBObjectBuilder(); for (String field : input.getFields()) { Object value = input.getValueByField(field); if (isValidDBObjectField(value)) { dbObjectBuilder.append(field, value); }/*from w w w. ja v a 2s .co m*/ } return dbObjectBuilder.get(); }
From source file:com.jjorgemoura.hangmanz.model.ZDHangmanGame.java
private DBObject createDBObject() { List lettersList = new ArrayList(); BasicDBObjectBuilder docBuilder = BasicDBObjectBuilder.start(); BasicDBObjectBuilder lettersDocBuilder; int theOrder = 1; for (Iterator<Integer> it = this.playsRecord.keySet().iterator(); it.hasNext();) { Integer i = it.next();// ww w . ja v a 2 s . c o m ZDAlphabet x = this.playsRecord.get(i); lettersDocBuilder = BasicDBObjectBuilder.start(); lettersDocBuilder.append("hm_letter", x.getLetter()); lettersDocBuilder.append("hm_letter_order", theOrder); lettersList.add(lettersDocBuilder.get()); theOrder++; } docBuilder.append("hm_uuid", this.uniqueUUID); docBuilder.append("hm_start_date", this.startDate.toString()); docBuilder.append("hm_latest_date", this.latestDate.toString()); docBuilder.append("hm_the_word", this.theWord.getName()); docBuilder.append("hm_category", this.category.getName()); docBuilder.append("hm_letters_played", lettersList); return docBuilder.get(); }
From source file:com.mobileman.kuravis.core.services.entity.impl.AbstractEntityServiceImpl.java
License:Apache License
@Override public List<DBObject> findAll(String entityName, String projection, Pageable page) { if (page == null) { page = new PageRequest(0, Integer.MAX_VALUE); }//from w w w .ja va 2 s .c o m DBCursor cursor = null; if (StringUtils.isEmpty(projection)) { cursor = getCollection(entityName).find(new BasicDBObject()); } else { String[] properties = projection.split(","); BasicDBObjectBuilder projectionBuilder = BasicDBObjectBuilder.start(); boolean idWanted = false; for (String property : properties) { property = property.trim(); if (!StringUtils.isEmpty(property)) { if (property.equals(EntityUtils.ID)) { idWanted = true; } projectionBuilder.add(property.trim(), true); } } if (idWanted == false) { projectionBuilder.append("_id", false); } cursor = getCollection(entityName).find(new BasicDBObject(), projectionBuilder.get()) .sort(new BasicDBObject(projection, 1)); } if (page.getSort() != null) { cursor = cursor.sort(createSort(page)); } else if (projection != null) { cursor = cursor.sort(new BasicDBObject(projection, 1)); } cursor = cursor.skip(page.getOffset()).limit(page.getPageSize()); List<DBObject> result = cursor.toArray(); return result; }
From source file:com.mycompany.schools1.SchooltoD.java
public static DBObject toDBObject(School s) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("name", s.getName()) .append("code", s.getCode()).append("address", s.getAddress()) .append("emailDomain", s.getEmailDomain()); if (s.getId() != null) { builder = builder.append("_id", new ObjectId(s.getId())); }//from w ww.java 2 s. co m return builder.get(); }