Currently I have a small workaround for this that is not super elegant and required creating objects to wrap the java classes in the javascript side, that inject the parameter [Database] automatically in the java class and with this we are avoiding the user to set the parameter all the time (annoying) and to send the Database /Connection class to the javascript engine every time that we receive a request in the controller.
So,
I created a JSEngine service because we need to use hot executions and use the same engine all the time to use already "compiled" code ... :
@Singleton
public class JavascriptEngine implements JSEngine {
private Database db;
ScriptEngineManager factory;
ScriptEngine engine;
@Inject
public JavascriptEngine(Database db) {
this.db = db;
....
and
Basically I'm setting a special variable inside the javascript engine every time that I receive a request in the controller and sending the Database object
to the javascript side/engine: (not perfect)
public class ControllerA extends Controller {
@Inject
JavascriptEngine jsengine;
....
jsengine.addToEngine(db); // this basically calls the method (engine.put("DS_DATABASE",db);)
works fine, but I want to know if you have a better approach for this or any suggestion ?
Thanks
Regards
-Luis