Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Override
public Iterator<Tuple> executeBackendQuery(CustomQuery customQuery, QueryParameters queryParameters, EntityKeyMetadata[] metadatas) {
//e.g. "db.Item.find({ foo : bar })
String query = customQuery.getSQL();
// parse via Parboiled
QueryDescriptor qd = new QueryParser().parse( query );
//qd.collection = "Item"
//qd.payload = "{ foo : bar }"
//qd.operation = Ops.FIND
DBCollection collection = provider.getDatabase().getCollection( qd.getCollection() );
if ( qd.getOperation == Ops.FIND ) {
DBObject queryObj = JSON.parse( qd.getPayload() );
DBObject proj = JSON.parse( qd.getProjection() );
DBCursor cursor = collection.find( queryObj, proj );
}
// in case of executeUpdate()
else if ( qd.getOperation() = Ops.INSERT ) {
collection.insert( qd.getQuery() );
}
else if () {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment