package com.aemreunal.config;


import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;

/*
 ***************************
 * Copyright (c) 2014      *
 *                         *
 * This code belongs to:   *
 *                         *
 * @author Ahmet Emre Ünal *
 * S001974                 *
 *                         *
 * aemreunal@gmail.com     *
 * emre.unal@ozu.edu.tr    *
 *                         *
 * aemreunal.com           *
 ***************************
 */

@Configuration
@PropertySource("file:db.properties")
public class DatabaseSettings {
    private static final String DB_DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";

    @Value("${db.username}")
    private String dbUsername;

    @Value("${db.password}")
    private String dbPassword;

    @Value("${db.ip}")
    private String dbIp;

    @Value("${db.port}")
    private String dbPort;

    @Value("${db.name}")
    private String dbName;

    @Bean
    public HibernateJpaVendorAdapter vendorAdapter() {
        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        vendorAdapter.setDatabase(DatabaseSettings.DB_TYPE);
        vendorAdapter.setGenerateDdl(true);
        vendorAdapter.setShowSql(GlobalSettings.SHOW_SQL);
        return vendorAdapter;
    }

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(DB_DRIVER_CLASS_NAME);
        dataSource.setUrl(getDbUrl());
        dataSource.setUsername(dbUsername);
        dataSource.setPassword(dbPassword);
        return dataSource;
    }

    private String getDbUrl() {
        return "jdbc:mysql://" + dbIp + ":" + dbPort + "/" + dbName + "?useUnicode=true&characterEncoding=UTF-8";
    }

    public static final Database DB_TYPE = Database.MYSQL;
}

@@ -24,16 +24,400 @@
 onfig;%0A%0A
+/*%0A ***************************%0A * Copyright (c) 2014      *%0A *                         *%0A * This code belongs to:   *%0A *                         *%0A * @author Ahmet Emre %C3%9Cnal *%0A * S001974                 *%0A *                         *%0A * aemreunal@gmail.com     *%0A * emre.unal@ozu.edu.tr    *%0A *                         *%0A * aemreunal.com           *%0A ***************************%0A */%0A
 %0Aimport 
@@ -865,392 +865,37 @@
 er;%0A
-%0A/*%0A ***************************%0A * Copyright (c) 2014      *%0A *                         *%0A * This code belongs to:   *%0A *                         *%0A * @author Ahmet Emre %C3%9Cnal *%0A * S001974                 *%0A *                         *%0A * aemreunal@gmail.com     *%0A * emre.unal@ozu.edu.tr    *%0A *                         *%0A * aemreunal.com           *%0A ***************************%0A */
+import com.mysql.jdbc.Driver;
 %0A%0A@C
@@ -981,89 +981,8 @@
 s %7B%0A
-    private static final String DB_DRIVER_CLASS_NAME = %22com.mysql.jdbc.Driver%22;%0A%0A
     
@@ -1448,24 +1448,14 @@
 base
-Settings.DB_TYPE
+.MYSQL
 );%0A 
@@ -1759,27 +1759,29 @@
 me(D
-B_DRIVER_CLASS_NAME
+river.class.getName()
 );%0A 
@@ -1936,24 +1936,194 @@
 rce;%0A    %7D%0A%0A
+    // We need to call this dynamically and can't make it a field,%0A    // as the other fields this depends on are assigned dynamically%0A    // during runtime via '@Value'%0A
     private 
@@ -2267,65 +2267,6 @@
  %7D%0A%0A
-    public static final Database DB_TYPE = Database.MYSQL;%0A
 %7D%0A

Refactor DB settings