org.jeecg.common.system.vo.DynamicDataSourceModel Java Examples
The following examples show how to use
org.jeecg.common.system.vo.DynamicDataSourceModel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicDBUtil.java From jeecg-cloud with Apache License 2.0 | 6 votes |
/** * 通过 dbKey ,获取数据源 * * @param dbKey * @return */ public static DruidDataSource getDbSourceByDbKey(final String dbKey) { //获取多数据源配置 DynamicDataSourceModel dbSource = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey); //先判断缓存中是否存在数据库链接 DruidDataSource cacheDbSource = DataSourceCachePool.getCacheBasicDataSource(dbKey); if (cacheDbSource != null && !cacheDbSource.isClosed()) { log.debug("--------getDbSourceBydbKey------------------从缓存中获取DB连接-------------------"); return cacheDbSource; } else { DruidDataSource dataSource = getJdbcDataSource(dbSource); if(dataSource!=null && dataSource.isEnable()){ DataSourceCachePool.putCacheBasicDataSource(dbKey, dataSource); }else{ throw new JeecgBootException("动态数据源连接失败,dbKey:"+dbKey); } log.info("--------getDbSourceBydbKey------------------创建DB数据库连接-------------------"); return dataSource; } }
Example #2
Source File: DynamicDBUtil.java From teaching with Apache License 2.0 | 6 votes |
/** * 获取数据源【最底层方法,不要随便调用】 * * @param dbSource * @return */ @Deprecated private static BasicDataSource getJdbcDataSource(final DynamicDataSourceModel dbSource) { BasicDataSource dataSource = new BasicDataSource(); String driverClassName = dbSource.getDbDriver(); String url = dbSource.getDbUrl(); String dbUser = dbSource.getDbUsername(); String dbPassword = dbSource.getDbPassword(); //设置数据源的时候,要重新解密 // String dbPassword = PasswordUtil.decrypt(dbSource.getDbPassword(), dbSource.getDbUsername(), PasswordUtil.getStaticSalt());//解密字符串; dataSource.setDriverClassName(driverClassName); dataSource.setUrl(url); dataSource.setUsername(dbUser); dataSource.setPassword(dbPassword); return dataSource; }
Example #3
Source File: DynamicDBUtil.java From teaching with Apache License 2.0 | 6 votes |
/** * 通过 dbKey ,获取数据源 * * @param dbKey * @return */ public static BasicDataSource getDbSourceByDbKey(final String dbKey) { //获取多数据源配置 DynamicDataSourceModel dbSource = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey); //先判断缓存中是否存在数据库链接 BasicDataSource cacheDbSource = DataSourceCachePool.getCacheBasicDataSource(dbKey); if (cacheDbSource != null && !cacheDbSource.isClosed()) { log.debug("--------getDbSourceBydbKey------------------从缓存中获取DB连接-------------------"); return cacheDbSource; } else { BasicDataSource dataSource = getJdbcDataSource(dbSource); DataSourceCachePool.putCacheBasicDataSource(dbKey, dataSource); log.info("--------getDbSourceBydbKey------------------创建DB数据库连接-------------------"); return dataSource; } }
Example #4
Source File: DynamicDBUtil.java From jeecg-boot with Apache License 2.0 | 6 votes |
/** * 通过 dbKey ,获取数据源 * * @param dbKey * @return */ public static DruidDataSource getDbSourceByDbKey(final String dbKey) { //获取多数据源配置 DynamicDataSourceModel dbSource = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey); //先判断缓存中是否存在数据库链接 DruidDataSource cacheDbSource = DataSourceCachePool.getCacheBasicDataSource(dbKey); if (cacheDbSource != null && !cacheDbSource.isClosed()) { log.debug("--------getDbSourceBydbKey------------------从缓存中获取DB连接-------------------"); return cacheDbSource; } else { DruidDataSource dataSource = getJdbcDataSource(dbSource); if(dataSource!=null && dataSource.isEnable()){ DataSourceCachePool.putCacheBasicDataSource(dbKey, dataSource); }else{ throw new JeecgBootException("动态数据源连接失败,dbKey:"+dbKey); } log.info("--------getDbSourceBydbKey------------------创建DB数据库连接-------------------"); return dataSource; } }
Example #5
Source File: DataSourceCachePool.java From jeecg-cloud with Apache License 2.0 | 5 votes |
/** * 获取多数据源缓存 * * @param dbKey * @return */ public static DynamicDataSourceModel getCacheDynamicDataSourceModel(String dbKey) { String redisCacheKey = CacheConstant.SYS_DYNAMICDB_CACHE + dbKey; if (getRedisTemplate().hasKey(redisCacheKey)) { return (DynamicDataSourceModel) getRedisTemplate().opsForValue().get(redisCacheKey); } ISysBaseAPI sysBaseAPI = SpringContextUtils.getBean(ISysBaseAPI.class); DynamicDataSourceModel dbSource = sysBaseAPI.getDynamicDbSourceByCode(dbKey); if (dbSource != null) { getRedisTemplate().opsForValue().set(redisCacheKey, dbSource); } return dbSource; }
Example #6
Source File: DynamicDBUtil.java From jeecg-cloud with Apache License 2.0 | 5 votes |
/** * 获取数据源【最底层方法,不要随便调用】 * * @param dbSource * @return */ private static DruidDataSource getJdbcDataSource(final DynamicDataSourceModel dbSource) { DruidDataSource dataSource = new DruidDataSource(); String driverClassName = dbSource.getDbDriver(); String url = dbSource.getDbUrl(); String dbUser = dbSource.getDbUsername(); String dbPassword = dbSource.getDbPassword(); dataSource.setDriverClassName(driverClassName); dataSource.setUrl(url); //dataSource.setValidationQuery("SELECT 1 FROM DUAL"); dataSource.setTestWhileIdle(true); dataSource.setTestOnBorrow(false); dataSource.setTestOnReturn(false); dataSource.setBreakAfterAcquireFailure(true); dataSource.setConnectionErrorRetryAttempts(0); dataSource.setUsername(dbUser); dataSource.setMaxWait(60000); dataSource.setPassword(dbPassword); log.info("******************************************"); log.info("* *"); log.info("*====【"+dbSource.getCode()+"】=====Druid连接池已启用 ====*"); log.info("* *"); log.info("******************************************"); return dataSource; }
Example #7
Source File: DataSourceCachePool.java From teaching with Apache License 2.0 | 5 votes |
/** * 获取多数据源缓存 * * @param dbKey * @return */ public static DynamicDataSourceModel getCacheDynamicDataSourceModel(String dbKey) { DynamicDataSourceModel dbSource = dynamicDbSourcesCache.get(dbKey); if (dbSource == null) { ISysBaseAPI sysBaseAPI = SpringContextUtils.getBean(ISysBaseAPI.class); dbSource = sysBaseAPI.getDynamicDbSourceByCode(dbKey); dynamicDbSourcesCache.put(dbKey, dbSource); dynamicDbSourcesIdToCode.put(dbSource.getId(), dbKey); } return dbSource; }
Example #8
Source File: DataSourceCachePool.java From jeecg-boot with Apache License 2.0 | 5 votes |
/** * 获取多数据源缓存 * * @param dbKey * @return */ public static DynamicDataSourceModel getCacheDynamicDataSourceModel(String dbKey) { String redisCacheKey = CacheConstant.SYS_DYNAMICDB_CACHE + dbKey; if (getRedisTemplate().hasKey(redisCacheKey)) { return (DynamicDataSourceModel) getRedisTemplate().opsForValue().get(redisCacheKey); } ISysBaseAPI sysBaseAPI = SpringContextUtils.getBean(ISysBaseAPI.class); DynamicDataSourceModel dbSource = sysBaseAPI.getDynamicDbSourceByCode(dbKey); if (dbSource != null) { getRedisTemplate().opsForValue().set(redisCacheKey, dbSource); } return dbSource; }
Example #9
Source File: DynamicDBUtil.java From jeecg-boot with Apache License 2.0 | 5 votes |
/** * 获取数据源【最底层方法,不要随便调用】 * * @param dbSource * @return */ private static DruidDataSource getJdbcDataSource(final DynamicDataSourceModel dbSource) { DruidDataSource dataSource = new DruidDataSource(); String driverClassName = dbSource.getDbDriver(); String url = dbSource.getDbUrl(); String dbUser = dbSource.getDbUsername(); String dbPassword = dbSource.getDbPassword(); dataSource.setDriverClassName(driverClassName); dataSource.setUrl(url); //dataSource.setValidationQuery("SELECT 1 FROM DUAL"); dataSource.setTestWhileIdle(true); dataSource.setTestOnBorrow(false); dataSource.setTestOnReturn(false); dataSource.setBreakAfterAcquireFailure(true); dataSource.setConnectionErrorRetryAttempts(0); dataSource.setUsername(dbUser); dataSource.setMaxWait(60000); dataSource.setPassword(dbPassword); log.info("******************************************"); log.info("* *"); log.info("*====【"+dbSource.getCode()+"】=====Druid连接池已启用 ====*"); log.info("* *"); log.info("******************************************"); return dataSource; }
Example #10
Source File: DataSourceCachePool.java From teaching with Apache License 2.0 | 4 votes |
/** * 动态数据源参数配置【缓存】 */ public static Map<String, DynamicDataSourceModel> getCacheAllDynamicDataSourceModel() { return dynamicDbSourcesCache; }
Example #11
Source File: SqlUtils.java From jeecg-cloud with Apache License 2.0 | 2 votes |
/** * 生成分页查询 SQL * * @param sql * @param page * @param rows * @return */ public static String createPageSqlByDBKey(String dbKey, String sql, int page, int rows) { DynamicDataSourceModel dynamicSourceEntity = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey); String dbType = dynamicSourceEntity.getDbType(); return createPageSqlByDBType(dbType, sql, page, rows); }
Example #12
Source File: SqlUtils.java From teaching with Apache License 2.0 | 2 votes |
/** * 生成分页查询 SQL * * @param sql * @param page * @param rows * @return */ public static String createPageSqlByDBKey(String dbKey, String sql, int page, int rows) { DynamicDataSourceModel dynamicSourceEntity = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey); String dbType = dynamicSourceEntity.getDbType(); return createPageSqlByDBType(dbType, sql, page, rows); }
Example #13
Source File: SqlUtils.java From jeecg-boot with Apache License 2.0 | 2 votes |
/** * 生成分页查询 SQL * * @param sql * @param page * @param rows * @return */ public static String createPageSqlByDBKey(String dbKey, String sql, int page, int rows) { DynamicDataSourceModel dynamicSourceEntity = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey); String dbType = dynamicSourceEntity.getDbType(); return createPageSqlByDBType(dbType, sql, page, rows); }