JacksonDBCollection<MongoData, Object> collection =
JacksonDBCollection
.wrap(db.getCollection(DB_NAME), MongoData.class);
// Build the query.
QueryBuilder queryBuilder = QueryBuilder.start();
// Only select data for a single user.
queryBuilder.and(Data.JSON_KEY_OWNER).is(owner);
// Only select data for a given schema.
queryBuilder.and(Schema.JSON_KEY_ID).is(schemaId);
// Only select data for a given version of the the given schema.
queryBuilder.and(Schema.JSON_KEY_VERSION).is(version);
// Create the projection.
DBObject projection = new BasicDBObject();
// Add the owner field.
projection.put(Data.JSON_KEY_OWNER, 1);
// Add the schema ID field.
projection.put(Schema.JSON_KEY_ID, 1);
// Add the schema version.
projection.put(Schema.JSON_KEY_VERSION, 1);
// Add the meta-data field.
projection.put(Data.JSON_KEY_METADATA, 1);
// Add all of the data or add only the specified columns if given.
if(columnList.size() == 0) {
projection.put(Data.JSON_KEY_DATA, 1);
}
else {
if((columnList != null) && (columnList.size() > 0)) {
for(String column : columnList.toList()) {
projection
.put(
Data.JSON_KEY_DATA +
ColumnList.COLUMN_SEPARATOR +
column,
1);
}
}
}
// Build the query.
DBCursor<MongoData> dbResult =
collection.find(queryBuilder.get(), projection);
// Build the sort field by sorting in reverse chronological order.
DBObject sort = new BasicDBObject();
sort.put(
Data.JSON_KEY_METADATA +