List of usage examples for com.mongodb BasicDBObject toString
@SuppressWarnings("deprecation") public String toString()
Returns a JSON serialization of this object
The output will look like: {"a":1, "b":["x","y","z"]} }
From source file:edu.umass.cs.gnsserver.database.MongoRecords.java
License:Apache License
private void doUpdate(String collectionName, String guid, BasicDBObject updates) throws FailedDBOperationException { String primaryKey = mongoCollectionSpecs.getCollectionSpec(collectionName).getPrimaryKey().getName(); DBCollection collection = db.getCollection(collectionName); BasicDBObject query = new BasicDBObject(primaryKey, guid); if (updates.keySet().size() > 0) { long startTime = System.currentTimeMillis(); try {/*from w w w . jav a 2 s . c o m*/ collection.update(query, new BasicDBObject("$set", updates)); } catch (MongoException e) { DatabaseConfig.getLogger().log(Level.SEVERE, "{0} doUpdate failed: {1}", new Object[] { dbName, e.getMessage() }); throw new FailedDBOperationException(collectionName, updates.toString(), "Original mongo exception:" + e.getMessage()); } DelayProfiler.updateDelay("mongoSetUpdate", startTime); long finishTime = System.currentTimeMillis(); if (finishTime - startTime > 10) { DatabaseConfig.getLogger().log(Level.FINE, "{0} Long latency mongoUpdate {1}", new Object[] { dbName, (finishTime - startTime) }); } } }
From source file:edu.umass.cs.gnsserver.database.MongoRecords.java
License:Apache License
@Override public void removeMapKeys(String collectionName, String name, ColumnField mapField, ArrayList<ColumnField> mapKeys) throws FailedDBOperationException { String primaryKey = mongoCollectionSpecs.getCollectionSpec(collectionName).getPrimaryKey().getName(); DBCollection collection = db.getCollection(collectionName); BasicDBObject query = new BasicDBObject(primaryKey, name); BasicDBObject updates = new BasicDBObject(); if (mapField != null && mapKeys != null) { for (int i = 0; i < mapKeys.size(); i++) { String fieldName = mapField.getName() + "." + mapKeys.get(i).getName(); updates.append(fieldName, 1); }/*from www. j av a 2s .c o m*/ } if (updates.keySet().size() > 0) { try { DatabaseConfig.getLogger().log(Level.FINE, "{0} <============>unset{1}<============>", new Object[] { dbName, updates.toString() }); collection.update(query, new BasicDBObject("$unset", updates)); } catch (MongoException e) { DatabaseConfig.getLogger().log(Level.FINE, "{0} removeMapKeys failed: {1}", new Object[] { dbName, e.getMessage() }); throw new FailedDBOperationException(collectionName, updates.toString(), "Original mongo exception:" + e.getMessage()); } } }
From source file:eu.eubrazilcc.lvl.storage.dao.LeishmaniaDAO.java
License:EUPL
private void transformReferenceLocations(final List<Localizable<Point>> localizables, final List<BasicDBObject> results) { final List<InnerReference> innerRefs = from(results) .transform(new Function<BasicDBObject, InnerReference>() { @Override/*from w w w . java 2 s . c o m*/ public InnerReference apply(final BasicDBObject obj) { InnerReference reference = null; try { reference = JSON_MAPPER.readValue(obj.toString(), InnerReference.class); } catch (IOException e) { LOGGER.error("Failed to read inner reference from DB object", e); } return reference; } }).filter(notNull()).toList(); for (final InnerReference ref : innerRefs) { for (final Point point : ref.getValue().getLocations()) { localizables.add(new Localizable<Point>() { private final String tag = ref.get_id().getPmid(); private final Point location = point; @Override public Point getLocation() { return location; } @Override public void setLocation(final Point location) { throw new UnsupportedOperationException( "Modifiable location is not supported in this class"); } @Override public String getTag() { return tag; } @Override public String toString() { return toStringHelper(this).add("tag", tag).add("location", location).toString(); } }); } } }
From source file:eu.eubrazilcc.lvl.storage.dao.LeishmaniaDAO.java
License:EUPL
private LeishmaniaEntity map(final BasicDBObject obj) { LeishmaniaEntity entity = null;//from ww w . ja v a 2 s . co m try { entity = JSON_MAPPER.readValue(obj.toString(), LeishmaniaEntity.class); } catch (IOException e) { LOGGER.error("Failed to read leishmania from DB object", e); } return entity; }
From source file:eu.eubrazilcc.lvl.storage.dao.LvlInstanceDAO.java
License:EUPL
private LvlInstanceEntity map(final BasicDBObject obj) { LvlInstanceEntity entity = null;/* w ww. j av a 2 s . c o m*/ try { entity = JSON_MAPPER.readValue(obj.toString(), LvlInstanceEntity.class); } catch (IOException e) { LOGGER.error("Failed to read instance from DB object", e); } return entity; }
From source file:eu.eubrazilcc.lvl.storage.dao.NotificationDAO.java
License:EUPL
private NotificationEntity map(final BasicDBObject obj) { NotificationEntity entity = null;// ww w .j av a 2 s .c o m try { entity = JSON_MAPPER.readValue(obj.toString(), NotificationEntity.class); } catch (IOException e) { LOGGER.error("Failed to read notification from DB object", e); } return entity; }
From source file:eu.eubrazilcc.lvl.storage.dao.ReferenceDAO.java
License:EUPL
private ReferenceEntity map(final BasicDBObject obj) { ReferenceEntity entity = null;/* ww w . ja v a 2s . com*/ try { entity = JSON_MAPPER.readValue(obj.toString(), ReferenceEntity.class); } catch (IOException e) { LOGGER.error("Failed to read reference from DB object", e); } return entity; }
From source file:eu.eubrazilcc.lvl.storage.dao.SandflyDAO.java
License:EUPL
private @Nullable BasicDBObject buildQuery(final @Nullable ImmutableMap<String, String> filter) throws InvalidFilterParseException { BasicDBObject query = null; if (filter != null) { for (final Entry<String, String> entry : filter.entrySet()) { query = parseFilter(entry.getKey(), entry.getValue(), query); }/*from www . j ava2s . c om*/ } // TODO System.err.println("\n\n >> QUERY: " + (query != null ? query.toString() : "NULL") + "\n"); // TODO return query; }
From source file:eu.eubrazilcc.lvl.storage.dao.SandflyDAO.java
License:EUPL
private SandflyEntity map(final BasicDBObject obj) { SandflyEntity entity = null;//from w w w . java 2 s .c o m try { entity = JSON_MAPPER.readValue(obj.toString(), SandflyEntity.class); } catch (IOException e) { LOGGER.error("Failed to read sandfly from DB object", e); } return entity; }
From source file:eu.eubrazilcc.lvl.storage.dao.SavedSearchDAO.java
License:EUPL
private SavedSearchEntity map(final BasicDBObject obj) { SavedSearchEntity entity = null;//from w w w . j av a 2 s . co m try { entity = JSON_MAPPER.readValue(obj.toString(), SavedSearchEntity.class); } catch (IOException e) { LOGGER.error("Failed to read saved search from DB object", e); } return entity; }