Skip to content

Instantly share code, notes, and snippets.

@gunnarmorling
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gunnarmorling/c4a4826b6e7c11615a72 to your computer and use it in GitHub Desktop.
Save gunnarmorling/c4a4826b6e7c11615a72 to your computer and use it in GitHub Desktop.
@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