Project Page | SparkAlpha
Here are some instructions for getting running with the spark preview.
It shows how scripts work in spark, and different ways you can connect to the database using hibernate in spark. The client is pritty simple, something I built quickly to test the remoting methods.
To expose a method for remoting you use the meta object. This object is only in the context during compile.
addMethod(String methodName, String paramTypes, String returnType) addInterface(String className) setExtends(String className) Examples: // add a business interface, all these methods will be exposed to remoting clients meta.addInterface('some.business.package.MyBusinessObject'); // add a method which will be exposed to remoting clients meta.addMethod('myRemotingFunc','String,Integer','java.util.List'); function myRemotingFunc(someStr,someNum){ var list = new Packages.java.util.LinkedList(); list.add(someStr); list.add(someNum); return list; }
Why is this needed? Its used by the compiler to generate a interface used to expose the script to remoting.
This is how scripts access beans in the spring application context, access the http session, etc.
This is exposed to scripts as the spark object. Here is the api.
getCookie(req,name) getResources(path) getResource(file) getMessageSource() getApplicationContext() getBeans() addCookie(cookie) createCookie(name, value) getCookieByName(name) getCookies() getSession(create) getSession() /* Note: Need to add access to all or part of http request object. DONE in SVN. Examples: */ var isAuth = spark.session.getAttribute('user_auth'); var someService = spark.beans.getBean('serviceInSpring');
As this java api is called from js you can call get methods as properties so spark.getSession() and spark.session will both work.
Each script also has a log object. This is just a standard log4j logger. so have all the normal methods. debug(msg), isDebugEnabled() etc. For more info see log4j.
The other option is print() this prints values via System.out.println();. You should try to avoid it.
more info to follow.
Discussion