I have this rather “crazy” idea to have a “stored procedure” facility in my application. Basically, my app is data-centric and that it can access the datastore through some form of Restful interface.
I want to have the functionality to manipulate data (which is a JSON string) in many ways, like
- increment/decrement
- hash/encrypt/decrypt and all sorts of stuff
My initial
implementation was to create a Java class that will do these operations. Typical.
However, I want to have the flexibility in doing such manipulations. That is, I can add a procedure to manipulate data on-the-fly, that is, like a
script that can be selected and will process the retrieved data and then save it back
again in the datastore.
For example:
http://127.0.0.1:8888/resources?key=somekey&operation=funkyops
This will cause the server to internally fetch the Entity with such key then manipulate the data and save the Entity back to the datastore.
Retrieving and persisting logic can be hardcoded but the “stored procedure” must be
stored in the datastore as a script or something like that and then when selected will
be passed into some sort of processing block.
Here’s a concrete example of what I am trying to do: HashBend.java
Any ideas on how I can achieve this?
You could use the javascript engine: see “Scripting for the Java Platform” http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/
for ex: