Search in sources :

Example 1 with MongoMapping

use of org.apache.gora.mongodb.store.MongoMapping in project gora by apache.

the class DefaultFactory method transformFieldFilter.

protected DBObject transformFieldFilter(final SingleFieldValueFilter<K, T> fieldFilter, final MongoStore<K, T> store) {
    MongoMapping mapping = store.getMapping();
    String dbFieldName = mapping.getDocumentField(fieldFilter.getFieldName());
    FilterOp filterOp = fieldFilter.getFilterOp();
    List<Object> operands = fieldFilter.getOperands();
    QueryBuilder builder = QueryBuilder.start(dbFieldName);
    builder = appendToBuilder(builder, filterOp, operands);
    if (!fieldFilter.isFilterIfMissing()) {
        // If false, the find query will pass if the column is not found.
        DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get();
        builder = QueryBuilder.start().or(notExist, builder.get());
    }
    return builder.get();
}
Also used : DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) QueryBuilder(com.mongodb.QueryBuilder) MongoMapping(org.apache.gora.mongodb.store.MongoMapping) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 2 with MongoMapping

use of org.apache.gora.mongodb.store.MongoMapping in project gora by apache.

the class DefaultFactory method transformMapFilter.

protected DBObject transformMapFilter(final MapFieldValueFilter<K, T> mapFilter, final MongoStore<K, T> store) {
    MongoMapping mapping = store.getMapping();
    String dbFieldName = mapping.getDocumentField(mapFilter.getFieldName()) + "." + store.encodeFieldKey(mapFilter.getMapKey().toString());
    FilterOp filterOp = mapFilter.getFilterOp();
    List<Object> operands = mapFilter.getOperands();
    QueryBuilder builder = QueryBuilder.start(dbFieldName);
    builder = appendToBuilder(builder, filterOp, operands);
    if (!mapFilter.isFilterIfMissing()) {
        // If false, the find query will pass if the column is not found.
        DBObject notExist = QueryBuilder.start(dbFieldName).exists(false).get();
        builder = QueryBuilder.start().or(notExist, builder.get());
    }
    return builder.get();
}
Also used : DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) QueryBuilder(com.mongodb.QueryBuilder) MongoMapping(org.apache.gora.mongodb.store.MongoMapping) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)2 DBObject (com.mongodb.DBObject)2 QueryBuilder (com.mongodb.QueryBuilder)2 MongoMapping (org.apache.gora.mongodb.store.MongoMapping)2