/** * Actually makes the transformation form Jongo to the Object. * * @param findOne Find object to transform. * @return a Object with the results <b>null</b> if nothing is found. */ protected T returnSimple(final FindOne findOne) { return findOne.as(clazz); }
@Override public T get(ObjectId id) { T entity = collection.findOne(id).as(entityClass); return entity; }
@Override public ReportNode getReportNodeByParentIDAndArtefactID(ObjectId parentID, ObjectId artefactID) { assert parentID != null; assert artefactID!=null; return collection.findOne("{parentID: #, artefactID: #}", parentID, artefactID).as(ReportNode.class); }
@Override public User getByUsername(String username) { assert username != null; return collection.findOne("{username: #}", username).as(User.class); }
@Override public ReportNode getRootReportNode(String executionID) { assert executionID!=null; return collection.findOne("{executionID: '" + executionID + "', parentID: null}").as(ReportNode.class); }
@Override public T findByAttributes(Map<String, String> attributes) { JsonObjectBuilder builder = jsonProvider.createObjectBuilder(); for(String key:attributes.keySet()) { builder.add("attributes."+key, attributes.get(key)); } String query = builder.build().toString(); return collection.findOne(query).as(entityClass); }
protected AbstractArtefact findByAttributes(Map<String, String> attributes, boolean rootOnly) { JsonObjectBuilder builder = jsonProvider.createObjectBuilder(); for(String key:attributes.keySet()) { builder.add("attributes."+key, attributes.get(key)); } if(rootOnly) { builder.add("root", true); } String query = builder.build().toString(); return collection.findOne(query).as(AbstractArtefact.class); }
public ControllerSetting getSettingByKey(String key) { JsonObjectBuilder builder = jsonProvider.createObjectBuilder(); builder.add("key", key); String query = builder.build().toString(); return collection.findOne(query).as(ControllerSetting.class); } }
@Override public T findOne(final String query, final Object... queryParams) throws MongoDataException { try { return getCollection().findOne(query, queryParams).as(clazz); } catch (MongoException ex) { String msg = "Unable to find document by query " + query + " of type " + clazz.getName() + " with params " + Arrays.toString(queryParams); log.error(msg, ex); throw new MongoDataException(msg, ex); } }
@Override public T findByStringId(final String id) throws MongoDataException { try { return getCollection().findOne("{_id:#}", id).as(clazz); } catch (MongoException ex) { String msg = "Unable to find document of type " + clazz.getName() + " by id '" + id + "'"; log.error(msg, ex); throw new MongoDataException(msg, ex); } }
/** * Refreshes the state according to the latest version as a preceding step * before recursive call. * With this mechanism, changes on different State property will be safely * merged. However, with * interwoven execution order among multiple threads, multiple updates on * the same State property * is not guaranteed to be executed properly. * */ private synchronized void reloadProperties() { final MongoState updatedState = collection.findOne("{_id: #}", getId()) .as(MongoState.class); if (updatedState != null) { timestamp = updatedState.timestamp; properties = updatedState.properties; } else { properties = Collections .synchronizedMap(new HashMap<String, JsonNode>()); timestamp = System.nanoTime(); } }
@Override public Optional<U> findUserByName(String name) { return Optional.fromNullable(users.get().findOne("{" + userRefStrategy.getNameProperty() + ": #}", name).as(userClass)); }
@Override public Optional<U> findUserByName(String name) { return Optional.fromNullable(users.get().findOne("{" + userRefStrategy.getNameProperty() + ": #}", name).as(userClass)); }
public Optional<U> findUserByKey(String key) { return Optional.fromNullable(users.get().findOne("{ _id: # }", userRefStrategy.toId(key)).as(userClass)); }
public Optional<U> findUserByKey(String key) { return Optional.fromNullable(users.get().findOne("{ _id: # }", userRefStrategy.toId(key)).as(userClass)); }
private UserCredentials findCredentialsForUserRef(String userRef) { return usersCredentials.get() .findOne("{ _id: # }", userRefStrategy.toId(userRef)).as(UserCredentials.class); }
private UserCredentials findCredentialsForUserRef(String userRef) { return usersCredentials.get() .findOne("{ _id: # }", userRefStrategy.toId(userRef)).as(UserCredentials.class); }
@Override public T findById(final String id) throws MongoDataException { if (!ObjectId.isValid(id)) { throw new IllegalArgumentException("Given String " + id + " is not a valid Object Id"); } try { return getCollection().findOne(new ObjectId(id)).as(clazz); } catch (MongoException ex) { String msg = "Unable to find document of type " + clazz.getName() + " by id '" + id + "'"; log.error(msg, ex); throw new MongoDataException(msg, ex); } catch (IllegalArgumentException ex) { String msg = "Given id '" + id + "' can't be converted to an ObjectId"; log.error(msg, ex); throw new MongoDataException(msg, ex); } }
@Override public Map<String, Object> _selectByPrimaryKey(Table table) { Map<String, Object> result = null; try { DB db = database.getDB(); Jongo jongo = new Jongo(db); FindOne find = null; if(table.getConditions().containsKey("_id")){ find = jongo.getCollection(table.getTableName()).findOne(new ObjectId(String.valueOf(table.getConditions().get("_id")))); }else{ find = jongo.getCollection(table.getTableName()).findOne(JsonUtils.objToJson(table.getConditions())); } result = find.as(Map.class); result.put("id", result.get("_id").toString()); } catch (MongoException e) { LOG.error("mongo findOne error", e); } return result; }
try { synchronized (this) { result = getCollection().findOne("{_id: #}", id).as( MongoState.class); if (result == null) {