use of org.bson.codecs.EncoderContext in project morphia by mongodb.
the class Filters method expr.
/**
* Allows use of aggregation expressions within the query language.
*
* @param expression the expression to evaluate
* @return the filter
* @query.filter $expr
*/
public static Filter expr(Expression expression) {
return new Filter("$expr", null, expression) {
@Override
public void encode(Datastore datastore, BsonWriter writer, EncoderContext context) {
writer.writeName("$expr");
Expression value = getValue();
if (value != null) {
wrapExpression(datastore, writer, value, context);
} else {
writer.writeNull();
}
}
@Override
public Expression getValue() {
return (Expression) super.getValue();
}
};
}
use of org.bson.codecs.EncoderContext in project engine by Lumeer.
the class UserCodec method encode.
@Override
public void encode(final BsonWriter bsonWriter, final User user, final EncoderContext encoderContext) {
Document bson = user.getId() != null ? new Document(ID, new ObjectId(user.getId())) : new Document();
bson.append(NAME, user.getName()).append(EMAIL, user.getEmail());
if (user.getGroups() != null) {
List<Document> groupsArray = user.getGroups().entrySet().stream().map(entry -> new Document(ORGANIZATION_ID, entry.getKey()).append(GROUPS, entry.getValue())).collect(Collectors.toList());
bson.append(ALL_GROUPS, groupsArray);
}
documentCodec.encode(bsonWriter, bson, encoderContext);
}
use of org.bson.codecs.EncoderContext in project morphia by mongodb.
the class MorphiaQuery method getQueryDocument.
Document getQueryDocument() {
DocumentWriter writer = new DocumentWriter(mapper, seedQuery);
document(writer, () -> {
EncoderContext context = EncoderContext.builder().build();
for (Filter filter : filters) {
filter.encode(datastore, writer, context);
}
});
Document query = writer.getDocument();
if (mapper.isMappable(getEntityClass())) {
mapper.updateQueryWithDiscriminators(mapper.getEntityModel(getEntityClass()), query);
}
return query;
}
Aggregations