package com.tiarebalbi.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * Contexto da camada de persistencia
 * 
 * @author Tiarê Balbi Bonamini
 */
@Configuration
@ComponentScan(basePackages="com.tiarebalbi.entity")
@EnableJpaRepositories("com.tiarebalbi.repository")
@EnableJpaAuditing
@EnableTransactionManagement
@PropertySource(value="classpath:application.properties")
public class DataContext {
	
	@Autowired
	private Environment env;
	
	/**
	 * Bootstraps an in-memory Derby database.
	 * 
	 * @return {@link DataSource}
	 * http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/htmlsingle/#jdbc-embedded-database-using-Derby 
	 */
	@Bean
	public DataSource dataSource() {
		EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
		return builder.setType(EmbeddedDatabaseType.DERBY).build();
	}
	
	/**
	 * @return {@link LocalContainerEntityManagerFactoryBean}
	 */
	@Bean
	public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

		HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
		vendorAdapter.setDatabase(Database.DERBY);
		vendorAdapter.setGenerateDdl(true);

		LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
		factory.setJpaVendorAdapter(vendorAdapter);
		factory.setPackagesToScan(this.env.getRequiredProperty("entity.package.scan"));
		factory.setDataSource(dataSource());

		return factory;
	}
	
	/**
	 * @return {@link PlatformTransactionManager}
	 */
	@Bean
	public PlatformTransactionManager transactionManager() {

		JpaTransactionManager txManager = new JpaTransactionManager();
		txManager.setEntityManagerFactory(entityManagerFactory().getObject());
		return txManager;
	}

}

@@ -1495,47 +1495,59 @@
 %09 * 
-Bootstraps an in-memory Derby database.
+Configura%C3%A7%C3%A3o do DataSource com o banco Apache Derby
 %0A%09 *

Update DataContext.java