This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
galaxy-k18-galaxy-service/src/main/java/com/nis/web/service/restful/SpringJDBCTest.java

140 lines
7.0 KiB
Java
Raw Normal View History

2017-12-19 14:55:52 +08:00
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;
}
}