List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start()
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public long deleteUsers(DataCreationState creationState) { BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start(); if (creationState != null) { queryObjBuilder.add(FIELD_CREATION_STATE, creationState.toString()); }//from w w w . j a v a 2s . c om DBObject queryObj = queryObjBuilder.get(); WriteResult result = collection.remove(queryObj); return result.getN(); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
/** * Find a user by username//from w w w .ja v a 2 s . co m * * @return the {@link UserData} found otherwise <tt>null</tt. */ @Override public UserData findUserByUsername(String username) { DBObject queryObj = BasicDBObjectBuilder.start().add(FIELD_USERNAME, username).get(); DBObject userDataObj = collection.findOne(queryObj); return fromDBObject(userDataObj); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public UserData findUserByEmail(String email) { DBObject queryObj = BasicDBObjectBuilder.start().add(FIELD_EMAIL, email).get(); DBObject userDataObj = collection.findOne(queryObj); return fromDBObject(userDataObj); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public List<UserData> getUsersByCreationState(DataCreationState creationState, int startIndex, int count) { DBObject queryObj = BasicDBObjectBuilder.start().add(FIELD_CREATION_STATE, creationState.toString()).get(); DBObject sortObj = BasicDBObjectBuilder.start().add(FIELD_RANDOMIZER, 1).get(); DBCursor cursor = collection.find(queryObj).sort(sortObj).skip(startIndex).limit(count); return fromDBCursor(cursor); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public UserData getRandomUser() { int random = (int) (Math.random() * (double) 1e6); DBObject queryObj = BasicDBObjectBuilder.start() .add(FIELD_CREATION_STATE, DataCreationState.Created.toString()).push(FIELD_RANDOMIZER) .add("$gte", Integer.valueOf(random)).pop().get(); DBObject userDataObj = collection.findOne(queryObj); if (userDataObj == null) { queryObj.put(FIELD_RANDOMIZER, new BasicDBObject("$lt", random)); userDataObj = collection.findOne(queryObj); }// www. j ava 2 s .co m return fromDBObject(userDataObj); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public List<UserData> getUsersInDomain(String domain, int startIndex, int count) { DBObject queryObj = BasicDBObjectBuilder.start().add(FIELD_DOMAIN, domain) .add(FIELD_CREATION_STATE, DataCreationState.Created.toString()).get(); DBCursor cursor = collection.find(queryObj).skip(startIndex).limit(count); return fromDBCursor(cursor); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
private Range getRandomizerRange(List<String> domains) { BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start().add(FIELD_CREATION_STATE, DataCreationState.Created.toString()); if (domains.size() > 0) { queryObjBuilder.push(FIELD_DOMAIN).add("$in", domains).pop(); }// ww w.ja v a 2s. co m DBObject queryObj = queryObjBuilder.get(); DBObject fieldsObj = BasicDBObjectBuilder.start().add(FIELD_RANDOMIZER, Boolean.TRUE).get(); DBObject sortObj = BasicDBObjectBuilder.start().add(FIELD_RANDOMIZER, -1).get(); // Find max DBObject resultObj = collection.findOne(queryObj, fieldsObj, sortObj); int maxRandomizer = resultObj == null ? 0 : (Integer) resultObj.get(FIELD_RANDOMIZER); // Find min sortObj.put(FIELD_RANDOMIZER, +1); resultObj = collection.findOne(queryObj, fieldsObj, sortObj); int minRandomizer = resultObj == null ? 0 : (Integer) resultObj.get(FIELD_RANDOMIZER); return new Range(minRandomizer, maxRandomizer); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public UserData getRandomUserFromDomains(List<String> domains) { Range range = getRandomizerRange(domains); int upper = range.getMax(); int lower = range.getMin(); int random = lower + (int) (Math.random() * (double) (upper - lower)); BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start() .add(FIELD_CREATION_STATE, DataCreationState.Created.toString()).push(FIELD_RANDOMIZER) .add("$gte", random).pop(); if (domains.size() > 0) { queryObjBuilder.push(FIELD_DOMAIN).add("$in", domains).pop(); }//from www .j a v a2 s. com DBObject queryObj = queryObjBuilder.get(); DBObject userDataObj = collection.findOne(queryObj); return fromDBObject(userDataObj); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public void addUserGroups(String username, List<String> groups) { DBObject queryObj = BasicDBObjectBuilder.start().add(FIELD_USERNAME, username).get(); DBObject updateObj = BasicDBObjectBuilder.start().push("$addToSet").push(FIELD_GROUPS).add("$each", groups) .pop().pop().get();//from www .jav a 2s .co m collection.update(queryObj, updateObj); }
From source file:org.alfresco.bm.user.UserDataServiceImpl.java
License:Open Source License
@Override public void removeUserGroups(String username, List<String> groups) { DBObject queryObj = BasicDBObjectBuilder.start().add(FIELD_USERNAME, username).get(); DBObject updateObj = BasicDBObjectBuilder.start().push("$pullAll").add(FIELD_GROUPS, groups).pop().get(); collection.update(queryObj, updateObj); }