Commit 078451e78d6d67b06382ccc00b77dd1bbfcac6aa

Authored by 王通
1 parent a4bf89a2

1.encrypt

src/main/java/com/bsth/util/AppProperties.java 0 → 100644
  1 +package com.bsth.util;
  2 +
  3 +import org.springframework.beans.factory.annotation.Value;
  4 +import org.springframework.stereotype.Component;
  5 +
  6 +/**
  7 + * @author Hill
  8 + */
  9 +@Component
  10 +public class AppProperties {
  11 +
  12 + private static String scheduleDataUrl;
  13 +
  14 + private static String scheduleSecret;
  15 +
  16 + private static String gpsDataUrl;
  17 +
  18 + private static int cacheDays;
  19 +
  20 + public static String getScheduleDataUrl() {
  21 + return scheduleDataUrl;
  22 + }
  23 +
  24 + @Value("${http.control.service_data_url}")
  25 + public void setScheduleDataUrl(String scheduleDataUrl) {
  26 + AppProperties.scheduleDataUrl = scheduleDataUrl;
  27 + }
  28 +
  29 + public static String getScheduleSecret() {
  30 + return scheduleSecret;
  31 + }
  32 +
  33 + @Value("${http.control.secret.key}")
  34 + public void setScheduleSecret(String scheduleSecret) {
  35 + AppProperties.scheduleSecret = scheduleSecret;
  36 + }
  37 +
  38 + public static String getGpsDataUrl() {
  39 + return gpsDataUrl;
  40 + }
  41 +
  42 + @Value("${http.gps.real.url}")
  43 + public void setGpsDataUrl(String gpsDataUrl) {
  44 + AppProperties.gpsDataUrl = gpsDataUrl;
  45 + }
  46 +
  47 + public static int getCacheDays() {
  48 + return cacheDays;
  49 + }
  50 +
  51 + @Value("${cache.days}")
  52 + public void setCacheDays(int cacheDays) {
  53 + AppProperties.cacheDays = cacheDays;
  54 + }
  55 +}
src/main/java/com/bsth/util/DBUtils_Xxfb.java 0 → 100644
  1 +package com.bsth.util;
  2 +
  3 +import com.mchange.v2.c3p0.DataSources;
  4 +import org.apache.log4j.Logger;
  5 +import org.springframework.beans.factory.InitializingBean;
  6 +import org.springframework.beans.factory.annotation.Value;
  7 +import org.springframework.jdbc.core.JdbcTemplate;
  8 +import org.springframework.stereotype.Component;
  9 +
  10 +import javax.sql.DataSource;
  11 +import java.sql.Connection;
  12 +import java.sql.ResultSet;
  13 +import java.sql.SQLException;
  14 +import java.sql.Statement;
  15 +import java.util.HashMap;
  16 +import java.util.Map;
  17 +
  18 +/**
  19 + * 网关ms库连接池
  20 + * @author PanZhao
  21 + *
  22 + */
  23 +@Component
  24 +public class DBUtils_Xxfb implements InitializingBean {
  25 +
  26 + @Value("${xxfb.mysql.driver}")
  27 + private String driver;
  28 +
  29 + @Value("${xxfb.mysql.url}")
  30 + private String url = null;
  31 +
  32 + @Value("${xxfb.mysql.username}")
  33 + private String username = null;
  34 +
  35 + @Value("${xxfb.mysql.password}")
  36 + private String pwd = null;
  37 +
  38 + private static DataSource ds_pooled;
  39 +
  40 + private static JdbcTemplate jdbcTemplate;
  41 +
  42 + static Logger logger = Logger.getLogger(DBUtils_Xxfb.class);
  43 +
  44 + /**
  45 + * 获取连接对象
  46 + */
  47 + public static Connection getConnection() throws SQLException {
  48 + return ds_pooled.getConnection();
  49 + }
  50 +
  51 + /**
  52 + * 释放连接池资源
  53 + */
  54 + public static void clearup() {
  55 + if (ds_pooled != null) {
  56 + try {
  57 + DataSources.destroy(ds_pooled);
  58 + } catch (SQLException e) {
  59 + logger.error(e.toString());
  60 + e.printStackTrace();
  61 + }
  62 + }
  63 + }
  64 +
  65 + /**
  66 + * 资源关闭
  67 + *
  68 + * @param rs
  69 + * @param stmt
  70 + * @param conn
  71 + */
  72 + public static void close(ResultSet rs, Statement stmt, Connection conn) {
  73 + if (rs != null) {
  74 + try {
  75 + rs.close();
  76 + } catch (SQLException e) {
  77 + logger.error(e.toString());
  78 + e.printStackTrace();
  79 + }
  80 + }
  81 +
  82 + if (stmt != null) {
  83 + try {
  84 + stmt.close();
  85 + } catch (SQLException e) {
  86 + logger.error(e.toString());
  87 + e.printStackTrace();
  88 + }
  89 + }
  90 +
  91 + if (conn != null) {
  92 + try {
  93 + conn.close();
  94 + } catch (SQLException e) {
  95 + logger.error(e.toString());
  96 + e.printStackTrace();
  97 + }
  98 + }
  99 + }
  100 +
  101 + public static DataSource getDataSource(){
  102 + return ds_pooled;
  103 + }
  104 +
  105 + public static JdbcTemplate getJdbcTemplate() {
  106 + return jdbcTemplate;
  107 + }
  108 +
  109 + @Override
  110 + public void afterPropertiesSet() throws Exception {
  111 + try {
  112 + Class.forName(driver);
  113 + // 设置连接数据库的配置信息
  114 + DataSource ds_un_pooled = DataSources.unpooledDataSource(url, username, pwd);
  115 + Map<String, Object> pool_conf = new HashMap<>();
  116 + // 设置最大连接数
  117 + pool_conf.put("maxPoolSize", 10);
  118 +
  119 + pool_conf.put("testConnectionOnCheckout", false);
  120 + //异步检测连接的有效性
  121 + pool_conf.put("testConnectionOnCheckin", true);
  122 + //30秒检测一次
  123 + pool_conf.put("idleConnectionTestPeriod", 30);
  124 + ds_pooled = DataSources.pooledDataSource(ds_un_pooled, pool_conf);
  125 + jdbcTemplate = new JdbcTemplate(ds_pooled);
  126 + } catch (ClassNotFoundException e) {
  127 + logger.error(e.toString());
  128 + } catch (SQLException e) {
  129 + logger.error(e.toString());
  130 + }
  131 + }
  132 +}