private String createDynamicDataSourceRouting(Integer customerId, String currentDbUUID) { log.info(">>>>>> 【添加客户数据源】: addCustomDataSource" + "\n>>>>>> customerId:{}", customerId); List<TCusDbServerPO> cusDbServerQueries = cusDbserverMapper.listCustomerById(customerId); if (cusDbServerQueries.size() != 1) { throw new GoLoginException(SystemExceptionEnum.LOGIN_USERINFO_ERROR); } TCusDbServerPO cusDbserver = cusDbServerQueries.get(0); DataSourceProperty dataSourceProperty = new DataSourceProperty(); String decodePassword = null; try { decodePassword = DesUtil.hhComDecode(cusDbserver.getPassword()); } catch (Exception e) { throw new MySystemException(SystemExceptionEnum.INTERNAL_SERVER_ERROR.getCode(), e.getMessage()); } dataSourceProperty.setPoolName(cusDbserver.getDbName()); dataSourceProperty.setUsername(cusDbserver.getUsername()); dataSourceProperty.setPassword(decodePassword);
String url = dynamicDbProperties.getPgsqlUrl(cusDbserver.getInnerAddress(),cusDbserver.getInnerport(),cusDbserver.getDbName()); Integer dev = Optional.ofNullable(systemDefineProperties.getDev()).orElse(1); if (dev == 1) { url = dynamicDbProperties.getPgsqlUrl(cusDbserver.getOuterAddress(),cusDbserver.getOuterPort(),cusDbserver.getDbName()); } dataSourceProperty.setUrl(url); dataSourceProperty.setDriverClassName(dynamicDbProperties.getPgsqlDriver()); dataSourceProperty.setLazy(true); DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; long startTime = System.currentTimeMillis(); DataSource dataSource = dataSourceCreator.createDataSource(dataSourceProperty); long time1 = System.currentTimeMillis(); String dbName = cusDbserver.getCustomerId() + cusDbserver.getDbName() + "_" + currentDbUUID; ds.addDataSource(dbName, dataSource); long time2 = System.currentTimeMillis(); log.info(">>>>>> 【数据源连接】:getDynamicRoutingDataSource" + "\n>>>>>> url: {}" + "\n>>>>>> connectionName: {}" + "\n>>>>>> createDataSource: {}" + "\n>>>>>> addDataSource: {}", url, dbName, time1-startTime,time2-startTime);
private String createDynamicDataSourceRouting(Integer customerId, String currentDbUUID) { log.info(">>>>>> 【添加客户数据源】: addCustomDataSource" + "\n>>>>>> customerId:{}", customerId); List<TCusDbServerPO> cusDbServerQueries = cusDbserverMapper.listCustomerById(customerId); if (cusDbServerQueries.size() != 1) { throw new GoLoginException(SystemExceptionEnum.LOGIN_USERINFO_ERROR); } TCusDbServerPO cusDbserver = cusDbServerQueries.get(0); DataSourceProperty dataSourceProperty = new DataSourceProperty(); String decodePassword = null; try { decodePassword = DesUtil.hhComDecode(cusDbserver.getPassword()); } catch (Exception e) { throw new MySystemException(SystemExceptionEnum.INTERNAL_SERVER_ERROR.getCode(), e.getMessage()); } dataSourceProperty.setPoolName(cusDbserver.getDbName()); dataSourceProperty.setUsername(cusDbserver.getUsername()); dataSourceProperty.setPassword(decodePassword);
String url = dynamicDbProperties.getPgsqlUrl(cusDbserver.getInnerAddress(),cusDbserver.getInnerport(),cusDbserver.getDbName()); Integer dev = Optional.ofNullable(systemDefineProperties.getDev()).orElse(1); if (dev == 1) { url = dynamicDbProperties.getPgsqlUrl(cusDbserver.getOuterAddress(),cusDbserver.getOuterPort(),cusDbserver.getDbName()); } dataSourceProperty.setUrl(url); dataSourceProperty.setDriverClassName(dynamicDbProperties.getPgsqlDriver()); dataSourceProperty.setLazy(true); DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource; long startTime = System.currentTimeMillis(); DataSource dataSource = dataSourceCreator.createDataSource(dataSourceProperty); long time1 = System.currentTimeMillis(); String dbName = cusDbserver.getCustomerId() + cusDbserver.getDbName() + "_" + currentDbUUID; ds.addDataSource(dbName, dataSource); long time2 = System.currentTimeMillis(); log.info(">>>>>> 【数据源连接】:getDynamicRoutingDataSource" + "\n>>>>>> url: {}" + "\n>>>>>> connectionName: {}" + "\n>>>>>> createDataSource: {}" + "\n>>>>>> addDataSource: {}", url, dbName, time1-startTime,time2-startTime); return dbName; }
|