package co.yiiu.pybbs.config;

import co.yiiu.pybbs.util.SpringContextUtil;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * Created by tomoya.
 * Copyright (c) 2018, All Rights Reserved.
 * https://yiiu.co
 */
@Configuration
public class DataSourceConfig {

    @Autowired
    private SiteConfig siteConfig;

    private HikariDataSource dataSource;

    public HikariDataSource instance() {
        if (siteConfig == null) siteConfig = SpringContextUtil.getBean(SiteConfig.class);
        if (dataSource != null) return dataSource;
//    HikariConfig config = new HikariConfig();
//    config.setDriverClassName(siteConfig.getDatasource_driver());
//    config.setJdbcUrl(siteConfig.getDatasource_url());
//    config.setUsername(siteConfig.getDatasource_username());
//    config.setPassword(siteConfig.getDatasource_password());
//    config.addDataSourceProperty("cachePrepStmts", true);
//    config.addDataSourceProperty("prepStmtCacheSize", 500);
//    config.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
//    config.setConnectionTestQuery("SELECT 1");
//    config.setAutoCommit(true);
//    //池中最小空闲链接数量
//    config.setMinimumIdle(10);
//    //池中最大链接数量
//    config.setMaximumPoolSize(50);
//    dataSource = new HikariDataSource(config);
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setMaximumPoolSize(100);
        dataSource.setMinimumIdle(10);
        dataSource.setDataSourceClassName("oracle.jdbc.pool.OracleDataSource");

        Properties properties = new Properties();
        properties.put("user", "");
        properties.put("password", "");
        properties.put("databaseName", "");
        properties.put("serverName", "192.168.xx.xx");
        properties.put("portNumber", "1521");
        properties.put("driverType", "thin");
        dataSource.setDataSourceProperties(properties);
        return dataSource;
    }

    @Bean(name = "dataSource")
    @DependsOn("dataSourceHelper")
    public DataSource dataSource() {
        return instance();
    }
}

@@ -69,16 +69,55 @@
 xtUtil;%0A
+import com.zaxxer.hikari.HikariConfig;%0A
 import c
@@ -147,24 +147,24 @@
 DataSource;%0A
-
 import org.s
@@ -417,37 +417,8 @@
 rce;
-%0Aimport java.util.Properties;
 %0A%0A/*
@@ -831,18 +831,20 @@
 Source;%0A
-//
+    
     Hika
@@ -881,18 +881,20 @@
 nfig();%0A
-//
+    
     conf
@@ -947,26 +947,28 @@
 _driver());%0A
-//
+    
     config.s
@@ -1006,30 +1006,32 @@
 rce_url());%0A
-//
+  
     
+  
 config.setUs
@@ -1071,30 +1071,32 @@
 sername());%0A
-//
+   
     
+ 
 config.setPa
@@ -1140,22 +1140,24 @@
 ord());%0A
-//
+ 
     
+   
 config.a
@@ -1198,26 +1198,28 @@
 ts%22, true);%0A
-//
+    
     config.a
@@ -1262,26 +1262,28 @@
 ize%22, 500);%0A
-//
+    
     config.a
@@ -1335,18 +1335,20 @@
  2048);%0A
-//
+    
     conf
@@ -1386,22 +1386,24 @@
 CT 1%22);%0A
-//
+  
     
+  
 config.s
@@ -1422,18 +1422,20 @@
 (true);%0A
-//
+    
     //%E6%B1%A0%E4%B8%AD
@@ -1439,26 +1439,28 @@
 /%E6%B1%A0%E4%B8%AD%E6%9C%80%E5%B0%8F%E7%A9%BA%E9%97%B2%E9%93%BE%E6%8E%A5%E6%95%B0%E9%87%8F%0A
-//
+    
     config.s
@@ -1474,26 +1474,28 @@
 umIdle(10);%0A
-//
+    
     //%E6%B1%A0%E4%B8%AD%E6%9C%80%E5%A4%A7%E9%93%BE%E6%8E%A5
@@ -1497,18 +1497,20 @@
 %E4%B8%AD%E6%9C%80%E5%A4%A7%E9%93%BE%E6%8E%A5%E6%95%B0%E9%87%8F%0A
-//
+    
     conf
@@ -1540,14 +1540,16 @@
 0);%0A
-//
+ 
     
+   
 data
@@ -1587,16 +1587,18 @@
 onfig);%0A
+//
         
@@ -1647,24 +1647,26 @@
 taSource();%0A
+//
         data
@@ -1693,24 +1693,26 @@
 lSize(100);%0A
+//
         data
@@ -1730,32 +1730,34 @@
 inimumIdle(10);%0A
+//
         dataSour
@@ -1820,17 +1820,21 @@
 urce%22);%0A
-%0A
+//%0A//
         
@@ -1871,24 +1871,26 @@
 operties();%0A
+//
         prop
@@ -1905,32 +1905,34 @@
 ut(%22user%22, %22%22);%0A
+//
         properti
@@ -1947,32 +1947,34 @@
 password%22, %22%22);%0A
+//
         properti
@@ -1997,24 +1997,26 @@
 Name%22, %22%22);%0A
+//
         prop
@@ -2054,24 +2054,26 @@
 68.xx.xx%22);%0A
+//
         prop
@@ -2102,24 +2102,26 @@
 %22, %221521%22);%0A
+//
         prop
@@ -2150,24 +2150,26 @@
 %22, %22thin%22);%0A
+//
         data

rollback code