Tuesday, 2 April 2013

Execute Spring ACL SQL Script In Memory

This post describes how to execute the Spring ACL script to create ACL tables in an in-memory HSQL database instance. The code is available at GitHub in the Execute-ACL-SQL-Scripts-In-Memory directory.

In-Memory DataSource

We are using a configuration classe implementing the DisposableBean interface to shut down the created HSQL embedded database nicely.
public class InMemoryDataSource implements DisposableBean {

    private EmbeddedDatabase ed;

    public EmbeddedDatabase hsqlInMemory() {

        if ( this.ed == null ) {

            EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();

            this.ed = builder.setType(EmbeddedDatabaseType.HSQL)


        return this.ed;


    public void destroy() {

        if ( this.ed != null ) {


When creating the database, we also have the aclSchema.sql script executed. It must be located at the root of the resource directory:

The content of the script is taken from the Spring documentation appendix.

Checking Table Creation

We extract the list table of tables in the controller. Technically speaking, we should do this at the service/DAO level, but for the sake of this example, we'll keep it simple:
public class MyController {

    EmbeddedDatabase hsqlInMemory;

    @RequestMapping(value = "/")
    public ModelAndView home() {

        ModelAndView result = new ModelAndView("index");

        ArrayList<String> tables = new ArrayList<String>();

        JdbcTemplate tplate = new JdbcTemplate(hsqlInMemory);

        SqlRowSet retr = tplate.queryForRowSet(

        while (retr.next()) {

        result.addObject("tables", tables);

        return result;



Running The Example

One can run it using the maven tomcat:run goal. Then, browse:


We find the tables we have created:

More Spring related posts here.