package lan.dk.podcastserver.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.auditing.DateTimeProvider;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.GregorianCalendar;

import static java.time.ZonedDateTime.now;

/**
 * Created by kevin on 11/04/15
 */
@Configuration
@ComponentScan("lan.dk.podcastserver.repository")
@EnableJpaAuditing(dateTimeProviderRef = "dateTimeProvider")
public class DataSourceConfig {

    @Bean
    public DataSource dataSource(
            @Value("${spring.datasource.username:sa}") String user,
            @Value("${spring.datasource.password:}") String password,
            @Value("${spring.datasource.url}") String url,
            @Value("${spring.datasource.driver-class-name}") String driveClassName) throws SQLException {

        HikariDataSource dataSource = new HikariDataSource();

        dataSource.setDriverClassName(driveClassName);
        dataSource.setJdbcUrl(url);
        dataSource.setUsername(user);
        dataSource.setPassword(password);

        return dataSource;
    }

    @Bean
    DateTimeProvider dateTimeProvider() {
        return () -> GregorianCalendar.from(now());
    }
}
@@ -438,16 +438,95 @@
 uditing;
+%0Aimport org.springframework.transaction.annotation.EnableTransactionManagement;
 %0A%0Aimport
@@ -764,16 +764,45 @@
 itory%22)%0A
+@EnableTransactionManagement%0A
 @EnableJ

enable transaction management by annotation