Merge branch 'develop' of http://10.0.6.99/common/maat_service.git into develop
This commit is contained in:
@@ -33,35 +33,25 @@ public class ConfigCompile implements Serializable {
|
||||
@ApiModelProperty(value = "配置ID", required = true)
|
||||
private Long compileId;
|
||||
@ApiModelProperty(value = "业务ID", required = true)
|
||||
private Long service;
|
||||
private Integer service;
|
||||
@ApiModelProperty(value = "动作", required = true)
|
||||
private Integer action;
|
||||
@ApiModelProperty(value = "有害类型", required = false)
|
||||
private Integer contType;
|
||||
@ApiModelProperty(value = "有害性质", required = false)
|
||||
private Integer attrType;
|
||||
@ApiModelProperty(value = "内容标签", required = false)
|
||||
@ApiModelProperty(value = "分类", required = false)
|
||||
private String contType;
|
||||
@ApiModelProperty(value = "性质", required = false)
|
||||
private String attrType;
|
||||
@ApiModelProperty(value = "标签", required = false)
|
||||
private String contLabel;
|
||||
@ApiModelProperty(value = "任务", required = false)
|
||||
private Integer taskId;
|
||||
@ApiModelProperty(value = "保障期", required = false)
|
||||
private Integer guaranteeId;
|
||||
@ApiModelProperty(value = "事件", required = false)
|
||||
@ApiModelProperty(value = "来文函号ID", required = false)
|
||||
private Integer affairId;
|
||||
@ApiModelProperty(value = "子话题", required = false)
|
||||
private Integer topicId;
|
||||
@ApiModelProperty(value = "是否黑名单", required = true)
|
||||
private Long doBlacklist;
|
||||
private Integer doBlacklist;
|
||||
@ApiModelProperty(value = "是否生成日志", required = true)
|
||||
private Integer doLog;
|
||||
@ApiModelProperty(value = "生效范围", required = true)
|
||||
private Integer activeSys;
|
||||
@ApiModelProperty(value = "生效系统", required = true)
|
||||
private String effectiveRange;
|
||||
@ApiModelProperty(value = "管控比例", required = true)
|
||||
private Long configPercent;
|
||||
@ApiModelProperty(value = "管控方式", required = true)
|
||||
private Integer configOption;
|
||||
@ApiModelProperty(value = "开始时间", required = true)
|
||||
private Date startTime;
|
||||
@ApiModelProperty(value = "结束时间", required = true)
|
||||
@@ -76,14 +66,10 @@ public class ConfigCompile implements Serializable {
|
||||
private Long fatherCfgId;
|
||||
@ApiModelProperty(value = "操作时间", required = true)
|
||||
private Date opTime;
|
||||
@ApiModelProperty(value = "本地更新时间 ", required = true)
|
||||
private Date lastUpdate;
|
||||
|
||||
@ApiModelProperty(value = "编译分组关系列表", required = true)
|
||||
private List<ConfigGroupRelation> groupRelationList;
|
||||
|
||||
|
||||
|
||||
@ApiModelProperty(value = "字符串域分组列表", access = "", required = true)
|
||||
private List<StrRegion> strRegionList;
|
||||
|
||||
@@ -96,25 +82,9 @@ public class ConfigCompile implements Serializable {
|
||||
@ApiModelProperty(value = "摘要域分组列表", required = true)
|
||||
private List<DigestRegion> digestRegionList;
|
||||
|
||||
@ApiModelProperty(value="版本序列号", required=true)
|
||||
private Long procSeq;
|
||||
@ApiModelProperty(value = "生效范围IP域分组列表", required = true)
|
||||
private List<IpRegion> ipClientRangeList;
|
||||
|
||||
@JsonIgnore
|
||||
public Date getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}
|
||||
|
||||
public void setLastUpdate(Date lastUpdate) {
|
||||
this.lastUpdate = lastUpdate;
|
||||
}
|
||||
public Integer getActiveSys() {
|
||||
return activeSys;
|
||||
}
|
||||
|
||||
public void setActiveSys(Integer activeSys) {
|
||||
this.activeSys = activeSys;
|
||||
}
|
||||
|
||||
public Long getCompileId() {
|
||||
return compileId;
|
||||
}
|
||||
@@ -126,7 +96,7 @@ public class ConfigCompile implements Serializable {
|
||||
/**
|
||||
* @return service
|
||||
*/
|
||||
public Long getService() {
|
||||
public Integer getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
@@ -134,7 +104,7 @@ public class ConfigCompile implements Serializable {
|
||||
* @param service
|
||||
* 要设置的 service
|
||||
*/
|
||||
public void setService(Long service) {
|
||||
public void setService(Integer service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@@ -153,19 +123,19 @@ public class ConfigCompile implements Serializable {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public Integer getContType() {
|
||||
public String getContType() {
|
||||
return contType;
|
||||
}
|
||||
|
||||
public void setContType(Integer contType) {
|
||||
public void setContType(String contType) {
|
||||
this.contType = contType;
|
||||
}
|
||||
|
||||
public Integer getAttrType() {
|
||||
public String getAttrType() {
|
||||
return attrType;
|
||||
}
|
||||
|
||||
public void setAttrType(Integer attrType) {
|
||||
public void setAttrType(String attrType) {
|
||||
this.attrType = attrType;
|
||||
}
|
||||
|
||||
@@ -180,7 +150,7 @@ public class ConfigCompile implements Serializable {
|
||||
/**
|
||||
* @return doBlackList
|
||||
*/
|
||||
public Long getDoBlacklist() {
|
||||
public Integer getDoBlacklist() {
|
||||
return doBlacklist;
|
||||
}
|
||||
|
||||
@@ -188,7 +158,7 @@ public class ConfigCompile implements Serializable {
|
||||
* @param doBlackList
|
||||
* 要设置的 doBlackList
|
||||
*/
|
||||
public void setDoBlacklist(Long doBlacklist) {
|
||||
public void setDoBlacklist(Integer doBlacklist) {
|
||||
this.doBlacklist = doBlacklist;
|
||||
}
|
||||
|
||||
@@ -222,35 +192,6 @@ public class ConfigCompile implements Serializable {
|
||||
this.effectiveRange = effectiveRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return configPercent
|
||||
*/
|
||||
public Long getConfigPercent() {
|
||||
return configPercent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param configPercent
|
||||
* 要设置的 configPercent
|
||||
*/
|
||||
public void setConfigPercent(Long configPercent) {
|
||||
this.configPercent = configPercent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return configOption
|
||||
*/
|
||||
public Integer getConfigOption() {
|
||||
return configOption;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param configOption
|
||||
* 要设置的 configOption
|
||||
*/
|
||||
public void setConfigOption(Integer configOption) {
|
||||
this.configOption = configOption;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return startTime
|
||||
@@ -437,14 +378,6 @@ public class ConfigCompile implements Serializable {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public Integer getGuaranteeId() {
|
||||
return guaranteeId;
|
||||
}
|
||||
|
||||
public void setGuaranteeId(Integer guaranteeId) {
|
||||
this.guaranteeId = guaranteeId;
|
||||
}
|
||||
|
||||
public Integer getAffairId() {
|
||||
return affairId;
|
||||
}
|
||||
@@ -453,19 +386,12 @@ public class ConfigCompile implements Serializable {
|
||||
this.affairId = affairId;
|
||||
}
|
||||
|
||||
public Integer getTopicId() {
|
||||
return topicId;
|
||||
public List<IpRegion> getIpClientRangeList() {
|
||||
return ipClientRangeList;
|
||||
}
|
||||
|
||||
public void setTopicId(Integer topicId) {
|
||||
this.topicId = topicId;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Long getProcSeq() {
|
||||
return procSeq;
|
||||
}
|
||||
public void setProcSeq(Long procSeq) {
|
||||
this.procSeq = procSeq;
|
||||
public void setIpClientRangeList(List<IpRegion> ipClientRangeList) {
|
||||
this.ipClientRangeList = ipClientRangeList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ public class ConfigGroupRelation implements Serializable {
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -9021829042309605139L;
|
||||
@ApiModelProperty(value = "id", required = true)
|
||||
private Long id;
|
||||
@ApiModelProperty(value = "分组ID", required = true)
|
||||
private Long groupId;
|
||||
@ApiModelProperty(value = "编译ID", required = true)
|
||||
@@ -39,19 +37,7 @@ public class ConfigGroupRelation implements Serializable {
|
||||
private Integer isValid;
|
||||
@ApiModelProperty(value = "操作时间", required = true)
|
||||
private Date opTime;
|
||||
@ApiModelProperty(value = "本地更新时间", required = true)
|
||||
private Date lastUpdate;
|
||||
@ApiModelProperty(value = "版本序列号", required = true)
|
||||
private Long procSeq;
|
||||
|
||||
@JsonIgnore
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return groupId
|
||||
@@ -114,22 +100,4 @@ public class ConfigGroupRelation implements Serializable {
|
||||
this.opTime = opTime;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Date getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}
|
||||
|
||||
public void setLastUpdate(Date lastUpdate) {
|
||||
this.lastUpdate = lastUpdate;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Long getProcSeq() {
|
||||
return procSeq;
|
||||
}
|
||||
|
||||
public void setProcSeq(Long procSeq) {
|
||||
this.procSeq = procSeq;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ public class MaatConfig implements Serializable {
|
||||
*/
|
||||
private List<Map<String, String>> fileLikeRegionMapList;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private List<Map<String, String>> ipClientRangeMapList;
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
@@ -118,6 +122,15 @@ public class MaatConfig implements Serializable {
|
||||
this.fileLikeRegionMapList = fileLikeRegionMapList;
|
||||
}
|
||||
|
||||
public List<Map<String, String>> getIpClientRangeMapList() {
|
||||
return ipClientRangeMapList;
|
||||
}
|
||||
|
||||
public void setIpClientRangeMapList(
|
||||
List<Map<String, String>> ipClientRangeMapList) {
|
||||
this.ipClientRangeMapList = ipClientRangeMapList;
|
||||
}
|
||||
|
||||
public Integer getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ public class CompileJudge {
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public static boolean type2TableNameIsOk(Long serviceType, String tableName) {
|
||||
public static boolean type2TableNameIsOk(Integer serviceType, String tableName) {
|
||||
if (null != serviceType && null != tableName && !tableName.equals("")) {
|
||||
Map<Integer, Map<String, String>> tableRelation = ConfigSourcesService.getTableRelation();
|
||||
Map<String, String> map = tableRelation.get(serviceType.intValue());
|
||||
@@ -456,12 +456,6 @@ public class CompileJudge {
|
||||
if (null == configCompile.getEffectiveRange() || configCompile.getEffectiveRange().equals("")) {
|
||||
return "id为" + compileId + "的编译配置中effectiveRange不能为空";
|
||||
}
|
||||
if (null == configCompile.getConfigPercent()) {
|
||||
return "id为" + compileId + "的编译配置中configPercent不能为空";
|
||||
}
|
||||
if (null == configCompile.getConfigOption()) {
|
||||
return "id为" + compileId + "的编译配置中configOption不能为空";
|
||||
}
|
||||
if (null == configCompile.getStartTime()) {
|
||||
return "id为" + compileId + "的编译配置中startTime不能为空";
|
||||
}
|
||||
@@ -483,9 +477,6 @@ public class CompileJudge {
|
||||
if (null == configCompile.getOpTime()) {
|
||||
return "id为" + compileId + "的编译配置中opTime不能为空";
|
||||
}
|
||||
if (null == configCompile.getActiveSys()) {
|
||||
return "id为" + compileId + "的编译配置中activeSys不能为空";
|
||||
}
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
||||
@@ -358,7 +358,7 @@ public class CompileVal {
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public static boolean type2TableNameIsOk(Long serviceType, String tableName) {
|
||||
public static boolean type2TableNameIsOk(Integer serviceType, String tableName) {
|
||||
if (null != serviceType && null != tableName && !tableName.equals("")) {
|
||||
Map<Integer, Map<String, String>> tableRelation = ConfigSourcesService.getTableRelation();
|
||||
Map<String, String> map = tableRelation.get(serviceType.intValue());
|
||||
@@ -432,12 +432,6 @@ public class CompileVal {
|
||||
if (null == configCompile.getEffectiveRange() || configCompile.getEffectiveRange().equals("")) {
|
||||
return "id为" + compileId + "的编译配置中effectiveRange不能为空";
|
||||
}
|
||||
if (null == configCompile.getConfigPercent()) {
|
||||
return "id为" + compileId + "的编译配置中configPercent不能为空";
|
||||
}
|
||||
if (null == configCompile.getConfigOption()) {
|
||||
return "id为" + compileId + "的编译配置中configOption不能为空";
|
||||
}
|
||||
if (null == configCompile.getStartTime()) {
|
||||
return "id为" + compileId + "的编译配置中startTime不能为空";
|
||||
}
|
||||
@@ -459,9 +453,6 @@ public class CompileVal {
|
||||
if (null == configCompile.getOpTime()) {
|
||||
return "id为" + compileId + "的编译配置中opTime不能为空";
|
||||
}
|
||||
if (null == configCompile.getActiveSys()) {
|
||||
return "id为" + compileId + "的编译配置中activeSys不能为空";
|
||||
}
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@@ -645,18 +636,19 @@ public class CompileVal {
|
||||
+ "的域配置direction的值不正确,只能是0或1";
|
||||
}
|
||||
|
||||
if (ipRegion.getTableName().toLowerCase().equals("dj_ip_port")) {
|
||||
if (ipRegion.getProtocol() < 0 || ipRegion.getProtocol() > 255) {
|
||||
return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId()
|
||||
+ "的域配置tableName为dj_ip_port时,protocol的取值范围只能是0-255";
|
||||
}
|
||||
} else {
|
||||
if (ipRegion.getProtocol() != 0) {
|
||||
return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置tableName为"
|
||||
+ ipRegion.getTableName() + "时,protocol的值只能是0";
|
||||
}
|
||||
|
||||
}
|
||||
//zdx protocol验证?
|
||||
// if (ipRegion.getTableName().toLowerCase().equals("dj_ip_port")) {
|
||||
// if (ipRegion.getProtocol() < 0 || ipRegion.getProtocol() > 255) {
|
||||
// return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId()
|
||||
// + "的域配置tableName为dj_ip_port时,protocol的取值范围只能是0-255";
|
||||
// }
|
||||
// } else {
|
||||
// if (ipRegion.getProtocol() != 0) {
|
||||
// return "编译配置id为" + compileId + "的配置中ipRegionList中regionId为" + ipRegion.getRegionId() + "的域配置tableName为"
|
||||
// + ipRegion.getTableName() + "时,protocol的值只能是0";
|
||||
// }
|
||||
//
|
||||
// }
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@@ -694,14 +686,6 @@ public class CompileVal {
|
||||
return "编译配置id为" + compileId + "的配置中doLog的值只能是0(不需要),1(需要),2(只记录结构化日志,不记录非结构化日志)";
|
||||
}
|
||||
|
||||
if (configCompile.getActiveSys() < 1 || configCompile.getActiveSys() > 7) {
|
||||
return "编译配置id为" + compileId + "的配置中activeSys的值范围只能是1-7";
|
||||
}
|
||||
|
||||
if (configCompile.getConfigOption() != 1 && configCompile.getConfigOption() != 2) {
|
||||
return "编译配置id为" + compileId + "的配置中configOption的值只能是1或2";
|
||||
}
|
||||
|
||||
if (configCompile.getFatherCfgId() != 0) {
|
||||
return "编译配置id为" + compileId + "的配置中fatherCfgId的值只能是0";
|
||||
}
|
||||
|
||||
@@ -188,5 +188,7 @@ public final class Constants {
|
||||
* 数据中心B版数据库名称,程序中每次查询时使用的数据库名称 use HIVEBDBNAME
|
||||
*/
|
||||
public static final String HIVEBDBNAME = Configurations.getStringProperty("jdbc.hive.BName", "xa_z2_mesalog_hive");
|
||||
|
||||
public static final String DIGEST_GEN_TOOL_PATH = Configurations.getStringProperty("digest.gen.tool.path", "maat-redis/digest_gen");
|
||||
|
||||
}
|
||||
|
||||
@@ -377,6 +377,7 @@ public class BaseRestController {
|
||||
thread.setService(service);
|
||||
thread.setContent(fileInfo);
|
||||
thread.setOpAction(opAction);
|
||||
thread.setTraceCode(sdf.format(new Date())+(Math.round((Math.random()*9+1)*10000)+""));
|
||||
if (data != null && ConfigCommonSource.class.isAssignableFrom(data.getClass())) {
|
||||
System.out.println(data.getClass().getSimpleName());
|
||||
ConfigCommonSource source = (ConfigCommonSource) data;
|
||||
|
||||
@@ -577,28 +577,28 @@ public class ConfigTestController extends BaseRestController {
|
||||
System.out.println("compileId--------------------------" + compileId);
|
||||
ConfigCompileTest configCompile = new ConfigCompileTest();
|
||||
configCompile.setCompileId(compileId);
|
||||
configCompile.setService(serviceType);
|
||||
// configCompile.setService(serviceType);
|
||||
configCompile.setAction(action);
|
||||
configCompile.setContType(0);
|
||||
configCompile.setAttrType(0);
|
||||
// configCompile.setContType(0);
|
||||
// configCompile.setAttrType(0);
|
||||
configCompile.setContLabel("0");
|
||||
configCompile.setTaskId(0);
|
||||
configCompile.setGuaranteeId(0);
|
||||
// configCompile.setGuaranteeId(0);
|
||||
configCompile.setAffairId(0);
|
||||
configCompile.setTopicId(0);
|
||||
configCompile.setDoBlacklist(0l);
|
||||
// configCompile.setTopicId(0);
|
||||
// configCompile.setDoBlacklist(0l);
|
||||
configCompile.setDoLog(0);
|
||||
configCompile.setEffectiveRange("0");
|
||||
configCompile.setConfigPercent(100l);
|
||||
configCompile.setConfigOption(1);
|
||||
// configCompile.setConfigPercent(100l);
|
||||
// configCompile.setConfigOption(1);
|
||||
configCompile.setStartTime(sdf.parse(startTime));
|
||||
configCompile.setEndTime(sdf.parse(endTime));
|
||||
// configCompile.setStartTime(startTime);
|
||||
// configCompile.setEndTime(endTime);
|
||||
|
||||
configCompile.setActiveSys(0);
|
||||
configCompile.setLastUpdate(date);
|
||||
configCompile.setProcSeq(compileId);
|
||||
// configCompile.setActiveSys(0);
|
||||
// configCompile.setLastUpdate(date);
|
||||
// configCompile.setProcSeq(compileId);
|
||||
configCompile.setUserRegion("0");
|
||||
configCompile.setIsValid(1);
|
||||
configCompile.setGroupNum(1);
|
||||
@@ -634,7 +634,7 @@ public class ConfigTestController extends BaseRestController {
|
||||
List<ConfigGroupRelation> groupRelationList = new ArrayList<ConfigGroupRelation>();
|
||||
ConfigGroupRelation configGroupRelation = new ConfigGroupRelation();
|
||||
configGroupRelation.setGroupId(groupId);
|
||||
configGroupRelation.setId(groupId);
|
||||
// configGroupRelation.setId(groupId);
|
||||
configGroupRelation.setCompileId(compileId);
|
||||
configGroupRelation.setIsValid(1);
|
||||
configGroupRelation.setOpTime(date);
|
||||
|
||||
@@ -1,721 +0,0 @@
|
||||
package com.nis.web.controller.restful;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.restful.ConfigCompile;
|
||||
import com.nis.domain.restful.ConfigCompileTest;
|
||||
import com.nis.domain.restful.ConfigGroupRelation;
|
||||
import com.nis.domain.restful.ConfigSourceTest;
|
||||
import com.nis.domain.restful.IpRegion;
|
||||
import com.nis.domain.restful.IpRegionTest;
|
||||
import com.nis.domain.restful.NumRegion;
|
||||
import com.nis.domain.restful.NumRegionTest;
|
||||
import com.nis.domain.restful.StrRegion;
|
||||
import com.nis.domain.restful.StrRegionTest;
|
||||
import com.nis.restful.RestBusinessCode;
|
||||
import com.nis.restful.RestServiceException;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.JsonDateValueProcessor;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.web.controller.BaseRestController;
|
||||
import com.nis.web.service.SaveRequestLogThread;
|
||||
import com.nis.web.service.ServicesRequestLogService;
|
||||
import com.nis.web.service.restful.ConfigSourcesService;
|
||||
import com.wordnik.swagger.annotations.Api;
|
||||
import com.wordnik.swagger.annotations.ApiOperation;
|
||||
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JsonConfig;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("${servicePath}/cfg/v1/test")
|
||||
@Api(value = "SaveConfigTestController", description = "配置存储服务,包括管控、监测、白名单的控制类")
|
||||
public class SaveConfigTestController extends BaseRestController {
|
||||
private long allCount = 0l;
|
||||
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Logger logger = Logger.getLogger(ConfigTestController.class);
|
||||
@Autowired
|
||||
protected ConfigSourcesService configSourcesService;
|
||||
|
||||
@Autowired
|
||||
protected ServicesRequestLogService servicesRequestLogService;
|
||||
|
||||
@RequestMapping(value = "/testSaveByJDBCThread", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "测试批量业务配置存储", httpMethod = "GET", response = Map.class, notes = "对有效的配置(封堵|监测|白名单)存储")
|
||||
public Map testSaveByJDBCThread(@RequestParam(value = "configCount", required = false) Long configCount,
|
||||
@RequestParam(value = "startNum", required = false) Long startNum,
|
||||
@RequestParam(value = "startTime", required = false) String startTime,
|
||||
@RequestParam(value = "endTime", required = false) String endTime, HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
try {
|
||||
|
||||
startTime = "2016-11-01 08:20:20";
|
||||
endTime = "2016-11-8 15:55:33";
|
||||
|
||||
if (configCount == null) {
|
||||
configCount = 0l;
|
||||
}
|
||||
allCount = 0l;
|
||||
long dataCount = 0l;
|
||||
|
||||
if (startTime == null || startTime.equals("")) {
|
||||
startTime = sdf.format(new Date());
|
||||
}
|
||||
|
||||
if (endTime == null || endTime.equals("")) {
|
||||
endTime = sdf.format(new Date());
|
||||
}
|
||||
Date date = new Date();
|
||||
ConfigSourceTest configSource = new ConfigSourceTest();
|
||||
configSource.setOpTime(date);
|
||||
configSource.setOpAction(1);
|
||||
configSource.setOperator("rkg");
|
||||
configSource.setVersion("0.1");
|
||||
List<ConfigCompile> configCompileList = new ArrayList<ConfigCompile>();
|
||||
if (startNum == null || startNum == 0) {
|
||||
startNum = 1l;
|
||||
}
|
||||
long count = System.currentTimeMillis() + startNum;
|
||||
Integer[] zeroArr = { 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
|
||||
Integer[] oneArr = { 15, 16, 17, 18, 32, 33, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62 };
|
||||
Integer[] twoArr = { 2 };
|
||||
for (Integer x = 0; x < zeroArr.length; x++) {
|
||||
for (Long i = 1l; i <= configCount; i++) {
|
||||
count++;
|
||||
dataCount++;
|
||||
allCount++;
|
||||
ConfigCompile configCompile = setCompileTest(zeroArr[x].longValue(), 0, date, startTime, endTime,
|
||||
count);
|
||||
configCompileList.add(configCompile);
|
||||
}
|
||||
}
|
||||
for (Integer x = 15; x < oneArr.length + 15; x++) {
|
||||
for (Long i = 1l; i <= configCount; i++) {
|
||||
count++;
|
||||
dataCount++;
|
||||
allCount++;
|
||||
ConfigCompile configCompile = setCompileTest(oneArr[x - 15].longValue(), 1, date, startTime,
|
||||
endTime, count);
|
||||
configCompileList.add(configCompile);
|
||||
}
|
||||
}
|
||||
for (Integer x = 50; x < twoArr.length + 50; x++) {
|
||||
for (Long i = 1l; i <= configCount; i++) {
|
||||
count++;
|
||||
dataCount++;
|
||||
allCount++;
|
||||
ConfigCompile configCompile = setCompileTest(twoArr[x - 50].longValue(), 2, date, startTime,
|
||||
endTime, count);
|
||||
configCompileList.add(configCompile);
|
||||
}
|
||||
}
|
||||
configSource.setConfigCompileList(configCompileList);
|
||||
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST,
|
||||
request, configSource);
|
||||
|
||||
// JsonConfig jsonConfig = new JsonConfig();
|
||||
// jsonConfig.registerJsonValueProcessor(Date.class, new
|
||||
// JsonDateValueProcessor());
|
||||
// JSONArray jsonArray = JSONArray.fromObject(configSource,
|
||||
// jsonConfig);
|
||||
// String jsonStr = jsonArray.getString(0);
|
||||
// String distisct = "\"district\":\"\",";
|
||||
// if (jsonStr.contains(distisct)) {
|
||||
// jsonStr = jsonStr.replaceAll(distisct, "");
|
||||
// }
|
||||
// System.out.println(jsonStr);
|
||||
System.out.println("开始执行插入操作" + dataCount + "条配置总计" + allCount + "条数据");
|
||||
long start = System.currentTimeMillis();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
configSourcesService.saveByJDBCThread(thread, start, configCompileList, sb);
|
||||
Long end = System.currentTimeMillis();
|
||||
Long time = (end - start) / 1000;
|
||||
System.out.println("插入了" + dataCount + "条配置总计" + allCount + "条数据总共需要" + time + "秒");
|
||||
validateConfigSourceTest(thread, start, configSource);
|
||||
return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "编译配置数据插入成功",
|
||||
configSource);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/testSaveByMybatis", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "测试批量业务配置存储", httpMethod = "GET", response = Map.class, notes = "对有效的配置(封堵|监测|白名单)存储")
|
||||
public Map testSaveByMybatis(@RequestParam(value = "configCount", required = false) Long configCount,
|
||||
@RequestParam(value = "batchSize", required = false) Integer batchSize,
|
||||
@RequestParam(value = "startNum", required = false) Long startNum, HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
try {
|
||||
if (startNum == null || startNum == 0) {
|
||||
startNum = 1l;
|
||||
}
|
||||
allCount = 0l;
|
||||
long dataCount = 0l;
|
||||
String startTime = "2016-11-01 08:20:20";
|
||||
String endTime = "2016-11-8 15:55:33";
|
||||
Date date = new Date();
|
||||
ConfigSourceTest configSource = new ConfigSourceTest();
|
||||
configSource.setOpTime(date);
|
||||
configSource.setOpAction(1);
|
||||
configSource.setOperator("rkg");
|
||||
configSource.setVersion("0.1");
|
||||
List<ConfigCompile> configCompileList = new ArrayList<ConfigCompile>();
|
||||
long count = System.currentTimeMillis() + startNum;
|
||||
Integer[] zeroArr = { 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
|
||||
Integer[] oneArr = { 15, 16, 17, 18, 32, 33, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62 };
|
||||
Integer[] twoArr = { 2 };
|
||||
for (Integer x = 0; x < zeroArr.length; x++) {
|
||||
for (Long i = 1l; i <= configCount; i++) {
|
||||
count++;
|
||||
dataCount++;
|
||||
allCount++;
|
||||
ConfigCompile configCompile = setCompileTest(zeroArr[x].longValue(), 0, date, startTime, endTime,
|
||||
count);
|
||||
configCompileList.add(configCompile);
|
||||
}
|
||||
}
|
||||
for (Integer x = 15; x < oneArr.length + 15; x++) {
|
||||
for (Long i = 1l; i <= configCount; i++) {
|
||||
count++;
|
||||
dataCount++;
|
||||
allCount++;
|
||||
ConfigCompile configCompile = setCompileTest(oneArr[x - 15].longValue(), 1, date, startTime,
|
||||
endTime, count);
|
||||
configCompileList.add(configCompile);
|
||||
}
|
||||
}
|
||||
for (Integer x = 50; x < twoArr.length + 50; x++) {
|
||||
for (Long i = 1l; i <= configCount; i++) {
|
||||
count++;
|
||||
dataCount++;
|
||||
allCount++;
|
||||
ConfigCompile configCompile = setCompileTest(twoArr[x - 50].longValue(), 2, date, startTime,
|
||||
endTime, count);
|
||||
configCompileList.add(configCompile);
|
||||
}
|
||||
}
|
||||
configSource.setConfigCompileList(configCompileList);
|
||||
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_POST,
|
||||
request, configSource);
|
||||
|
||||
System.out.println("开始执行插入操作" + dataCount + "条配置总计" + allCount + "条数据");
|
||||
long start = System.currentTimeMillis();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
configSourcesService.insertConfigSourceData(thread, start, configCompileList, sb);
|
||||
Long end = System.currentTimeMillis();
|
||||
Long time = (end - start) / 1000;
|
||||
System.out.println("插入了" + dataCount + "条配置总计" + allCount + "条数据总共需要" + time + "秒");
|
||||
validateConfigSourceTest(thread, start, configSource);
|
||||
return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "编译配置数据插入成功",
|
||||
configSource);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ConfigCompileTest setCompileTest(Long serviceType, Integer action, Date date, String startTime,
|
||||
String endTime, Long index) throws Exception {
|
||||
|
||||
Long compileId = System.currentTimeMillis() + index;
|
||||
//System.out.println("compileId--------------------------" + compileId);
|
||||
ConfigCompileTest configCompile = new ConfigCompileTest();
|
||||
configCompile.setCompileId(compileId);
|
||||
configCompile.setService(serviceType);
|
||||
configCompile.setAction(1);
|
||||
configCompile.setContType(0);
|
||||
configCompile.setAttrType(0);
|
||||
configCompile.setContLabel("0");
|
||||
configCompile.setTaskId(0);
|
||||
configCompile.setGuaranteeId(0);
|
||||
configCompile.setAffairId(0);
|
||||
configCompile.setTopicId(0);
|
||||
configCompile.setDoBlacklist(1l);
|
||||
configCompile.setDoLog(0);
|
||||
configCompile.setEffectiveRange("0");
|
||||
configCompile.setConfigPercent(100l);
|
||||
configCompile.setConfigOption(1);
|
||||
configCompile.setStartTime(new Date(1482472334731l));
|
||||
configCompile.setEndTime(new Date(1482472734731l));
|
||||
//configCompile.setStartTime(sdf.parse("2016-12-22 08:20:20"));
|
||||
//configCompile.setEndTime(sdf.parse("2016-12-23 08:20:20"));
|
||||
// configCompile.setStartTime(startTime);
|
||||
// configCompile.setEndTime(endTime);
|
||||
|
||||
configCompile.setActiveSys(2);
|
||||
configCompile.setLastUpdate(date);
|
||||
configCompile.setProcSeq(compileId);
|
||||
configCompile.setUserRegion("0");
|
||||
configCompile.setIsValid(1);
|
||||
configCompile.setGroupNum(1);
|
||||
configCompile.setFatherCfgId(0l);
|
||||
configCompile.setOpTime(date);
|
||||
Long groupId = System.currentTimeMillis() + (long) ((Math.random()) * 100000);
|
||||
configCompile.setGroupRelationList(setGroupList(compileId, date, groupId));
|
||||
Map<String, String> tableMap = configSourcesService.getTableMap(serviceType.intValue());
|
||||
List<String> strTable = new ArrayList<String>();
|
||||
String ipTable = null;
|
||||
String numTable = null;
|
||||
|
||||
if (null != tableMap && tableMap.size() > 0) {
|
||||
for (String str : tableMap.keySet()) {
|
||||
if (tableMap.get(str).equals("ip")) {
|
||||
ipTable = str;
|
||||
} else if (tableMap.get(str).equals("num")) {
|
||||
numTable = str;
|
||||
} else if (tableMap.get(str).equals("str")) {
|
||||
strTable.add(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configCompile.setStrRegionList(setAllStrRegionList(serviceType, groupId, date, strTable, index));
|
||||
configCompile.setIpRegionList(setIpRegionList(serviceType, groupId, date, ipTable, index));
|
||||
configCompile.setNumRegionList(setNumRegionList(serviceType, groupId, date, numTable, index));
|
||||
return configCompile;
|
||||
|
||||
}
|
||||
|
||||
public List<ConfigGroupRelation> setGroupList(Long compileId, Date date, Long groupId) {
|
||||
List<ConfigGroupRelation> groupRelationList = new ArrayList<ConfigGroupRelation>();
|
||||
ConfigGroupRelation configGroupRelation = new ConfigGroupRelation();
|
||||
configGroupRelation.setGroupId(groupId);
|
||||
configGroupRelation.setId(groupId);
|
||||
configGroupRelation.setCompileId(compileId);
|
||||
configGroupRelation.setIsValid(1);
|
||||
configGroupRelation.setOpTime(date);
|
||||
groupRelationList.add(configGroupRelation);
|
||||
allCount++;
|
||||
return groupRelationList;
|
||||
}
|
||||
|
||||
public List<StrRegion> setStrRegionList(Long service, Long groupId, Date date, List<String> tableName, Long index) {
|
||||
List<StrRegion> strRegionList = new ArrayList<StrRegion>();
|
||||
if (tableName != null & tableName.size() > 0) {
|
||||
Long regionId = System.currentTimeMillis() + index + 10000000000000l;
|
||||
//System.out.println("Strid--------------------------" + regionId);
|
||||
StrRegionTest strRegion = new StrRegionTest();
|
||||
strRegion.setRegionId(regionId);
|
||||
strRegion.setGroupId(groupId);
|
||||
strRegion.setKeywords("百度");
|
||||
strRegion.setExprType(0);
|
||||
strRegion.setMatchMethod(0);
|
||||
strRegion.setIsHexbin(0);
|
||||
strRegion.setIsValid(1);
|
||||
strRegion.setOpTime(date);
|
||||
if (configSourcesService.isStrStrongRegion(tableName.get(0))) {
|
||||
strRegion.setDistrict("南京");
|
||||
}
|
||||
strRegion.setTableName(tableName.get(0));
|
||||
strRegion.setProcSeq(regionId);
|
||||
strRegionList.add(strRegion);
|
||||
|
||||
StrRegionTest strRegion1 = new StrRegionTest();
|
||||
Long regionId1 = System.currentTimeMillis() + index + 100000;
|
||||
//System.out.println("Strid===================================" + regionId);
|
||||
strRegion1.setRegionId(regionId1);
|
||||
strRegion1.setGroupId(groupId);
|
||||
strRegion1.setKeywords("新浪");
|
||||
strRegion1.setExprType(0);
|
||||
strRegion1.setMatchMethod(0);
|
||||
strRegion1.setIsHexbin(0);
|
||||
strRegion1.setIsValid(1);
|
||||
strRegion1.setOpTime(date);
|
||||
strRegion1.setProcSeq(regionId1);
|
||||
if (tableName.size() > 1) {
|
||||
strRegion1.setTableName(tableName.get(1));
|
||||
if (configSourcesService.isStrStrongRegion(tableName.get(1))) {
|
||||
strRegion1.setDistrict("北京");
|
||||
}
|
||||
} else {
|
||||
strRegion1.setTableName(tableName.get(0));
|
||||
if (configSourcesService.isStrStrongRegion(tableName.get(0))) {
|
||||
strRegion1.setDistrict("上海");
|
||||
}
|
||||
}
|
||||
strRegionList.add(strRegion1);
|
||||
allCount++;
|
||||
return strRegionList;
|
||||
} else {
|
||||
return strRegionList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<StrRegion> setAllStrRegionList(Long service, Long groupId, Date date, List<String> tableName,
|
||||
Long index) {
|
||||
List<StrRegion> strRegionList = new ArrayList<StrRegion>();
|
||||
int num = 0;
|
||||
if (tableName != null & tableName.size() > 0) {
|
||||
for (String tbName : tableName) {
|
||||
num++;
|
||||
Long regionId = System.currentTimeMillis() + index + 999999999999999l * num;
|
||||
//System.out.println("Strid--------------------------" + regionId);
|
||||
StrRegionTest strRegion = new StrRegionTest();
|
||||
strRegion.setRegionId(regionId);
|
||||
strRegion.setGroupId(groupId);
|
||||
strRegion.setKeywords("百度");
|
||||
strRegion.setExprType(0);
|
||||
strRegion.setMatchMethod(0);
|
||||
strRegion.setIsHexbin(2);
|
||||
strRegion.setIsValid(1);
|
||||
strRegion.setOpTime(date);
|
||||
if (configSourcesService.isStrStrongRegion(tbName)) {
|
||||
strRegion.setDistrict("南京");
|
||||
}
|
||||
strRegion.setTableName(tbName);
|
||||
strRegion.setProcSeq(regionId);
|
||||
strRegionList.add(strRegion);
|
||||
allCount++;
|
||||
}
|
||||
return strRegionList;
|
||||
} else {
|
||||
return strRegionList;
|
||||
}
|
||||
}
|
||||
|
||||
public List<IpRegion> setIpRegionList(Long service, Long groupId, Date date, String tableName, Long index) {
|
||||
List<IpRegion> ipRegionList = new ArrayList<IpRegion>();
|
||||
if (tableName != null) {
|
||||
|
||||
IpRegionTest ipRegion = new IpRegionTest();
|
||||
Long regionId = System.currentTimeMillis() + index + 20000000000000l;
|
||||
//System.out.println("Ipid--------------------------" + regionId);
|
||||
ipRegion.setRegionId(regionId);
|
||||
ipRegion.setGroupId(groupId);
|
||||
ipRegion.setAddrType(4);
|
||||
ipRegion.setSrcIp("0.0.0.0");
|
||||
ipRegion.setMaskSrcIp("0.0.0.0");
|
||||
ipRegion.setSrcPort("0");
|
||||
ipRegion.setMaskSrcPort("0");
|
||||
ipRegion.setDstIp("0.0.0.2");
|
||||
ipRegion.setMaskDstIp("0.0.0.0");
|
||||
ipRegion.setDstPort("0");
|
||||
ipRegion.setMaskDstPort("0");
|
||||
ipRegion.setProtocol(0);
|
||||
ipRegion.setDirection(0);
|
||||
ipRegion.setIsValid(1);
|
||||
ipRegion.setOpTime(date);
|
||||
ipRegion.setTableName(tableName);
|
||||
ipRegion.setProcSeq(regionId);
|
||||
ipRegionList.add(ipRegion);
|
||||
allCount++;
|
||||
return ipRegionList;
|
||||
} else {
|
||||
return ipRegionList;
|
||||
}
|
||||
}
|
||||
|
||||
public List<NumRegion> setNumRegionList(Long service, Long groupId, Date date, String tableName, Long index) {
|
||||
List<NumRegion> numRegionList = new ArrayList<NumRegion>();
|
||||
if (tableName != null) {
|
||||
NumRegionTest numRegion = new NumRegionTest();
|
||||
Long regionId = System.currentTimeMillis() + index + 30000000000000l;
|
||||
//System.out.println("numid--------------------------" + regionId);
|
||||
numRegion.setRegionId(regionId);
|
||||
numRegion.setGroupId(groupId);
|
||||
numRegion.setLowBoundary(4294967294l);
|
||||
numRegion.setUpBoundary(4294967295l);
|
||||
numRegion.setIsValid(1);
|
||||
numRegion.setOpTime(date);
|
||||
numRegion.setTableName(tableName);
|
||||
numRegion.setProcSeq(regionId);
|
||||
numRegionList.add(numRegion);
|
||||
allCount++;
|
||||
return numRegionList;
|
||||
} else {
|
||||
return numRegionList;
|
||||
}
|
||||
}
|
||||
|
||||
private void validateConfigSourceTest(SaveRequestLogThread thread, long start, ConfigSourceTest configSource) {
|
||||
String errorInfo = "";
|
||||
List<ConfigCompile> configCompileList = configSource.getConfigCompileList();
|
||||
if (StringUtils.isEmpty(configSource.getOperator())) {
|
||||
errorInfo = "get operator is Empty";
|
||||
}
|
||||
if (StringUtils.isEmpty(configSource.getVersion())) {
|
||||
errorInfo = "get version is Empty";
|
||||
}
|
||||
|
||||
if (!isBlank(configSource.getOpTime())) {
|
||||
errorInfo = "get OpTime is Empty";
|
||||
}
|
||||
|
||||
if (configCompileList.size() <= 0) {
|
||||
errorInfo = "编译配置不能为空";
|
||||
}
|
||||
if (!errorInfo.equals("")) {
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, errorInfo,
|
||||
RestBusinessCode.missing_args.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isBlank(Date datetime) {
|
||||
if (null != datetime) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@RequestMapping(value = "/testUpdateByJDBCThread", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "测试批量业务配置修改", httpMethod = "GET", response = Map.class, notes = "对有效的配置(封堵|监测|白名单)存储")
|
||||
public Map testUpdateByJDBCThread(@RequestParam(value = "compileId", required = false) Long compileId,
|
||||
HttpServletRequest request, HttpServletResponse response) {
|
||||
allCount = 0l;
|
||||
long dataCount = 0l;
|
||||
List<ConfigCompile> compileList = new ArrayList<ConfigCompile>();
|
||||
ConfigCompileTest configCompileTest = new ConfigCompileTest();
|
||||
configCompileTest.setIsValid(1);
|
||||
if (null != compileId) {
|
||||
configCompileTest.setCompileId(compileId);
|
||||
}
|
||||
List<ConfigCompileTest> queryAllCompile = configSourcesService.queryAllCompile(configCompileTest);
|
||||
for (int i = 0; i < queryAllCompile.size(); i++) {
|
||||
ConfigCompile compileInfo = getCompileInfo(queryAllCompile.get(i));
|
||||
compileInfo.setOpTime(new Date());
|
||||
dataCount++;
|
||||
allCount++;
|
||||
// compileInfo.setIsValid(0);
|
||||
compileList.add(compileInfo);
|
||||
}
|
||||
ConfigSourceTest configSource = new ConfigSourceTest();
|
||||
configSource.setOpTime(new Date());
|
||||
configSource.setOpAction(1);
|
||||
configSource.setOperator("rkg");
|
||||
configSource.setVersion("0.1");
|
||||
configSource.setConfigCompileList(compileList);
|
||||
|
||||
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
|
||||
configSource);
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
System.out.println("开始执行修改操作" + dataCount + "条配置总计" + allCount + "条数据");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
configSourcesService.updateByJDBCThread(thread, start, configSource.getConfigCompileList(),
|
||||
configSource.getOpTime(), sb);
|
||||
|
||||
Long end = System.currentTimeMillis();
|
||||
Long time = (end - start) / 1000;
|
||||
System.out.println("修改了" + dataCount + "条配置总计" + allCount + "条数据总共需要" + time + "秒");
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
if (!e.getMessage().contains("Connection is closed!")) {
|
||||
RestServiceException rse = (RestServiceException) e;
|
||||
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, rse.getMessage(),
|
||||
rse.getErrorCode());
|
||||
} else {
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, "数据保存发生异常!",
|
||||
RestBusinessCode.unknow_error.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "编译配置数据修改成功",
|
||||
configSource);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@RequestMapping(value = "/updateConfigSource", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "测试批量业务配置修改", httpMethod = "GET", response = Map.class, notes = "对有效的配置(封堵|监测|白名单)存储")
|
||||
public Map updateConfigSource(@RequestParam(value = "compileId", required = false) Long compileId,
|
||||
HttpServletRequest request, HttpServletResponse response) {
|
||||
allCount = 0l;
|
||||
long dataCount = 0l;
|
||||
List<ConfigCompile> compileList = new ArrayList<ConfigCompile>();
|
||||
ConfigCompileTest configCompileTest = new ConfigCompileTest();
|
||||
configCompileTest.setIsValid(1);
|
||||
if (null != compileId) {
|
||||
configCompileTest.setCompileId(compileId);
|
||||
}
|
||||
|
||||
List<ConfigCompileTest> queryAllCompile = configSourcesService.queryAllCompile(configCompileTest);
|
||||
for (int i = 0; i < queryAllCompile.size(); i++) {
|
||||
ConfigCompile compileInfo = getCompileInfo(queryAllCompile.get(i));
|
||||
// compileInfo.setIsValid(0);
|
||||
compileInfo.setOpTime(new Date());
|
||||
compileList.add(compileInfo);
|
||||
dataCount++;
|
||||
allCount++;
|
||||
}
|
||||
ConfigSourceTest configSource = new ConfigSourceTest();
|
||||
configSource.setOpTime(new Date());
|
||||
configSource.setOpAction(1);
|
||||
configSource.setOperator("rkg");
|
||||
configSource.setVersion("0.1");
|
||||
configSource.setConfigCompileList(compileList);
|
||||
|
||||
JsonConfig jsonConfig = new JsonConfig();
|
||||
jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
|
||||
JSONArray jsonArray = JSONArray.fromObject(configSource, jsonConfig);
|
||||
String jsonStr = jsonArray.getString(0);
|
||||
String distisct = "\"district\":\"\",";
|
||||
if (jsonStr.contains(distisct)) {
|
||||
jsonStr = jsonStr.replaceAll(distisct, "");
|
||||
}
|
||||
|
||||
// System.out.println(jsonStr);
|
||||
|
||||
SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
|
||||
configSource);
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
System.out.println("开始执行修改操作" + dataCount + "条配置总计" + allCount + "条数据");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
configSourcesService.updateConfigSource(thread, start, configSource.getConfigCompileList(),
|
||||
configSource.getOpTime(), sb);
|
||||
Long end = System.currentTimeMillis();
|
||||
Long time = (end - start) / 1000;
|
||||
System.out.println("修改了" + dataCount + "条配置总计" + allCount + "条数据总共需要" + time + "秒");
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
if (!e.getMessage().contains("Connection is closed!")) {
|
||||
RestServiceException rse = (RestServiceException) e;
|
||||
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, rse.getMessage(),
|
||||
rse.getErrorCode());
|
||||
} else {
|
||||
throw new RestServiceException(thread, System.currentTimeMillis() - start, "数据保存发生异常!",
|
||||
RestBusinessCode.unknow_error.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "编译配置数据修改成功",
|
||||
configSource);
|
||||
}
|
||||
|
||||
public ConfigCompile getCompileInfo(ConfigCompile configCompileTest) {
|
||||
List<ConfigGroupRelation> groupByCompileList = configSourcesService
|
||||
.getGroupByCompile(configCompileTest.getCompileId());
|
||||
configCompileTest.setGroupRelationList(groupByCompileList);
|
||||
Long[] groupIdArr = new Long[groupByCompileList.size()];
|
||||
for (int i = 0; i < groupByCompileList.size(); i++) {
|
||||
groupIdArr[i] = groupByCompileList.get(i).getGroupId();
|
||||
allCount++;
|
||||
}
|
||||
|
||||
Map<String, String> tableMap = configSourcesService.getTableMap(configCompileTest.getService().intValue());
|
||||
List<String> strTable = new ArrayList<String>();
|
||||
String ipTable = null;
|
||||
String numTable = null;
|
||||
|
||||
if (null != tableMap && tableMap.size() > 0) {
|
||||
for (String str : tableMap.keySet()) {
|
||||
if (tableMap.get(str).equals("ip")) {
|
||||
ipTable = str;
|
||||
} else if (tableMap.get(str).equals("num")) {
|
||||
numTable = str;
|
||||
} else if (tableMap.get(str).equals("str")) {
|
||||
strTable.add(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strTable.size() > 0) {
|
||||
// List<StrRegion> strList =new ArrayList<StrRegion>();
|
||||
List<StrRegion> strRegionList = configSourcesService.getStrRegionByGId(strTable, groupIdArr);
|
||||
if (null != strRegionList && strRegionList.size() > 0) {
|
||||
for (StrRegion strRegion : strRegionList) {
|
||||
// strList.add(strRegion)
|
||||
strRegion.setIsValid(0);
|
||||
allCount++;
|
||||
}
|
||||
configCompileTest.setStrRegionList(strRegionList);
|
||||
} else {
|
||||
List<StrRegion> strList = new ArrayList<StrRegion>();
|
||||
configCompileTest.setStrRegionList(strList);
|
||||
}
|
||||
} else {
|
||||
List<StrRegion> strList = new ArrayList<StrRegion>();
|
||||
configCompileTest.setStrRegionList(strList);
|
||||
}
|
||||
|
||||
if (ipTable != null) {
|
||||
|
||||
List<IpRegion> ipRegionByGId = configSourcesService.getIpRegionByGId(ipTable, groupIdArr);
|
||||
if (null != ipRegionByGId && ipRegionByGId.size() > 0) {
|
||||
for (IpRegion ipRegion : ipRegionByGId) {
|
||||
ipRegion.setIsValid(0);
|
||||
allCount++;
|
||||
}
|
||||
configCompileTest.setIpRegionList(ipRegionByGId);
|
||||
} else {
|
||||
List<IpRegion> ipList = new ArrayList<IpRegion>();
|
||||
configCompileTest.setIpRegionList(ipList);
|
||||
}
|
||||
} else {
|
||||
List<IpRegion> ipList = new ArrayList<IpRegion>();
|
||||
configCompileTest.setIpRegionList(ipList);
|
||||
}
|
||||
|
||||
if (numTable != null) {
|
||||
List<NumRegion> numRegionList = configSourcesService.getNumRegionByGId(numTable, groupIdArr);
|
||||
if (null != numRegionList && numRegionList.size() > 0) {
|
||||
for (NumRegion numRegion : numRegionList) {
|
||||
numRegion.setIsValid(0);
|
||||
allCount++;
|
||||
}
|
||||
configCompileTest.setNumRegionList(numRegionList);
|
||||
} else {
|
||||
List<NumRegion> numList = new ArrayList<NumRegion>();
|
||||
configCompileTest.setNumRegionList(numList);
|
||||
}
|
||||
} else {
|
||||
List<NumRegion> numList = new ArrayList<NumRegion>();
|
||||
configCompileTest.setNumRegionList(numList);
|
||||
}
|
||||
return configCompileTest;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/findCompile", method = RequestMethod.POST)
|
||||
public Map findCompile(ConfigCompileTest configCompileTest, HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
long start = System.currentTimeMillis();
|
||||
SaveRequestLogThread thread1 = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
|
||||
configCompileTest);
|
||||
Page page = new Page();
|
||||
int no = configCompileTest.getPagesNo() == null ? 1 : configCompileTest.getPagesNo();
|
||||
int size = configCompileTest.getPagesSize() == null ? 10 : configCompileTest.getPagesSize();
|
||||
page.setPageNo(no);
|
||||
page.setPageSize(size);
|
||||
Page<ConfigCompileTest> queryAllCompile = null;
|
||||
try {
|
||||
if (configCompileTest.getSearchStartTime() != null && !configCompileTest.getSearchStartTime().equals("")) {
|
||||
configCompileTest.setStartTime(sdf.parse(configCompileTest.getSearchStartTime()));
|
||||
// configCompile.setStartTime(configCompile.getSearchStartTime());
|
||||
}
|
||||
if (configCompileTest.getSearchEndTime() != null && !configCompileTest.getSearchEndTime().equals("")) {
|
||||
configCompileTest.setEndTime(sdf.parse(configCompileTest.getSearchEndTime()));
|
||||
|
||||
// configCompile.setEndTime(configCompile.getSearchEndTime());
|
||||
}
|
||||
queryAllCompile = configSourcesService.queryAllCompile(page, configCompileTest);
|
||||
} catch (SQLException e) {
|
||||
thread1.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
e.printStackTrace();
|
||||
throw new RestServiceException(thread1, System.currentTimeMillis() - start, "编译配置获取失败");
|
||||
} catch (Exception e) {
|
||||
thread1.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
||||
e.printStackTrace();
|
||||
throw new RestServiceException(thread1, System.currentTimeMillis() - start, "编译配置获取失败");
|
||||
}
|
||||
return serviceResponse(thread1, System.currentTimeMillis() - start, request, response, "编译配置获取成功",
|
||||
queryAllCompile);
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ public interface ConfigCompileDao {
|
||||
* @return
|
||||
*/
|
||||
public List<ConfigCompileTest> queryAllCompile(@Param("searchEndTime") String searchEndTime,
|
||||
@Param("searchStartTime") String searchStartTime, @Param("service") Long service,
|
||||
@Param("searchStartTime") String searchStartTime, @Param("service") Integer service,
|
||||
@Param("compileId") Long compileId);
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ConfigPzIdService extends BaseLogService {
|
||||
entity.setSourceName(entity.getSourceName().toUpperCase());
|
||||
String seqName= StringUtil.isEmpty(sourceNameMap.get(entity.getSourceName()))?"SEQ_COMPILEID":sourceNameMap.get(entity.getSourceName());
|
||||
for (int i = 0; i < entity.getNum(); i++) {
|
||||
//pzIdList.add(dao.getConfigPzIdList(entity)); //直接从数据库序列号获取
|
||||
// pzIdList.add(dao.getConfigPzIdList(entity)); //直接从数据库序列号获取
|
||||
pzIdList.add(configRedisService.getIncrId(seqName));
|
||||
}
|
||||
entity.setPzIdList(pzIdList);
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
package com.nis.web.service.restful;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.List;
|
||||
import com.nis.domain.restful.ConfigCompile;
|
||||
import com.nis.domain.restful.ConfigGroupRelation;
|
||||
import com.nis.domain.restful.IpRegion;
|
||||
import com.nis.domain.restful.NumRegion;
|
||||
import com.nis.domain.restful.StrRegion;
|
||||
|
||||
/**
|
||||
* jdbc测试批量插入
|
||||
*
|
||||
* @author RenKaiGe-Office
|
||||
*
|
||||
*/
|
||||
public class JDBCTest {
|
||||
public static java.sql.Timestamp utileDate2TimeStamp(java.util.Date udate) {
|
||||
java.sql.Timestamp sqlDate = null;
|
||||
long t = udate.getTime();
|
||||
sqlDate = new java.sql.Timestamp(t);
|
||||
return sqlDate;
|
||||
|
||||
}
|
||||
|
||||
public static void saveCompile(List<ConfigCompile> compileList, Connection conn, int batchSize) throws Exception {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(
|
||||
"insert into CONFIG_COMPILE (COMPILE_ID ,SERVICE ,ACTION , CONT_TYPE, ATTR_TYPE, CONT_LABEL, Task_id, Guarantee_ID, AFFAIR_ID, TOPIC_ID, DO_BLACKLIST ,DO_LOG ,EFFECTIVE_RANGE , ACTIVE_SYS, CONFIG_PERCENT ,CONFIG_OPTION ,START_TIME ,END_TIME , USER_REGION, IS_VALID,GROUP_NUM,FATHER_CFG_ID ,OP_TIME,LAST_UPDATE ) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate)");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
int count = 0;
|
||||
for (ConfigCompile compile : compileList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { compile.getCompileId(), compile.getService(), compile.getAction(),
|
||||
compile.getContType(), compile.getAttrType(), compile.getContLabel(), compile.getTaskId(),
|
||||
compile.getGuaranteeId(), compile.getAffairId(), compile.getTopicId(), compile.getDoBlacklist(),
|
||||
compile.getDoLog(), compile.getEffectiveRange(), compile.getActiveSys(), compile.getConfigPercent(),
|
||||
compile.getConfigOption(), compile.getStartTime(), compile.getEndTime(), compile.getUserRegion(),
|
||||
compile.getIsValid(), compile.getGroupNum(), compile.getFatherCfgId(), compile.getOpTime() };
|
||||
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 16) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(compile.getStartTime()));
|
||||
} else if (x == 17) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(compile.getEndTime()));
|
||||
} else if (x == 22) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(compile.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
if (count % batchSize == 0) {
|
||||
ps.executeBatch();
|
||||
////conn.commit();
|
||||
}
|
||||
}
|
||||
ps.executeBatch();
|
||||
//conn.commit();
|
||||
}
|
||||
|
||||
public static void saveGroup(List<ConfigGroupRelation> groupList, Connection conn, int batchSize) throws Exception {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(
|
||||
"insert into CONFIG_GROUP (ID,GROUP_ID, COMPILE_ID, IS_VALID, LAST_UPDATE, OP_TIME ) values ( seq_config_group.nextval, ?, ?, ?, sysdate, ?) ");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
int count = 0;
|
||||
for (ConfigGroupRelation group : groupList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { group.getGroupId(), group.getCompileId(), group.getIsValid(),
|
||||
group.getOpTime() };
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 3) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(group.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
if (count % batchSize == 0) {
|
||||
ps.executeBatch();
|
||||
//conn.commit();
|
||||
}
|
||||
}
|
||||
ps.executeBatch();
|
||||
//conn.commit();
|
||||
}
|
||||
|
||||
public static void saveIPRegion(String name, List<IpRegion> ipRegionList, Connection conn, int batchSize)
|
||||
throws Exception {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, ADDR_TYPE, SRC_IP, MASK_SRC_IP, SRC_PORT, MASK_SRC_PORT, DST_IP, MASK_DST_IP, DST_PORT, MASK_DST_PORT, PROTOCOL, DIRECTION, IS_VALID, OP_TIME,LAST_UPDATE ) values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
int count = 0;
|
||||
for (IpRegion ipRegion : ipRegionList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { ipRegion.getRegionId(), ipRegion.getGroupId(), ipRegion.getAddrType(),
|
||||
ipRegion.getSrcIp(), ipRegion.getMaskSrcIp(), ipRegion.getSrcPort(), ipRegion.getMaskSrcPort(),
|
||||
ipRegion.getDstIp(), ipRegion.getMaskDstIp(), ipRegion.getDstPort(), ipRegion.getMaskDstPort(),
|
||||
ipRegion.getProtocol(), ipRegion.getDirection(), ipRegion.getIsValid(), ipRegion.getOpTime()
|
||||
|
||||
};
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 14) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(ipRegion.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
if (count % batchSize == 0) {
|
||||
ps.executeBatch();
|
||||
//conn.commit();
|
||||
}
|
||||
}
|
||||
ps.executeBatch();
|
||||
//conn.commit();
|
||||
}
|
||||
|
||||
public static void saveNumRegion(String name, List<NumRegion> numRegionList, Connection conn, int batchSize)
|
||||
throws Exception {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
" (REGION_ID,GROUP_ID,LOW_BOUNDARY,UP_BOUNDARY,IS_VALID,OP_TIME,LAST_UPDATE) values(?, ?, ?, ?, ?, ?, sysdate)");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
int count = 0;
|
||||
for (NumRegion numRegion : numRegionList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { numRegion.getRegionId(), numRegion.getGroupId(), numRegion.getLowBoundary(),
|
||||
numRegion.getUpBoundary(), numRegion.getIsValid(), numRegion.getOpTime() };
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 5) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(numRegion.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
if (count % batchSize == 0) {
|
||||
ps.executeBatch();
|
||||
//conn.commit();
|
||||
}
|
||||
}
|
||||
ps.executeBatch();
|
||||
//conn.commit();
|
||||
}
|
||||
|
||||
public static void saveStrongStrRegion(String name, List<StrRegion> strRegionList, Connection conn, int batchSize)
|
||||
throws Exception {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, DISTRICT, KEYWORDS, EXPR_TYPE, MATCH_METHOD , IS_HEXBIN, IS_VALID, OP_TIME,LAST_UPDATE ) values(?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
int count = 0;
|
||||
for (StrRegion strRegion : strRegionList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { strRegion.getRegionId(), strRegion.getGroupId(), strRegion.getDistrict(),
|
||||
strRegion.getKeywords(), strRegion.getExprType(), strRegion.getMatchMethod(),
|
||||
strRegion.getIsHexbin(), strRegion.getIsValid(), strRegion.getOpTime() };
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 8) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(strRegion.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
if (count % batchSize == 0) {
|
||||
ps.executeBatch();
|
||||
//conn.commit();
|
||||
}
|
||||
}
|
||||
ps.executeBatch();
|
||||
//conn.commit();
|
||||
}
|
||||
|
||||
public static void saveStrRegion(String name, List<StrRegion> strRegionList, Connection conn, int batchSize)
|
||||
throws Exception {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, KEYWORDS, EXPR_TYPE, MATCH_METHOD , IS_HEXBIN, IS_VALID, OP_TIME,LAST_UPDATE ) values( ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
int count = 0;
|
||||
for (StrRegion strRegion : strRegionList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { strRegion.getRegionId(), strRegion.getGroupId(), strRegion.getKeywords(),
|
||||
strRegion.getExprType(), strRegion.getMatchMethod(), strRegion.getIsHexbin(),
|
||||
strRegion.getIsValid(), strRegion.getOpTime() };
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 7) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(strRegion.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
if (count % batchSize == 0) {
|
||||
ps.executeBatch();
|
||||
//conn.commit();
|
||||
}
|
||||
}
|
||||
ps.executeBatch();
|
||||
//conn.commit();
|
||||
}
|
||||
}
|
||||
@@ -1,472 +0,0 @@
|
||||
package com.nis.web.service.restful;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import com.nis.domain.restful.ConfigCompile;
|
||||
import com.nis.domain.restful.ConfigGroupRelation;
|
||||
import com.nis.domain.restful.IpRegion;
|
||||
import com.nis.domain.restful.NumRegion;
|
||||
import com.nis.domain.restful.StrRegion;
|
||||
import com.nis.web.service.SaveRequestLogThread;
|
||||
|
||||
/**
|
||||
* jdbc测试批量插入
|
||||
*
|
||||
* @author RenKaiGe-Office
|
||||
*
|
||||
*/
|
||||
public class JDBCThreadTest implements Runnable {
|
||||
|
||||
private static SaveRequestLogThread thread;
|
||||
private static Long start;
|
||||
private CountDownLatch latch;
|
||||
private Boolean isStrongStr;
|
||||
private String tableName;
|
||||
private int batchSize;
|
||||
private Connection conn;
|
||||
private List<ConfigCompile> compileList;
|
||||
private List<ConfigGroupRelation> groupList;
|
||||
private List<IpRegion> ipRegionList;
|
||||
private List<NumRegion> numRegionList;
|
||||
private List<StrRegion> strRegionList;
|
||||
|
||||
public JDBCThreadTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
public JDBCThreadTest(int batchSize, Connection conn, CountDownLatch latch, SaveRequestLogThread thread,
|
||||
Long start) {
|
||||
super();
|
||||
this.batchSize = batchSize;
|
||||
this.conn = conn;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public JDBCThreadTest(String tableName, int batchSize, Connection conn, CountDownLatch latch,
|
||||
SaveRequestLogThread thread, Long start) {
|
||||
super();
|
||||
this.tableName = tableName;
|
||||
this.batchSize = batchSize;
|
||||
this.conn = conn;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public JDBCThreadTest(boolean isStrongStr, String tableName, int batchSize, Connection conn, CountDownLatch latch,
|
||||
SaveRequestLogThread thread, Long start) {
|
||||
super();
|
||||
this.isStrongStr = isStrongStr;
|
||||
this.tableName = tableName;
|
||||
this.batchSize = batchSize;
|
||||
this.conn = conn;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public SaveRequestLogThread getThread() {
|
||||
return thread;
|
||||
}
|
||||
|
||||
public void setThread(SaveRequestLogThread thread) {
|
||||
this.thread = thread;
|
||||
}
|
||||
|
||||
public Long getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(Long start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public int getBatchSize() {
|
||||
return batchSize;
|
||||
}
|
||||
|
||||
public void setBatchSize(int batchSize) {
|
||||
this.batchSize = batchSize;
|
||||
}
|
||||
|
||||
public CountDownLatch getLatch() {
|
||||
return latch;
|
||||
}
|
||||
|
||||
public void setLatch(CountDownLatch latch) {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public Boolean getIsStrongStr() {
|
||||
return isStrongStr;
|
||||
}
|
||||
|
||||
public void setIsStrongStr(Boolean isStrongStr) {
|
||||
this.isStrongStr = isStrongStr;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public Connection getConn() {
|
||||
return conn;
|
||||
}
|
||||
|
||||
public void setConn(Connection conn) {
|
||||
this.conn = conn;
|
||||
}
|
||||
|
||||
public List<ConfigCompile> getCompileList() {
|
||||
return compileList;
|
||||
}
|
||||
|
||||
public void setCompileList(List<ConfigCompile> compileList) {
|
||||
this.compileList = compileList;
|
||||
}
|
||||
|
||||
public List<ConfigGroupRelation> getGroupList() {
|
||||
return groupList;
|
||||
}
|
||||
|
||||
public void setGroupList(List<ConfigGroupRelation> groupList) {
|
||||
this.groupList = groupList;
|
||||
}
|
||||
|
||||
public List<IpRegion> getIpRegionList() {
|
||||
return ipRegionList;
|
||||
}
|
||||
|
||||
public void setIpRegionList(List<IpRegion> ipRegionList) {
|
||||
this.ipRegionList = ipRegionList;
|
||||
}
|
||||
|
||||
public List<NumRegion> getNumRegionList() {
|
||||
return numRegionList;
|
||||
}
|
||||
|
||||
public void setNumRegionList(List<NumRegion> numRegionList) {
|
||||
this.numRegionList = numRegionList;
|
||||
}
|
||||
|
||||
public List<StrRegion> getStrRegionList() {
|
||||
return strRegionList;
|
||||
}
|
||||
|
||||
public void setStrRegionList(List<StrRegion> strRegionList) {
|
||||
this.strRegionList = strRegionList;
|
||||
}
|
||||
|
||||
public static java.sql.Timestamp utileDate2TimeStamp(java.util.Date udate) {
|
||||
java.sql.Timestamp sqlDate = null;
|
||||
long t = udate.getTime();
|
||||
sqlDate = new java.sql.Timestamp(t);
|
||||
return sqlDate;
|
||||
|
||||
}
|
||||
|
||||
public static void saveCompile(List<ConfigCompile> compileList, Connection conn, int batchSize) {
|
||||
if (null != conn) {
|
||||
try {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(
|
||||
"insert into CONFIG_COMPILE (COMPILE_ID ,SERVICE ,ACTION , CONT_TYPE, ATTR_TYPE, CONT_LABEL, Task_id, Guarantee_ID, AFFAIR_ID, TOPIC_ID, DO_BLACKLIST ,DO_LOG ,EFFECTIVE_RANGE , ACTIVE_SYS, CONFIG_PERCENT ,CONFIG_OPTION ,START_TIME ,END_TIME , USER_REGION, IS_VALID,GROUP_NUM,FATHER_CFG_ID ,OP_TIME,LAST_UPDATE ) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate)");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
int count = 0;
|
||||
for (ConfigCompile compile : compileList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { compile.getCompileId(), compile.getService(), compile.getAction(),
|
||||
compile.getContType(), compile.getAttrType(), compile.getContLabel(), compile.getTaskId(),
|
||||
compile.getGuaranteeId(), compile.getAffairId(), compile.getTopicId(),
|
||||
compile.getDoBlacklist(), compile.getDoLog(), compile.getEffectiveRange(),
|
||||
compile.getActiveSys(), compile.getConfigPercent(), compile.getConfigOption(),
|
||||
compile.getStartTime(), compile.getEndTime(), compile.getUserRegion(), compile.getIsValid(),
|
||||
compile.getGroupNum(), compile.getFatherCfgId(), compile.getOpTime() };
|
||||
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 16) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(compile.getStartTime()));
|
||||
} else if (x == 17) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(compile.getEndTime()));
|
||||
} else if (x == 22) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(compile.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
// if (count % batchSize == 0) {
|
||||
// ps.executeBatch();
|
||||
// ps.clearBatch();
|
||||
// }
|
||||
}
|
||||
ps.executeBatch();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
conn.close();
|
||||
conn = null;
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ps.close();
|
||||
// conn.commit();
|
||||
}
|
||||
|
||||
public static void saveGroup(List<ConfigGroupRelation> groupList, Connection conn, int batchSize) {
|
||||
if (null != conn) {
|
||||
try {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(
|
||||
"insert into CONFIG_GROUP (ID,GROUP_ID, COMPILE_ID, IS_VALID, LAST_UPDATE, OP_TIME ) values ( seq_config_group.nextval, ?, ?, ?, sysdate, ?) ");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
int count = 0;
|
||||
for (ConfigGroupRelation group : groupList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { group.getGroupId(), group.getCompileId(), group.getIsValid(),
|
||||
group.getOpTime() };
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 3) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(group.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
// if (count % batchSize == 0) {
|
||||
// ps.executeBatch();
|
||||
// ps.clearBatch();
|
||||
// }
|
||||
}
|
||||
ps.executeBatch();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
conn.close();
|
||||
conn = null;
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ps.close();
|
||||
// conn.commit();
|
||||
}
|
||||
|
||||
public static void saveIPRegion(String name, List<IpRegion> ipRegionList, Connection conn, int batchSize) {
|
||||
if (null != conn) {
|
||||
try {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, ADDR_TYPE, SRC_IP, MASK_SRC_IP, SRC_PORT, MASK_SRC_PORT, DST_IP, MASK_DST_IP, DST_PORT, MASK_DST_PORT, PROTOCOL, DIRECTION, IS_VALID, OP_TIME,LAST_UPDATE ) values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
int count = 0;
|
||||
for (IpRegion ipRegion : ipRegionList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { ipRegion.getRegionId(), ipRegion.getGroupId(), ipRegion.getAddrType(),
|
||||
ipRegion.getSrcIp(), ipRegion.getMaskSrcIp(), ipRegion.getSrcPort(),
|
||||
ipRegion.getMaskSrcPort(), ipRegion.getDstIp(), ipRegion.getMaskDstIp(),
|
||||
ipRegion.getDstPort(), ipRegion.getMaskDstPort(), ipRegion.getProtocol(),
|
||||
ipRegion.getDirection(), ipRegion.getIsValid(), ipRegion.getOpTime()
|
||||
|
||||
};
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 14) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(ipRegion.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
// if (count % batchSize == 0) {
|
||||
// ps.executeBatch();
|
||||
// ps.clearBatch();
|
||||
// }
|
||||
}
|
||||
ps.executeBatch();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
conn.close();
|
||||
conn = null;
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ps.close();
|
||||
// conn.commit();
|
||||
}
|
||||
|
||||
public static void saveNumRegion(String name, List<NumRegion> numRegionList, Connection conn, int batchSize) {
|
||||
if (null != conn) {
|
||||
try {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
" (REGION_ID,GROUP_ID,LOW_BOUNDARY,UP_BOUNDARY,IS_VALID,OP_TIME,LAST_UPDATE) values(?, ?, ?, ?, ?, ?, sysdate)");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
int count = 0;
|
||||
for (NumRegion numRegion : numRegionList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { numRegion.getRegionId(), numRegion.getGroupId(),
|
||||
numRegion.getLowBoundary(), numRegion.getUpBoundary(), numRegion.getIsValid(),
|
||||
numRegion.getOpTime() };
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 5) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(numRegion.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
// if (count % batchSize == 0) {
|
||||
// ps.executeBatch();
|
||||
// ps.clearBatch();
|
||||
// }
|
||||
}
|
||||
ps.executeBatch();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
conn.close();
|
||||
conn = null;
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ps.close();
|
||||
// conn.commit();
|
||||
}
|
||||
|
||||
public static void saveStrongStrRegion(String name, List<StrRegion> strRegionList, Connection conn, int batchSize) {
|
||||
if (null != conn) {
|
||||
try {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, DISTRICT, KEYWORDS, EXPR_TYPE, MATCH_METHOD , IS_HEXBIN, IS_VALID, OP_TIME,LAST_UPDATE ) values(?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
|
||||
int count = 0;
|
||||
for (StrRegion strRegion : strRegionList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { strRegion.getRegionId(), strRegion.getGroupId(),
|
||||
strRegion.getDistrict(), strRegion.getKeywords(), strRegion.getExprType(),
|
||||
strRegion.getMatchMethod(), strRegion.getIsHexbin(), strRegion.getIsValid(),
|
||||
strRegion.getOpTime() };
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 8) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(strRegion.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
// if (count % batchSize == 0) {
|
||||
// ps.executeBatch();
|
||||
// ps.clearBatch();
|
||||
// }
|
||||
}
|
||||
ps.executeBatch();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
conn.close();
|
||||
conn = null;
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ps.close();
|
||||
// conn.commit();
|
||||
}
|
||||
|
||||
public static void saveStrRegion(String name, List<StrRegion> strRegionList, Connection conn, int batchSize) {
|
||||
if (null != conn) {
|
||||
try {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, KEYWORDS, EXPR_TYPE, MATCH_METHOD , IS_HEXBIN, IS_VALID, OP_TIME,LAST_UPDATE ) values( ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
conn.setAutoCommit(false);
|
||||
PreparedStatement ps = conn.prepareStatement(sb.toString());
|
||||
|
||||
int count = 0;
|
||||
for (StrRegion strRegion : strRegionList) {
|
||||
count++;
|
||||
Object[] obj = new Object[] { strRegion.getRegionId(), strRegion.getGroupId(),
|
||||
strRegion.getKeywords(), strRegion.getExprType(), strRegion.getMatchMethod(),
|
||||
strRegion.getIsHexbin(), strRegion.getIsValid(), strRegion.getOpTime() };
|
||||
for (int x = 0; x < obj.length; x++) {
|
||||
if (x == 7) {
|
||||
ps.setTimestamp(x + 1, utileDate2TimeStamp(strRegion.getOpTime()));
|
||||
} else {
|
||||
ps.setObject(x + 1, obj[x]);
|
||||
}
|
||||
}
|
||||
ps.addBatch();
|
||||
// if (count % batchSize == 0) {
|
||||
// ps.executeBatch();
|
||||
// ps.clearBatch();
|
||||
// }
|
||||
}
|
||||
ps.executeBatch();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
conn.close();
|
||||
conn = null;
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ps.close();
|
||||
// conn.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (conn) {
|
||||
try {
|
||||
if (null != compileList && compileList.size() > 0) {
|
||||
saveCompile(compileList, conn, batchSize);
|
||||
} else if (null != groupList && groupList.size() > 0) {
|
||||
saveGroup(groupList, conn, batchSize);
|
||||
} else if (null != ipRegionList && ipRegionList.size() > 0) {
|
||||
saveIPRegion(tableName, ipRegionList, conn, batchSize);
|
||||
} else if (null != strRegionList && strRegionList.size() > 0) {
|
||||
if (null != isStrongStr && isStrongStr) {
|
||||
saveStrongStrRegion(tableName, strRegionList, conn, batchSize);
|
||||
} else {
|
||||
saveStrRegion(tableName, strRegionList, conn, batchSize);
|
||||
}
|
||||
}else if (null != numRegionList && numRegionList.size() > 0) {
|
||||
saveNumRegion(tableName, numRegionList, conn, batchSize);
|
||||
}
|
||||
latch.countDown();
|
||||
System.out.println("latchCount=======================" + latch.getCount());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
package com.nis.web.service.restful;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.List;
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.jdbc.object.BatchSqlUpdate;
|
||||
import com.nis.domain.restful.ConfigCompile;
|
||||
import com.nis.domain.restful.ConfigGroupRelation;
|
||||
import com.nis.domain.restful.IpRegion;
|
||||
import com.nis.domain.restful.NumRegion;
|
||||
import com.nis.domain.restful.StrRegion;
|
||||
|
||||
/**
|
||||
* jdbc测试批量插入
|
||||
*
|
||||
* @author RenKaiGe-Office
|
||||
*
|
||||
*/
|
||||
public class SpringJDBCTest {
|
||||
public static BatchSqlUpdate saveCompile(List<ConfigCompile> compileList, DataSource ds, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(
|
||||
"insert into CONFIG_COMPILE (COMPILE_ID ,SERVICE ,ACTION , CONT_TYPE, ATTR_TYPE, CONT_LABEL, Task_id, Guarantee_ID, AFFAIR_ID, TOPIC_ID, DO_BLACKLIST ,DO_LOG ,EFFECTIVE_RANGE , ACTIVE_SYS, CONFIG_PERCENT ,CONFIG_OPTION ,START_TIME ,END_TIME , USER_REGION, IS_VALID,GROUP_NUM,FATHER_CFG_ID ,OP_TIME,LAST_UPDATE ) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate)");
|
||||
|
||||
BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR,
|
||||
Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR,
|
||||
Types.INTEGER, Types.BIGINT, Types.INTEGER, Types.DATE, Types.DATE, Types.VARCHAR, Types.INTEGER,
|
||||
Types.INTEGER, Types.BIGINT, Types.DATE });
|
||||
for (ConfigCompile compile : compileList) {
|
||||
bsu.update(new Object[] { compile.getCompileId(), compile.getService(), compile.getAction(),
|
||||
compile.getContType(), compile.getAttrType(), compile.getContLabel(), compile.getTaskId(),
|
||||
compile.getGuaranteeId(), compile.getAffairId(), compile.getTopicId(), compile.getDoBlacklist(),
|
||||
compile.getDoLog(), compile.getEffectiveRange(), compile.getActiveSys(), compile.getConfigPercent(),
|
||||
compile.getConfigOption(), compile.getStartTime(), compile.getEndTime(), compile.getUserRegion(),
|
||||
compile.getIsValid(), compile.getGroupNum(), compile.getFatherCfgId(), compile.getOpTime() });
|
||||
}
|
||||
// bsu.flush();
|
||||
return bsu;
|
||||
}
|
||||
|
||||
public static BatchSqlUpdate saveGroup(List<ConfigGroupRelation> groupList, DataSource ds, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(
|
||||
"insert into CONFIG_GROUP (ID,GROUP_ID, COMPILE_ID, IS_VALID, LAST_UPDATE, OP_TIME ) values ( seq_config_group.nextval, ?, ?, ?, sysdate, ?) ");
|
||||
BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.DATE });
|
||||
for (ConfigGroupRelation group : groupList) {
|
||||
bsu.update(
|
||||
new Object[] { group.getGroupId(), group.getCompileId(), group.getIsValid(), group.getOpTime() });
|
||||
}
|
||||
// bsu.flush();
|
||||
return bsu;
|
||||
}
|
||||
|
||||
public static BatchSqlUpdate saveIPRegion(String name, List<IpRegion> ipRegionList, DataSource ds, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, ADDR_TYPE, SRC_IP, MASK_SRC_IP, SRC_PORT, MASK_SRC_PORT, DST_IP, MASK_DST_IP, DST_PORT, MASK_DST_PORT, PROTOCOL, DIRECTION, IS_VALID, OP_TIME,LAST_UPDATE ) values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
|
||||
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.DATE });
|
||||
for (IpRegion ipRegion : ipRegionList) {
|
||||
bsu.update(new Object[] { ipRegion.getRegionId(), ipRegion.getGroupId(), ipRegion.getAddrType(),
|
||||
ipRegion.getSrcIp(), ipRegion.getMaskSrcIp(), ipRegion.getSrcPort(), ipRegion.getMaskSrcPort(),
|
||||
ipRegion.getDstIp(), ipRegion.getMaskDstIp(), ipRegion.getDstPort(), ipRegion.getMaskDstPort(),
|
||||
ipRegion.getProtocol(), ipRegion.getDirection(), ipRegion.getIsValid(), ipRegion.getOpTime()
|
||||
|
||||
});
|
||||
}
|
||||
// bsu.flush();
|
||||
return bsu;
|
||||
}
|
||||
|
||||
public static BatchSqlUpdate saveNumRegion(String name, List<NumRegion> numRegionList, DataSource ds,
|
||||
int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
" (REGION_ID,GROUP_ID,LOW_BOUNDARY,UP_BOUNDARY,IS_VALID,OP_TIME,LAST_UPDATE) values(?, ?, ?, ?, ?, ?, sysdate)");
|
||||
BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.DATE });
|
||||
for (NumRegion numRegion : numRegionList) {
|
||||
bsu.update(new Object[] { numRegion.getRegionId(), numRegion.getGroupId(), numRegion.getLowBoundary(),
|
||||
numRegion.getUpBoundary(), numRegion.getIsValid(), numRegion.getOpTime() });
|
||||
}
|
||||
// bsu.flush();
|
||||
return bsu;
|
||||
}
|
||||
|
||||
public static BatchSqlUpdate saveStrongStrRegion(String name, List<StrRegion> strRegionList, DataSource ds,
|
||||
int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, DISTRICT, KEYWORDS, EXPR_TYPE, MATCH_METHOD , IS_HEXBIN, IS_VALID, OP_TIME,LAST_UPDATE ) values(?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.INTEGER, Types.DATE });
|
||||
for (StrRegion strRegion : strRegionList) {
|
||||
bsu.update(new Object[] { strRegion.getRegionId(), strRegion.getGroupId(), strRegion.getDistrict(),
|
||||
strRegion.getKeywords(), strRegion.getExprType(), strRegion.getMatchMethod(),
|
||||
strRegion.getIsHexbin(), strRegion.getIsValid(), strRegion.getOpTime() });
|
||||
}
|
||||
// bsu.flush();
|
||||
return bsu;
|
||||
}
|
||||
|
||||
public static BatchSqlUpdate saveStrRegion(String name, List<StrRegion> strRegionList, DataSource ds,
|
||||
int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, KEYWORDS, EXPR_TYPE, MATCH_METHOD , IS_HEXBIN, IS_VALID, OP_TIME,LAST_UPDATE ) values( ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.DATE });
|
||||
|
||||
for (StrRegion strRegion : strRegionList) {
|
||||
bsu.update(new Object[] { strRegion.getRegionId(), strRegion.getGroupId(), strRegion.getKeywords(),
|
||||
strRegion.getExprType(), strRegion.getMatchMethod(), strRegion.getIsHexbin(),
|
||||
strRegion.getIsValid(), strRegion.getOpTime() });
|
||||
}
|
||||
// bsu.flush();
|
||||
return bsu;
|
||||
}
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
package com.nis.web.service.restful;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Types;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.jdbc.object.BatchSqlUpdate;
|
||||
import com.nis.domain.restful.ConfigCompile;
|
||||
import com.nis.domain.restful.ConfigGroupRelation;
|
||||
import com.nis.domain.restful.IpRegion;
|
||||
import com.nis.domain.restful.NumRegion;
|
||||
import com.nis.domain.restful.StrRegion;
|
||||
|
||||
/**
|
||||
* jdbc测试批量插入
|
||||
*
|
||||
* @author RenKaiGe-Office
|
||||
*
|
||||
*/
|
||||
public class SpringJDBCThreadTest implements Runnable {
|
||||
private CountDownLatch latch;
|
||||
private Boolean isStrongStr;
|
||||
private String tableName;
|
||||
private int batchSize;
|
||||
private BatchSqlUpdate bsu;
|
||||
private List<ConfigCompile> compileList;
|
||||
private List<ConfigGroupRelation> groupList;
|
||||
private List<IpRegion> ipRegionList;
|
||||
private List<NumRegion> numRegionList;
|
||||
private List<StrRegion> strRegionList;
|
||||
|
||||
public SpringJDBCThreadTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SpringJDBCThreadTest(int batchSize, BatchSqlUpdate bsu, CountDownLatch latch) {
|
||||
super();
|
||||
this.batchSize = batchSize;
|
||||
this.bsu = bsu;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public SpringJDBCThreadTest(String tableName, int batchSize, BatchSqlUpdate bsu, CountDownLatch latch) {
|
||||
super();
|
||||
this.tableName = tableName;
|
||||
this.batchSize = batchSize;
|
||||
this.bsu = bsu;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public SpringJDBCThreadTest(boolean isStrongStr, String tableName, int batchSize, BatchSqlUpdate bsu,
|
||||
CountDownLatch latch) {
|
||||
super();
|
||||
this.isStrongStr = isStrongStr;
|
||||
this.tableName = tableName;
|
||||
this.batchSize = batchSize;
|
||||
this.bsu = bsu;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public int getBatchSize() {
|
||||
return batchSize;
|
||||
}
|
||||
|
||||
public void setBatchSize(int batchSize) {
|
||||
this.batchSize = batchSize;
|
||||
}
|
||||
|
||||
public BatchSqlUpdate getBsu() {
|
||||
return bsu;
|
||||
}
|
||||
|
||||
public void setBsu(BatchSqlUpdate bsu) {
|
||||
this.bsu = bsu;
|
||||
}
|
||||
|
||||
public CountDownLatch getLatch() {
|
||||
return latch;
|
||||
}
|
||||
|
||||
public void setLatch(CountDownLatch latch) {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public Boolean getIsStrongStr() {
|
||||
return isStrongStr;
|
||||
}
|
||||
|
||||
public void setIsStrongStr(Boolean isStrongStr) {
|
||||
this.isStrongStr = isStrongStr;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public List<ConfigCompile> getCompileList() {
|
||||
return compileList;
|
||||
}
|
||||
|
||||
public void setCompileList(List<ConfigCompile> compileList) {
|
||||
this.compileList = compileList;
|
||||
}
|
||||
|
||||
public List<ConfigGroupRelation> getGroupList() {
|
||||
return groupList;
|
||||
}
|
||||
|
||||
public void setGroupList(List<ConfigGroupRelation> groupList) {
|
||||
this.groupList = groupList;
|
||||
}
|
||||
|
||||
public List<IpRegion> getIpRegionList() {
|
||||
return ipRegionList;
|
||||
}
|
||||
|
||||
public void setIpRegionList(List<IpRegion> ipRegionList) {
|
||||
this.ipRegionList = ipRegionList;
|
||||
}
|
||||
|
||||
public List<NumRegion> getNumRegionList() {
|
||||
return numRegionList;
|
||||
}
|
||||
|
||||
public void setNumRegionList(List<NumRegion> numRegionList) {
|
||||
this.numRegionList = numRegionList;
|
||||
}
|
||||
|
||||
public List<StrRegion> getStrRegionList() {
|
||||
return strRegionList;
|
||||
}
|
||||
|
||||
public void setStrRegionList(List<StrRegion> strRegionList) {
|
||||
this.strRegionList = strRegionList;
|
||||
}
|
||||
|
||||
public static void saveCompile(List<ConfigCompile> compileList, BatchSqlUpdate bsu, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(
|
||||
"insert into CONFIG_COMPILE (COMPILE_ID ,SERVICE ,ACTION , CONT_TYPE, ATTR_TYPE, CONT_LABEL, Task_id, Guarantee_ID, AFFAIR_ID, TOPIC_ID, DO_BLACKLIST ,DO_LOG ,EFFECTIVE_RANGE , ACTIVE_SYS, CONFIG_PERCENT ,CONFIG_OPTION ,START_TIME ,END_TIME , USER_REGION, IS_VALID,GROUP_NUM,FATHER_CFG_ID ,OP_TIME,LAST_UPDATE ) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate)");
|
||||
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR,
|
||||
Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR,
|
||||
Types.INTEGER, Types.BIGINT, Types.INTEGER, Types.DATE, Types.DATE, Types.VARCHAR, Types.INTEGER,
|
||||
Types.INTEGER, Types.BIGINT, Types.DATE });
|
||||
for (ConfigCompile compile : compileList) {
|
||||
bsu.update(new Object[] { compile.getCompileId(), compile.getService(), compile.getAction(),
|
||||
compile.getContType(), compile.getAttrType(), compile.getContLabel(), compile.getTaskId(),
|
||||
compile.getGuaranteeId(), compile.getAffairId(), compile.getTopicId(), compile.getDoBlacklist(),
|
||||
compile.getDoLog(), compile.getEffectiveRange(), compile.getActiveSys(), compile.getConfigPercent(),
|
||||
compile.getConfigOption(), compile.getStartTime(), compile.getEndTime(), compile.getUserRegion(),
|
||||
compile.getIsValid(), compile.getGroupNum(), compile.getFatherCfgId(), compile.getOpTime() });
|
||||
}
|
||||
bsu.flush();
|
||||
}
|
||||
|
||||
public static void saveGroup(List<ConfigGroupRelation> groupList, BatchSqlUpdate bsu, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(
|
||||
"insert into CONFIG_GROUP (ID,GROUP_ID, COMPILE_ID, IS_VALID, LAST_UPDATE, OP_TIME ) values ( seq_config_group.nextval, ?, ?, ?, sysdate, ?) ");
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.DATE });
|
||||
for (ConfigGroupRelation group : groupList) {
|
||||
bsu.update(
|
||||
new Object[] { group.getGroupId(), group.getCompileId(), group.getIsValid(), group.getOpTime() });
|
||||
}
|
||||
bsu.flush();
|
||||
|
||||
}
|
||||
|
||||
public static void saveIPRegion(String name, List<IpRegion> ipRegionList, BatchSqlUpdate bsu, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, ADDR_TYPE, SRC_IP, MASK_SRC_IP, SRC_PORT, MASK_SRC_PORT, DST_IP, MASK_DST_IP, DST_PORT, MASK_DST_PORT, PROTOCOL, DIRECTION, IS_VALID, OP_TIME,LAST_UPDATE ) values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
|
||||
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.DATE });
|
||||
for (IpRegion ipRegion : ipRegionList) {
|
||||
bsu.update(new Object[] { ipRegion.getRegionId(), ipRegion.getGroupId(), ipRegion.getAddrType(),
|
||||
ipRegion.getSrcIp(), ipRegion.getMaskSrcIp(), ipRegion.getSrcPort(), ipRegion.getMaskSrcPort(),
|
||||
ipRegion.getDstIp(), ipRegion.getMaskDstIp(), ipRegion.getDstPort(), ipRegion.getMaskDstPort(),
|
||||
ipRegion.getProtocol(), ipRegion.getDirection(), ipRegion.getIsValid(), ipRegion.getOpTime()
|
||||
|
||||
});
|
||||
}
|
||||
bsu.flush();
|
||||
}
|
||||
|
||||
public static void saveNumRegion(String name, List<NumRegion> numRegionList, BatchSqlUpdate bsu, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
" (REGION_ID,GROUP_ID,LOW_BOUNDARY,UP_BOUNDARY,IS_VALID,OP_TIME,LAST_UPDATE) values(?, ?, ?, ?, ?, ?, sysdate)");
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.DATE });
|
||||
for (NumRegion numRegion : numRegionList) {
|
||||
bsu.update(new Object[] { numRegion.getRegionId(), numRegion.getGroupId(), numRegion.getLowBoundary(),
|
||||
numRegion.getUpBoundary(), numRegion.getIsValid(), numRegion.getOpTime() });
|
||||
}
|
||||
bsu.flush();
|
||||
}
|
||||
|
||||
public static void saveStrongStrRegion(String name, List<StrRegion> strRegionList, BatchSqlUpdate bsu,
|
||||
int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, DISTRICT, KEYWORDS, EXPR_TYPE, MATCH_METHOD , IS_HEXBIN, IS_VALID, OP_TIME,LAST_UPDATE ) values(?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.INTEGER, Types.DATE });
|
||||
for (StrRegion strRegion : strRegionList) {
|
||||
bsu.update(new Object[] { strRegion.getRegionId(), strRegion.getGroupId(), strRegion.getDistrict(),
|
||||
strRegion.getKeywords(), strRegion.getExprType(), strRegion.getMatchMethod(),
|
||||
strRegion.getIsHexbin(), strRegion.getIsValid(), strRegion.getOpTime() });
|
||||
}
|
||||
bsu.flush();
|
||||
}
|
||||
|
||||
public static void saveStrRegion(String name, List<StrRegion> strRegionList, BatchSqlUpdate bsu, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, KEYWORDS, EXPR_TYPE, MATCH_METHOD , IS_HEXBIN, IS_VALID, OP_TIME,LAST_UPDATE ) values( ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.DATE });
|
||||
|
||||
for (StrRegion strRegion : strRegionList) {
|
||||
bsu.update(new Object[] { strRegion.getRegionId(), strRegion.getGroupId(), strRegion.getKeywords(),
|
||||
strRegion.getExprType(), strRegion.getMatchMethod(), strRegion.getIsHexbin(),
|
||||
strRegion.getIsValid(), strRegion.getOpTime() });
|
||||
}
|
||||
bsu.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (null != compileList && compileList.size() > 0) {
|
||||
saveCompile(compileList, bsu, batchSize);
|
||||
} else if (null != groupList && groupList.size() > 0) {
|
||||
saveGroup(groupList, bsu, batchSize);
|
||||
} else if (null != ipRegionList && ipRegionList.size() > 0) {
|
||||
saveIPRegion(tableName, ipRegionList, bsu, batchSize);
|
||||
} else if (null != strRegionList && strRegionList.size() > 0) {
|
||||
if (null != isStrongStr && isStrongStr) {
|
||||
saveStrongStrRegion(tableName, strRegionList, bsu, batchSize);
|
||||
} else {
|
||||
saveStrRegion(tableName, strRegionList, bsu, batchSize);
|
||||
}
|
||||
} else if (null != numRegionList && numRegionList.size() > 0) {
|
||||
saveNumRegion(tableName, numRegionList, bsu, batchSize);
|
||||
}
|
||||
latch.countDown();
|
||||
System.out.println("SpringJDBC--latchCount=======================" + latch.getCount());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
package com.nis.web.service.restful;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Types;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import org.springframework.jdbc.object.BatchSqlUpdate;
|
||||
import com.nis.domain.restful.ConfigCompile;
|
||||
import com.nis.domain.restful.ConfigGroupRelation;
|
||||
import com.nis.domain.restful.IpRegion;
|
||||
import com.nis.domain.restful.NumRegion;
|
||||
import com.nis.domain.restful.StrRegion;
|
||||
|
||||
/**
|
||||
* jdbc测试批量插入
|
||||
*
|
||||
* @author RenKaiGe-Office
|
||||
*
|
||||
*/
|
||||
public class SpringJDBCThreadTest2 implements Runnable {
|
||||
private CountDownLatch latch;
|
||||
private Boolean isStrongStr;
|
||||
private String tableName;
|
||||
private int batchSize;
|
||||
private BatchSqlUpdate bsu;
|
||||
private List<ConfigCompile> compileList;
|
||||
private List<ConfigGroupRelation> groupList;
|
||||
private List<IpRegion> ipRegionList;
|
||||
private List<NumRegion> numRegionList;
|
||||
private List<StrRegion> strRegionList;
|
||||
|
||||
public SpringJDBCThreadTest2() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SpringJDBCThreadTest2(int batchSize, BatchSqlUpdate bsu, CountDownLatch latch) {
|
||||
super();
|
||||
this.batchSize = batchSize;
|
||||
this.bsu = bsu;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public SpringJDBCThreadTest2(String tableName, int batchSize, BatchSqlUpdate bsu, CountDownLatch latch) {
|
||||
super();
|
||||
this.tableName = tableName;
|
||||
this.batchSize = batchSize;
|
||||
this.bsu = bsu;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public SpringJDBCThreadTest2(boolean isStrongStr, String tableName, int batchSize, BatchSqlUpdate bsu,
|
||||
CountDownLatch latch) {
|
||||
super();
|
||||
this.isStrongStr = isStrongStr;
|
||||
this.tableName = tableName;
|
||||
this.batchSize = batchSize;
|
||||
this.bsu = bsu;
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public int getBatchSize() {
|
||||
return batchSize;
|
||||
}
|
||||
|
||||
public void setBatchSize(int batchSize) {
|
||||
this.batchSize = batchSize;
|
||||
}
|
||||
|
||||
public BatchSqlUpdate getBsu() {
|
||||
return bsu;
|
||||
}
|
||||
|
||||
public void setBsu(BatchSqlUpdate bsu) {
|
||||
this.bsu = bsu;
|
||||
}
|
||||
|
||||
public CountDownLatch getLatch() {
|
||||
return latch;
|
||||
}
|
||||
|
||||
public void setLatch(CountDownLatch latch) {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public Boolean getIsStrongStr() {
|
||||
return isStrongStr;
|
||||
}
|
||||
|
||||
public void setIsStrongStr(Boolean isStrongStr) {
|
||||
this.isStrongStr = isStrongStr;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public List<ConfigCompile> getCompileList() {
|
||||
return compileList;
|
||||
}
|
||||
|
||||
public void setCompileList(List<ConfigCompile> compileList) {
|
||||
this.compileList = compileList;
|
||||
}
|
||||
|
||||
public List<ConfigGroupRelation> getGroupList() {
|
||||
return groupList;
|
||||
}
|
||||
|
||||
public void setGroupList(List<ConfigGroupRelation> groupList) {
|
||||
this.groupList = groupList;
|
||||
}
|
||||
|
||||
public List<IpRegion> getIpRegionList() {
|
||||
return ipRegionList;
|
||||
}
|
||||
|
||||
public void setIpRegionList(List<IpRegion> ipRegionList) {
|
||||
this.ipRegionList = ipRegionList;
|
||||
}
|
||||
|
||||
public List<NumRegion> getNumRegionList() {
|
||||
return numRegionList;
|
||||
}
|
||||
|
||||
public void setNumRegionList(List<NumRegion> numRegionList) {
|
||||
this.numRegionList = numRegionList;
|
||||
}
|
||||
|
||||
public List<StrRegion> getStrRegionList() {
|
||||
return strRegionList;
|
||||
}
|
||||
|
||||
public void setStrRegionList(List<StrRegion> strRegionList) {
|
||||
this.strRegionList = strRegionList;
|
||||
}
|
||||
|
||||
public static void saveCompile(List<ConfigCompile> compileList, BatchSqlUpdate bsu, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(
|
||||
"insert into CONFIG_COMPILE (COMPILE_ID ,SERVICE ,ACTION , CONT_TYPE, ATTR_TYPE, CONT_LABEL, Task_id, Guarantee_ID, AFFAIR_ID, TOPIC_ID, DO_BLACKLIST ,DO_LOG ,EFFECTIVE_RANGE , ACTIVE_SYS, CONFIG_PERCENT ,CONFIG_OPTION ,START_TIME ,END_TIME , USER_REGION, IS_VALID,GROUP_NUM,FATHER_CFG_ID ,OP_TIME,LAST_UPDATE ) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate)");
|
||||
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR,
|
||||
Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR,
|
||||
Types.INTEGER, Types.BIGINT, Types.INTEGER, Types.DATE, Types.DATE, Types.VARCHAR, Types.INTEGER,
|
||||
Types.INTEGER, Types.BIGINT, Types.DATE });
|
||||
for (ConfigCompile compile : compileList) {
|
||||
bsu.update(new Object[] { compile.getCompileId(), compile.getService(), compile.getAction(),
|
||||
compile.getContType(), compile.getAttrType(), compile.getContLabel(), compile.getTaskId(),
|
||||
compile.getGuaranteeId(), compile.getAffairId(), compile.getTopicId(), compile.getDoBlacklist(),
|
||||
compile.getDoLog(), compile.getEffectiveRange(), compile.getActiveSys(), compile.getConfigPercent(),
|
||||
compile.getConfigOption(), compile.getStartTime(), compile.getEndTime(), compile.getUserRegion(),
|
||||
compile.getIsValid(), compile.getGroupNum(), compile.getFatherCfgId(), compile.getOpTime() });
|
||||
}
|
||||
bsu.flush();
|
||||
}
|
||||
|
||||
public static void saveGroup(List<ConfigGroupRelation> groupList, BatchSqlUpdate bsu, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(
|
||||
"insert into CONFIG_GROUP (ID,GROUP_ID, COMPILE_ID, IS_VALID, LAST_UPDATE, OP_TIME ) values ( seq_config_group.nextval, ?, ?, ?, sysdate, ?) ");
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.DATE });
|
||||
for (ConfigGroupRelation group : groupList) {
|
||||
bsu.update(
|
||||
new Object[] { group.getGroupId(), group.getCompileId(), group.getIsValid(), group.getOpTime() });
|
||||
}
|
||||
bsu.flush();
|
||||
|
||||
}
|
||||
|
||||
public static void saveIPRegion(String name, List<IpRegion> ipRegionList, BatchSqlUpdate bsu, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, ADDR_TYPE, SRC_IP, MASK_SRC_IP, SRC_PORT, MASK_SRC_PORT, DST_IP, MASK_DST_IP, DST_PORT, MASK_DST_PORT, PROTOCOL, DIRECTION, IS_VALID, OP_TIME,LAST_UPDATE ) values( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
|
||||
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.DATE });
|
||||
for (IpRegion ipRegion : ipRegionList) {
|
||||
bsu.update(new Object[] { ipRegion.getRegionId(), ipRegion.getGroupId(), ipRegion.getAddrType(),
|
||||
ipRegion.getSrcIp(), ipRegion.getMaskSrcIp(), ipRegion.getSrcPort(), ipRegion.getMaskSrcPort(),
|
||||
ipRegion.getDstIp(), ipRegion.getMaskDstIp(), ipRegion.getDstPort(), ipRegion.getMaskDstPort(),
|
||||
ipRegion.getProtocol(), ipRegion.getDirection(), ipRegion.getIsValid(), ipRegion.getOpTime()
|
||||
|
||||
});
|
||||
}
|
||||
bsu.flush();
|
||||
}
|
||||
|
||||
public static void saveNumRegion(String name, List<NumRegion> numRegionList, BatchSqlUpdate bsu, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
" (REGION_ID,GROUP_ID,LOW_BOUNDARY,UP_BOUNDARY,IS_VALID,OP_TIME,LAST_UPDATE) values(?, ?, ?, ?, ?, ?, sysdate)");
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.BIGINT, Types.INTEGER, Types.DATE });
|
||||
for (NumRegion numRegion : numRegionList) {
|
||||
bsu.update(new Object[] { numRegion.getRegionId(), numRegion.getGroupId(), numRegion.getLowBoundary(),
|
||||
numRegion.getUpBoundary(), numRegion.getIsValid(), numRegion.getOpTime() });
|
||||
}
|
||||
bsu.flush();
|
||||
}
|
||||
|
||||
public static void saveStrongStrRegion(String name, List<StrRegion> strRegionList, BatchSqlUpdate bsu,
|
||||
int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, DISTRICT, KEYWORDS, EXPR_TYPE, MATCH_METHOD , IS_HEXBIN, IS_VALID, OP_TIME,LAST_UPDATE ) values(?, ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.INTEGER, Types.DATE });
|
||||
for (StrRegion strRegion : strRegionList) {
|
||||
bsu.update(new Object[] { strRegion.getRegionId(), strRegion.getGroupId(), strRegion.getDistrict(),
|
||||
strRegion.getKeywords(), strRegion.getExprType(), strRegion.getMatchMethod(),
|
||||
strRegion.getIsHexbin(), strRegion.getIsValid(), strRegion.getOpTime() });
|
||||
}
|
||||
bsu.flush();
|
||||
}
|
||||
|
||||
public static void saveStrRegion(String name, List<StrRegion> strRegionList, BatchSqlUpdate bsu, int batchSize) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("insert into ");
|
||||
sb.append(name);
|
||||
sb.append(
|
||||
"(REGION_ID, GROUP_ID, KEYWORDS, EXPR_TYPE, MATCH_METHOD , IS_HEXBIN, IS_VALID, OP_TIME,LAST_UPDATE ) values( ?, ?, ?, ?, ?, ?, ?, ?, sysdate) ");
|
||||
|
||||
// BatchSqlUpdate bsu = new BatchSqlUpdate(ds, sb.toString());
|
||||
bsu.setSql(sb.toString());
|
||||
bsu.setBatchSize(batchSize);
|
||||
bsu.setTypes(new int[] { Types.BIGINT, Types.BIGINT, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER,
|
||||
Types.INTEGER, Types.DATE });
|
||||
|
||||
for (StrRegion strRegion : strRegionList) {
|
||||
bsu.update(new Object[] { strRegion.getRegionId(), strRegion.getGroupId(), strRegion.getKeywords(),
|
||||
strRegion.getExprType(), strRegion.getMatchMethod(), strRegion.getIsHexbin(),
|
||||
strRegion.getIsValid(), strRegion.getOpTime() });
|
||||
}
|
||||
bsu.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (null != compileList && compileList.size() > 0) {
|
||||
saveCompile(compileList, bsu, batchSize);
|
||||
} else if (null != groupList && groupList.size() > 0) {
|
||||
saveGroup(groupList, bsu, batchSize);
|
||||
} else if (null != ipRegionList && ipRegionList.size() > 0) {
|
||||
saveIPRegion(tableName, ipRegionList, bsu, batchSize);
|
||||
} else if (null != strRegionList && strRegionList.size() > 0) {
|
||||
if (null != isStrongStr && isStrongStr) {
|
||||
saveStrongStrRegion(tableName, strRegionList, bsu, batchSize);
|
||||
} else {
|
||||
saveStrRegion(tableName, strRegionList, bsu, batchSize);
|
||||
}
|
||||
} else if (null != numRegionList && numRegionList.size() > 0) {
|
||||
saveNumRegion(tableName, numRegionList, bsu, batchSize);
|
||||
}
|
||||
latch.countDown();
|
||||
System.out.println("SpringJDBC--latchCount=======================" + latch.getCount());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user