use of com.mongodb.DBCollection in project qi4j-sdk by Qi4j.
the class MongoMapEntityStoreMixin method applyChanges.
@Override
public void applyChanges(MapChanges changes) throws IOException {
db.requestStart();
final DBCollection entities = db.getCollection(collectionName);
changes.visitMap(new MapChanger() {
@Override
public Writer newEntity(final EntityReference ref, EntityDescriptor entityDescriptor) throws IOException {
return new StringWriter(1000) {
@Override
public void close() throws IOException {
super.close();
String jsonState = toString();
DBObject bsonState = (DBObject) JSON.parse(jsonState);
BasicDBObject entity = new BasicDBObject();
entity.put(IDENTITY_COLUMN, ref.identity());
entity.put(STATE_COLUMN, bsonState);
entities.insert(entity, writeConcern);
}
};
}
@Override
public Writer updateEntity(final EntityReference ref, EntityDescriptor entityDescriptor) throws IOException {
return new StringWriter(1000) {
@Override
public void close() throws IOException {
super.close();
DBObject bsonState = (DBObject) JSON.parse(toString());
BasicDBObject entity = new BasicDBObject();
entity.put(IDENTITY_COLUMN, ref.identity());
entity.put(STATE_COLUMN, bsonState);
entities.update(byIdentity(ref), entity, false, false, writeConcern);
}
};
}
@Override
public void removeEntity(EntityReference ref, EntityDescriptor entityDescriptor) throws EntityNotFoundException {
DBObject entity = entities.findOne(byIdentity(ref));
if (entity == null) {
throw new EntityNotFoundException(ref);
}
entities.remove(entity, writeConcern);
}
});
db.requestDone();
}
use of com.mongodb.DBCollection in project Mycat-Server by MyCATApache.
the class MongoSQLParser method dropTable.
private int dropTable(SQLDropTableStatement state) {
for (SQLTableSource table : state.getTableSources()) {
DBCollection coll = this._db.getCollection(table.toString());
coll.drop();
}
return 1;
}
use of com.mongodb.DBCollection in project Mycat-Server by MyCATApache.
the class MongoSQLParser method UpData.
private int UpData(SQLUpdateStatement state) {
SQLTableSource table = state.getTableSource();
DBCollection coll = this._db.getCollection(table.toString());
SQLExpr expr = state.getWhere();
DBObject query = parserWhere(expr);
BasicDBObject set = new BasicDBObject();
for (SQLUpdateSetItem col : state.getItems()) {
set.put(getFieldName2(col.getColumn()), getExpValue(col.getValue()));
}
DBObject mod = new BasicDBObject("$set", set);
coll.updateMulti(query, mod);
//System.out.println("changs count:"+coll.getStats().size());
return 1;
}
use of com.mongodb.DBCollection in project mongomvcc by igd-geo.
the class MongoDBVDatabaseBenchmark method plainOldInsertDelete.
/**
* Inserts a lot of documents using plain old MongoDB and then deletes them
*/
@Test
@BenchmarkOptions(benchmarkRounds = 2, warmupRounds = 1)
public void plainOldInsertDelete() {
plainOldInsert();
DBCollection coll = _db.getCollection("persons");
for (long i = 0; i < DOCUMENTS; ++i) {
coll.remove(new BasicDBObject("_id", 1 + i));
}
}
use of com.mongodb.DBCollection in project mongomvcc by igd-geo.
the class MongoDBVDatabaseBenchmark method plainOldInsertDeleteInsertQuery.
/**
* Queries a lot of objects after inserting, deleting and inserting again
*/
@Test
@BenchmarkOptions(benchmarkRounds = 2, warmupRounds = 1)
public void plainOldInsertDeleteInsertQuery() {
plainOldInsertDeleteInsert();
_master.commit();
DBCollection coll = _db.getCollection("persons");
for (DBObject o : coll.find()) {
assertTrue(((Long) o.get("age")).longValue() >= DOCUMENTS);
}
}
Aggregations