use of com.mongodb.DBObject in project jetty.project by eclipse.
the class MongoSessionDataStore method doGetExpired.
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
*/
@Override
public Set<String> doGetExpired(Set<String> candidates) {
long now = System.currentTimeMillis();
long upperBound = now;
Set<String> expiredSessions = new HashSet<>();
//firstly ask mongo to verify if these candidate ids have expired - all of
//these candidates will be for our node
BasicDBObject query = new BasicDBObject();
query.append(__ID, new BasicDBObject("$in", candidates));
query.append(__EXPIRY, new BasicDBObject("$gt", 0).append("$lt", upperBound));
DBCursor verifiedExpiredSessions = null;
try {
verifiedExpiredSessions = _dbSessions.find(query, new BasicDBObject(__ID, 1));
for (DBObject session : verifiedExpiredSessions) {
String id = (String) session.get(__ID);
if (LOG.isDebugEnabled())
LOG.debug("{} Mongo confirmed expired session {}", _context, id);
expiredSessions.add(id);
}
} finally {
if (verifiedExpiredSessions != null)
verifiedExpiredSessions.close();
}
//if this is our first expiry check, make sure that we only grab really old sessions
if (_lastExpiryCheckTime <= 0)
upperBound = (now - (3 * (1000L * _gracePeriodSec)));
else
upperBound = _lastExpiryCheckTime - (1000L * _gracePeriodSec);
query = new BasicDBObject();
BasicDBObject gt = new BasicDBObject(__EXPIRY, new BasicDBObject("$gt", 0));
BasicDBObject lt = new BasicDBObject(__EXPIRY, new BasicDBObject("$lt", upperBound));
BasicDBList list = new BasicDBList();
list.add(gt);
list.add(lt);
query.append("and", list);
DBCursor oldExpiredSessions = null;
try {
BasicDBObject bo = new BasicDBObject(__ID, 1);
bo.append(__EXPIRY, 1);
oldExpiredSessions = _dbSessions.find(query, bo);
for (DBObject session : oldExpiredSessions) {
String id = (String) session.get(__ID);
if (LOG.isDebugEnabled())
LOG.debug("{} Mongo found old expired session {}", _context, id + " exp=" + session.get(__EXPIRY));
expiredSessions.add(id);
}
} finally {
oldExpiredSessions.close();
}
return expiredSessions;
}
use of com.mongodb.DBObject in project jetty.project by eclipse.
the class MongoTest method main.
public static void main(String... args) throws Exception {
Mongo m = new Mongo("127.0.0.1", 27017);
DB db = m.getDB("mydb");
Set<String> colls = db.getCollectionNames();
System.err.println("Colls=" + colls);
DBCollection coll = db.getCollection("testCollection");
BasicDBObject key = new BasicDBObject("id", "1234");
BasicDBObject sets = new BasicDBObject("name", "value");
BasicDBObject upsert = new BasicDBObject("$set", sets);
WriteResult result = coll.update(key, upsert, true, false);
System.err.println(result.getLastError());
while (coll.count() > 0) {
DBObject docZ = coll.findOne();
System.err.println("removing " + docZ);
if (docZ != null)
coll.remove(docZ);
}
}
use of com.mongodb.DBObject in project jetty.project by eclipse.
the class SessionExpiryTest method getSessionMaxInactiveInterval.
public long getSessionMaxInactiveInterval(DBCollection sessions, String id) throws Exception {
assertNotNull(sessions);
assertNotNull(id);
DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID, id));
assertNotNull(o);
Long inactiveInterval = (Long) o.get(MongoSessionDataStore.__MAX_IDLE);
return (inactiveInterval == null ? null : inactiveInterval.longValue());
}
use of com.mongodb.DBObject 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.DBObject 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;
}
Aggregations