所谓批量加载,即把原本要发送的SQL分批统一发送,比如说原本要发送100条SQL,如果设置batch-size=3,则只需要发送100/3+1=34条,可以提高效率
批量加载分为延迟加载和立即加载,先说立即加在
首先建立测试数据库
CREATE TABLE certificate (
id varchar ( 100 ) NOT NULL default '' ,
description varchar ( 100 ) default '' ,
PRIMARY KEY (id)
);
CREATE TABLE student (
team_id varchar ( 100 ) default '' ,
id varchar ( 100 ) NOT NULL default '' ,
name varchar ( 20 ) default '' ,
cardId varchar ( 20 ) NOT NULL default '' ,
age int ( 11 ) default ' 0 ' ,
PRIMARY KEY (id)
);
CREATE TABLE team (
id varchar ( 100 ) NOT NULL default '' ,
teamName varchar ( 100 ) default '' ,
PRIMARY KEY (id)
);
INSERT INTO student VALUES
( ' 5 ' , ' 1 ' , ' spark ' , ' 200211332 ' , 13 ),
( ' 4 ' , ' 2 ' , ' jerry ' , ' 200233332 ' , 23 ),
( ' 3 ' , ' 3 ' , ' adidas ' , ' 200231332 ' , 33 ),
( ' 2 ' , ' 4 ' , ' zhouxingchi ' , ' 200231132 ' , 43 ),
( ' 1 ' , ' 5 ' , ' tomclus ' , ' 200512345 ' , 53 ),
( ' 1 ' , ' 6 ' , ' tom ' , ' 200511345 ' , 63 );
INSERT INTO team VALUES
( ' 5 ' , ' team5 ' ),
( ' 4 ' , ' team4 ' ),
( ' 3 ' , ' team3 ' ),
( ' 2 ' , ' team2 ' ),
( ' 1 ' , ' team1 ' );
INSERT INTO certificate VALUES
( ' 1 ' , ' card1 ' ),
( ' 2 ' , ' card2 ' ),
( ' 3 ' , ' card3 ' ),
( ' 4 ' , ' card4 ' ),
( ' 5 ' , ' card5 ' ),
( ' 6 ' , ' card6 ' );
建立POJO对象
package
Search.immediately;
public class Certificate ......... {
private String id;
private String description;
private Student stu;
public Student getStu() ......... {
return stu;
}
public void setStu(Student stu) ......... {
this .stu = stu;
}
public String getDescription() ......... {
return description;
}
public void setDescription(String description) ......... {
this .description = description;
}
public String getId() ......... {
return id;
}
public void setId(String id) ......... {
this .id = id;
}
}
package Search.immediately;
import java.util.HashSet;
import java.util.Set;
public class Team ......... {
private String id;
private Set students = new HashSet();
private String teamName;
private Set tests;
public Set getTests() ......... {
return tests;
}
public void setTests(Set tests) ......... {
this .tests = tests;
}
public String getId() ......... {
return id;
}
public void setId(String id) ......... {
this .id = id;
}
public String getTeamName() ......... {
return teamName;
}
public void setTeamName(String name) ......... {
this .teamName = name;
}
public Set getStudents() ......... {
return students;
}
public void setStudents(Set students) ......... {
this .students = students;
}
}
package Search.immediately;
public class Certificate ......... {
private String id;
private String description;
private Student stu;
public Student getStu() ......... {
return stu;
}
public void setStu(Student stu) ......... {
this .stu = stu;
}
public String getDescription() ......... {
return description;
}
public void setDescription(String description) ......... {
this .description = description;
}
public String getId() ......... {
return id;
}
public class Certificate ......... {
private String id;
private String description;
private Student stu;
public Student getStu() ......... {
return stu;
}
public void setStu(Student stu) ......... {
this .stu = stu;
}
public String getDescription() ......... {
return description;
}
public void setDescription(String description) ......... {
this .description = description;
}
public String getId() ......... {
return id;
}
public void setId(String id) ......... {
this .id = id;
}
}
package Search.immediately;
import java.util.HashSet;
import java.util.Set;
public class Team ......... {
private String id;
private Set students = new HashSet();
private String teamName;
private Set tests;
public Set getTests() ......... {
return tests;
}
public void setTests(Set tests) ......... {
this .tests = tests;
}
public String getId() ......... {
return id;
}
public void setId(String id) ......... {
this .id = id;
}
public String getTeamName() ......... {
return teamName;
}
public void setTeamName(String name) ......... {
this .teamName = name;
}
public Set getStudents() ......... {
return students;
}
public void setStudents(Set students) ......... {
this .students = students;
}
}
package Search.immediately;
public class Certificate ......... {
private String id;
private String description;
private Student stu;
public Student getStu() ......... {
return stu;
}
public void setStu(Student stu) ......... {
this .stu = stu;
}
public String getDescription() ......... {
return description;
}
public void setDescription(String description) ......... {
this .description = description;
}
public String getId() ......... {
return id;
}