本文整理汇总了Java中com.mongodb.DBCollection.save方法的典型用法代码示例。如果您正苦于以下问题:Java DBCollection.save方法的具体用法?Java DBCollection.save怎么用?Java DBCollection.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.DBCollection
的用法示例。
在下文中一共展示了DBCollection.save方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reportGauge
import com.mongodb.DBCollection; //导入方法依赖的package包/类
private void reportGauge(final String name, final Gauge gauge, final Date timestamp) {
final DBCollection coll = db.getCollection("metric_gauge");
final Object value = gauge.getValue();
if (value == null) {
// skip report
return;
}
if (!String.class.equals(value.getClass())) {
final GaugeEntity entity = new GaugeEntity();
entity.setName(prefix(name));
entity.setTimestamp(timestamp);
entity.setValue(value);
try {
coll.save(entity.toDBObject());
} catch (MongoException e) {
LOGGER.warn("Unable to report gauge {}", name, e);
}
}
}
示例2: save
import com.mongodb.DBCollection; //导入方法依赖的package包/类
public void save() throws SinfonierException {
DBCollection collection = MongoFactory.getDB().getCollection(collectionName);
if (this.id == null) {
Logger.info("Adding a new module version");
DBObject dbObj = this.toDBObject();
collection.save(dbObj);
this.id = dbObj.get(FIELD_ID).toString();
} else {
Logger.info("Editing module version id:" + this.getId().toString());
DBObject query = new BasicDBObject(FIELD_ID, new ObjectId(this.id));
DBObject toSet = this.toDBObject();
// Remove fields's unmodified
toSet.removeField(FIELD_ID);
toSet.removeField(FIELD_CREATED);
toSet.removeField(FIELD_TOPOLOGIES_COUNT);
toSet.removeField(FIELD_BUILD_STATUS);
// Update field's update
toSet.put(FIELD_UPDATED, new Date());
collection.update(query, new BasicDBObject("$set", toSet), true, false);
}
}
示例3: reportTimer
import com.mongodb.DBCollection; //导入方法依赖的package包/类
private void reportTimer(final String name, final Timer timer, final Date timestamp) {
final DBCollection coll = db.getCollection("metric_timer");
final TimerEntity entity = new TimerEntity(timer);
entity.setName(prefix(name));
entity.setTimestamp(timestamp);
try {
coll.save(entity.toDBObject());
} catch (MongoException e) {
LOGGER.warn("Unable to report timer {}", name, e);
}
}
示例4: reportMetered
import com.mongodb.DBCollection; //导入方法依赖的package包/类
private void reportMetered(final String name, final Metered meter, final Date timestamp) {
final DBCollection coll = db.getCollection("metric_metered");
final MeteredEntity entity = new MeteredEntity(meter);
entity.setName(prefix(name));
entity.setTimestamp(timestamp);
try {
coll.save(entity.toDBObject());
} catch (MongoException e) {
LOGGER.warn("Unable to report meter {}", name, e);
}
}
示例5: reportHistogram
import com.mongodb.DBCollection; //导入方法依赖的package包/类
private void reportHistogram(final String name, final Histogram histogram, final Date timestamp) {
final Snapshot snapshot = histogram.getSnapshot();
final DBCollection coll = db.getCollection("metric_histogram");
final HistogramEntity entity = new HistogramEntity(snapshot);
entity.setName(prefix(name));
entity.setCount(histogram.getCount());
entity.setTimestamp(timestamp);
try {
coll.save(entity.toDBObject());
} catch (MongoException e) {
LOGGER.warn("Unable to report histogram {}", name, e);
}
}
示例6: reportCounter
import com.mongodb.DBCollection; //导入方法依赖的package包/类
private void reportCounter(final String name, final Counter counter, final Date timestamp) {
final DBCollection coll = db.getCollection("metric_counter");
final CounterEntity entity = new CounterEntity();
entity.setName(prefix(name, "count"));
entity.setCount(counter.getCount());
entity.setTimestamp(timestamp);
try {
coll.save(entity.toDBObject());
} catch (MongoException e) {
LOGGER.warn("Unable to report counter {}", name, e);
}
}
示例7: save
import com.mongodb.DBCollection; //导入方法依赖的package包/类
public String save() throws SinfonierException {
try {
DBCollection collection = MongoFactory.getDB().getCollection(getCollectionName());
if (id == null) {
Logger.info("New topology");
DBObject dbObj = this.toDBObject();
updateUsedModulesCount(true);
collection.save(dbObj);
this.id = dbObj.get(FIELD_ID).toString();
} else {
Logger.info("Editing topology id:" + this.getId());
DBObject query = new BasicDBObject(FIELD_ID, new ObjectId(this.getId()));
DBObject toSet = this.toDBObject();
// Remove fields's unmodified
toSet.removeField(FIELD_ID);
toSet.removeField(FIELD_CREATED);
toSet.removeField(FIELD_AUTHOR_ID);
// Update field's update
toSet.put(FIELD_UPDATED, new Date());
updateUsedModulesCount(false);
collection.update(query, new BasicDBObject("$set", toSet), true, false);
}
return this.getId();
} catch (MongoException.DuplicateKey e) {
Logger.error(e, e.getMessage());
throw new SinfonierException(SinfonierError.TOPOLOGY_DUPLICATE, e, this.name);
}
}
示例8: save
import com.mongodb.DBCollection; //导入方法依赖的package包/类
/**
* 保存
* @param dbName
* @param dbObject
*/
public static void save(String dbName, String collName, DBObject dbObject) {
DBCollection collection = getCollection(dbName, collName);
if (collection != null) {
collection.save(dbObject);
}
}
示例9: add
import com.mongodb.DBCollection; //导入方法依赖的package包/类
public void add(JsonObject meeting) {
DBCollection coll = getColl();
DBObject existing = coll.findOne(meeting.getString("id"));
DBObject obj = MeetingsUtil.meetingAsMongo(meeting, existing);
coll.save(obj);
}
示例10: testQuery
import com.mongodb.DBCollection; //导入方法依赖的package包/类
public void testQuery() {
DBCollection collection = db.getCollection("msg");
Iterator<DBObject> iterator = collection.find().limit(10).iterator();
while (iterator.hasNext()) {
DBObject next = iterator.next();
next.put("fromId", "642693");
collection.save(next);
}
}
示例11: setUp
import com.mongodb.DBCollection; //导入方法依赖的package包/类
@Before
public void setUp() {
DB db = mongo.getDB("test");
DBCollection col = db.createCollection("testing", new BasicDBObject());
col.save(new BasicDBObject("greeting", "hello"));
col.save(new BasicDBObject("greeting", "hola"));
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:8,代码来源:MongodbSourceApplicationTests.java
示例12: update
import com.mongodb.DBCollection; //导入方法依赖的package包/类
/**
* Method to update an existing node category entity.
*
* @param objectToUpdate Node category entity to update.
* @param targetCollection Collection where the node category entity
* is located in the database.
*/
public void update(final DBObject objectToUpdate, final DBCollection targetCollection) {
targetCollection.remove(objectToUpdate);
DBObject _dbObject = this.getDbObject();
targetCollection.save(_dbObject);
String _name = this.getName();
String _plus = (_name +
" node category has been updated.");
ConfigSpaceGenerator.LOGGER.info(_plus);
}
示例13: update
import com.mongodb.DBCollection; //导入方法依赖的package包/类
/**
* Method to update an existing component type entity.
*
* @param objectToUpdate Component type entity to update.
* @param targetCollection Collection where the component type entity
* is located in the database.
*/
public void update(final DBObject objectToUpdate, final DBCollection targetCollection) {
targetCollection.remove(objectToUpdate);
DBObject _dbObject = this.getDbObject();
targetCollection.save(_dbObject);
String _name = this.getName();
String _plus = (_name +
" component type has been updated.");
ConfigSpaceGenerator.LOGGER.info(_plus);
}
示例14: update
import com.mongodb.DBCollection; //导入方法依赖的package包/类
/**
* Method to update an existing goal description entity.
*
* @param objectToUpdate Goal description entity to update.
* @param targetCollection Collection where the goal description entity
* is located in the database.
*/
public void update(final DBObject objectToUpdate, final DBCollection targetCollection) {
targetCollection.remove(objectToUpdate);
DBObject _dbObject = this.getDbObject();
targetCollection.save(_dbObject);
String _name = this.getName();
String _plus = (_name +
" goal has been updated.");
ConfigSpaceGenerator.LOGGER.info(_plus);
}