You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					
					
						
							76 lines
						
					
					
						
							3.1 KiB
						
					
					
				
			
		
		
	
	
							76 lines
						
					
					
						
							3.1 KiB
						
					
					
				| //package com.ynxbd.common.config.db;
 | |
| //
 | |
| //import com.ynxbd.common.helper.FileHelper;
 | |
| //import com.zaxxer.hikari.HikariConfig;
 | |
| //import com.zaxxer.hikari.HikariDataSource;
 | |
| //import org.slf4j.Logger;
 | |
| //import org.slf4j.LoggerFactory;
 | |
| //
 | |
| //import java.sql.Connection;
 | |
| //import java.sql.SQLException;
 | |
| //import java.util.List;
 | |
| //import java.util.Properties;
 | |
| //
 | |
| //public class PacsDB {
 | |
| //    private final static Logger log = LoggerFactory.getLogger(PacsDB.class);
 | |
| //
 | |
| //    private static HikariDataSource dataSource;
 | |
| //
 | |
| //    static {
 | |
| //        dataSource = init();
 | |
| //    }
 | |
| //
 | |
| //    private static synchronized HikariDataSource init() {
 | |
| //        HikariConfig config = new HikariConfig();
 | |
| //        Properties properties = DataBase.getPropertiesConfig();
 | |
| //
 | |
| //        config.setPoolName("hikari_pool_pacs");
 | |
| //        config.setDriverClassName(FileHelper.propertiesGetString(properties, "pacs.driverClassName"));
 | |
| //        config.setJdbcUrl(FileHelper.propertiesGetString(properties, "pacs.jdbcUrl"));
 | |
| //        config.setUsername(FileHelper.propertiesGetString(properties, "pacs.username"));
 | |
| //        config.setPassword(FileHelper.propertiesGetString(properties, "pacs.password"));
 | |
| //        //
 | |
| //        config.addDataSourceProperty("cachePrepStmts", "true");        // 是否自定义配置,为true时下面两个参数才生效
 | |
| //        config.addDataSourceProperty("prepStmtCacheSize", "250");      // 连接池大小默认25,官方推荐250-500
 | |
| //        config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); // 单条语句最大长度默认256,官方推荐2048
 | |
| //        // 最大空闲时间
 | |
| //        Long idleTimeout = FileHelper.propertiesGetLong(properties, "pacs.idleTimeout");
 | |
| //        if (idleTimeout != null) config.setIdleTimeout(idleTimeout);
 | |
| //        // 最大连接数量
 | |
| //        Integer maximumPoolSize = FileHelper.propertiesGetInteger(properties, "pacs.maximumPoolSize");
 | |
| //        if (maximumPoolSize != null) config.setMaximumPoolSize(maximumPoolSize);
 | |
| //
 | |
| //        config.setPoolName("pacs");
 | |
| //        config.setConnectionTestQuery("SELECT 1");
 | |
| //        return new HikariDataSource(config);
 | |
| //    }
 | |
| //
 | |
| //
 | |
| //    /**
 | |
| //     * 获取连接
 | |
| //     */
 | |
| //    public static Connection getConnection() {
 | |
| //        Connection conn = null;
 | |
| //        try {
 | |
| //            if (dataSource == null) {
 | |
| //                dataSource = init();
 | |
| //            }
 | |
| //            conn = dataSource.getConnection();
 | |
| //        } catch (SQLException e) {
 | |
| //            log.error("PACS数据库连接失败!{}, {}", dataSource.getJdbcUrl(), e.getMessage());
 | |
| //            if (dataSource != null) {
 | |
| //                dataSource.close();
 | |
| //                dataSource = null;
 | |
| //            }
 | |
| //        }
 | |
| //        return conn;
 | |
| //    }
 | |
| //
 | |
| //    public static <T> List<T> select(String sql, Class<T> clazz, DataBase.IPS ips) {
 | |
| //        return DataBase.select(getConnection(), sql, clazz, ips);
 | |
| //    }
 | |
| //
 | |
| //    public static <T> List<T> select(String sql, Class<T> clazz) {
 | |
| //        return DataBase.select(getConnection(), sql, clazz, null);
 | |
| //    }
 | |
| //}
 | |
| 
 |