Package com.jverstry.Configuration

Source Code of com.jverstry.Configuration.InMemoryDataSource

package com.jverstry.Configuration;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;

@Configuration
public class InMemoryDataSource implements DisposableBean {
   
    private EmbeddedDatabase ed;
   
    @Bean(name="hsqlInMemory")
  public EmbeddedDatabase hsqlInMemory() {
       
        if ( this.ed == null ) {
           
            EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
           
            this.ed = builder.setType(EmbeddedDatabaseType.HSQL)
                .addScript("aclSchema.sql").build();
           
        }
       
        return this.ed;
       
  }
   
    @Override
    public void destroy() {

        if ( this.ed != null ) {
            this.ed.shutdown();
        }

    }
   
}
TOP

Related Classes of com.jverstry.Configuration.InMemoryDataSource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.