List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start()
From source file:fr.ensimag.biblio.dao.impl.MongoDBUserDAO.java
public void deleteUser(User user) { DBObject query = BasicDBObjectBuilder.start().append("_id", new ObjectId(user.getId())).get(); this.col.remove(query); }
From source file:fr.wseduc.gridfs.GridFSPersistor.java
License:Apache License
private void persistChunk(Message<Buffer> message, byte[] data, JsonObject json) { final Integer n = json.getInteger("n"); if (n == null) { replyError(message, "Invalid chunk number"); return;// w w w .j a v a 2 s.c om } final String id = json.getString("_id"); if (id == null || id.trim().isEmpty()) { replyError(message, "Invalid file id"); return; } if (n == 0) { try { saveFile(json, data.length); } catch (MongoException e) { logger.error(e.getMessage(), e); replyError(message, e.getMessage()); return; } } try { DBObject chunk = BasicDBObjectBuilder.start().add("files_id", id).add("n", n).add("data", data).get(); DBCollection collection = db.getCollection(bucket + CHUNKS); collection.save(chunk); replyOK(message, new JsonObject()); } catch (RuntimeException e) { logger.error(e.getMessage(), e); replyError(message, e.getMessage()); } }
From source file:fr.xebia.cocktail.CocktailRepository.java
License:Apache License
public boolean delete(Cocktail cocktail) { Preconditions.checkNotNull(cocktail.getObjectId(), "Given objectId must not be null in %s", cocktail); try {/*w ww .ja v a 2s. c o m*/ // SOLR UpdateResponse solrResponse = solrServer.deleteByQuery("id:" + cocktail.getId()); logger.trace("solr.delete for {}: {}", cocktail, solrResponse); // MONGODB WriteResult mongoResult = cocktails.remove( BasicDBObjectBuilder.start().add("_id", cocktail.getObjectId()).get(), WriteConcern.SAFE); logger.trace("mongo.remove for {}: {}", cocktail, mongoResult); return mongoResult.getN() > 0; } catch (Exception e) { throw new RuntimeException("Exception deleting " + cocktail, e); } }
From source file:fr.xebia.cocktail.CocktailRepository.java
License:Apache License
public Cocktail get(String id) { DBObject dbObject = cocktails.findOne(BasicDBObjectBuilder.start().add("_id", new ObjectId(id)).get()); return BSON_TO_COCKTAIL.apply(dbObject); }
From source file:fr.xebia.cocktail.CocktailRepository.java
License:Apache License
public void purgeRepository() { try {/* w ww .ja va 2 s . co m*/ // SOLR UpdateResponse solrResponse = solrServer.deleteByQuery("*:*"); logger.trace("solr.delete all: {}", solrResponse); // MONGODB WriteResult mongoResult = cocktails.remove(BasicDBObjectBuilder.start().get(), WriteConcern.SAFE); logger.trace("mongo.remove all", mongoResult); } catch (Exception e) { throw new RuntimeException("Exception purging repository", e); } }
From source file:hadoop.mongo.treasury.TreasuryYieldUpdateReducer.java
License:Apache License
@Override public void reduce(final IntWritable pKey, final Iterable<DoubleWritable> pValues, final Context pContext) throws IOException, InterruptedException { int count = 0; double sum = 0; for (final DoubleWritable value : pValues) { sum += value.get();// w w w.j a v a 2s . co m count++; } final double avg = sum / count; if (LOG.isDebugEnabled()) { LOG.debug("Average 10 Year Treasury for " + pKey.get() + " was " + avg); } BasicBSONObject query = new BasicBSONObject("_id", pKey.get()); BasicBSONObject modifiers = new BasicBSONObject(); modifiers.put("$set", BasicDBObjectBuilder.start().add("count", count).add("avg", avg).add("sum", sum).get()); modifiers.put("$push", new BasicBSONObject("calculatedAt", new Date())); modifiers.put("$inc", new BasicBSONObject("numCalculations", 1)); reduceResult.setQuery(query); reduceResult.setModifiers(modifiers); pContext.write(null, reduceResult); }
From source file:io.gravitee.repository.mongodb.ratelimit.MongoRateLimitRepository.java
License:Apache License
@Override public void save(RateLimit rateLimit) { final DBObject doc = BasicDBObjectBuilder.start().add(FIELD_KEY, rateLimit.getKey()) .add(FIELD_COUNTER, rateLimit.getCounter()).add(FIELD_LAST_REQUEST, rateLimit.getLastRequest()) .add(FIELD_RESET_TIME, new Date(rateLimit.getResetTime())) .add(FIELD_UPDATED_AT, rateLimit.getUpdatedAt()).add(FIELD_CREATED_AT, rateLimit.getCreatedAt()) .add(FIELD_ASYNC, rateLimit.isAsync()).get(); mongoOperations.getCollection(RATE_LIMIT_COLLECTION).save(doc); }
From source file:javasensei.db.managments.RankingManager.java
public boolean colocarRankingDefault() { boolean result = false; try {/* w w w . j a v a2s.co m*/ QueryBuilder query = QueryBuilder.start("id").notIn(rankingEjercicios.distinct("idEjercicio", QueryBuilder.start("idAlumno").is(estudiante.getId()).get())); //Obtenemos los id de ejercicios que no estan rankeados por el alumno //Se colocara un valor 2 de default para dicho ranking, de acuerdo a la escala de LIKERT List<DBObject> objects = ejercicios.find(query.get()).toArray(); if (!objects.isEmpty()) { List<DBObject> listObjects = new ArrayList<>(); for (DBObject object : objects) { listObjects.add(BasicDBObjectBuilder.start().add("idEjercicio", object.get("id")) .add("idAlumno", estudiante.getId()).add("ranking", 2) //2 De acuerdo a la escala .get()); } rankingEjercicios.insert(listObjects); updateDataModelEjercicios(); } //Mismo proceso para ranking de recursos QueryBuilder queryRecursos = QueryBuilder.start("id").notIn(rankingRecursos.distinct("idRecurso", QueryBuilder.start("idAlumno").is(estudiante.getId()).get())); List<DBObject> idRecursos = recursos.find(queryRecursos.get()).toArray(); if (!idRecursos.isEmpty()) { List<DBObject> listRankingRecursosSave = new ArrayList<>(); for (DBObject object : idRecursos) { listRankingRecursosSave.add(BasicDBObjectBuilder.start().add("idRecurso", object.get("id")) .add("idAlumno", estudiante.getId()).add("ranking", 2) //2 De acuerdo a la escala .get()); } rankingRecursos.insert(listRankingRecursosSave); updateDataModelRecursos(); } result = true; } catch (Exception ex) { System.err.println(ex); } return result; }
From source file:me.philnate.textmanager.updates.Update12_12.java
License:Open Source License
/** * does the actual migration for ClassNames *///w w w.ja v a2 s .c om private void updateClassName() { LOG.info("Removing potential className attributes"); for (Class<?> clazz : classes) { LOG.info("removing className from class " + clazz); ds.getCollection(clazz).update(new BasicDBObject(), BasicDBObjectBuilder.start().push("$unset").add("className", true).pop().get(), false, true); } LOG.info("Removed all className attributes"); }
From source file:me.philnate.textmanager.updates.Update12_12.java
License:Open Source License
private void postCheckClassName() { for (Class<?> clazz : classes) { checkArgument(0 == ds.getCollection(clazz) .find(BasicDBObjectBuilder.start().push("className").add("$exists", true).pop().get()).count(), "Found className attribute within a record of class " + clazz); }/*from w w w. j a v a 2 s . c om*/ }