package it.reply.orchestrator.config;

import javax.annotation.Resource;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import it.reply.workflowManager.spring.orchestrator.annotations.WorkflowPersistenceUnit;
import it.reply.workflowManager.utils.Constants;

@Configuration
@EnableTransactionManagement(proxyTargetClass = true)
public class WorklfowPersistenceConfigTest {

  @Resource
  private Environment environment;

  @Bean(destroyMethod = "shutdown")
  public DataSource workflowDataSource() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    EmbeddedDatabase dataSource = builder.setType(EmbeddedDatabaseType.H2)
        .addScripts("h2-jbpm-schema.sql").build();
    return dataSource;
  }

  @Bean
  @WorkflowPersistenceUnit
  public LocalContainerEntityManagerFactoryBean workflowEntityManagerFactory()
      throws NamingException {
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setPersistenceUnitName(Constants.PERSISTENCE_UNIT_NAME);
    factory.setPersistenceXmlLocation("classpath:/META-INF/persistence-test.xml");
    factory.setJtaDataSource(workflowDataSource());
    return factory;
  }
}

@@ -132,24 +132,55 @@
 DataSource;%0D
+%0A%0D%0Aimport org.h2.tools.Server;%0D
 %0Aimport org.
@@ -711,24 +711,57 @@
 agement;%0D%0A%0D%0A
+import java.sql.SQLException;%0D%0A%0D%0A
 import it.re
@@ -1335,24 +1335,24 @@
 ).build();%0D%0A
-
     return d
@@ -1366,24 +1366,222 @@
 ce;%0D%0A  %7D%0D%0A%0D%0A
+  @Bean(initMethod = %22start%22, destroyMethod = %22stop%22)%0D%0A  public Server h2WebServer() throws SQLException %7B%0D%0A    return Server.createWebServer(%22-web%22, %22-webAllowOthers%22, %22-webPort%22, %228082%22);%0D%0A  %7D%0D%0A%0D%0A
   @Bean%0D%0A  @

Add embedded DB web interface