-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseWriter.java
More file actions
38 lines (30 loc) · 897 Bytes
/
DatabaseWriter.java
File metadata and controls
38 lines (30 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package darun.csvloader;
import java.util.ArrayList;
public class DatabaseWriter implements JobExecutor{
private ArrayList<Job> jobList = new ArrayList<Job>();
private int jobCapacity = 0;
DatabaseWriter(int jobCapacity){
this.jobCapacity = jobCapacity;
}
public void execute(){
Thread t = new Thread(this);
t.start();
}
public void run() {
DatabaseSession session = new DatabaseSession();
session.prepareStatement("INSERT INTO SDH_XC VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);");
for(Job job : jobList){
String[] values = (String[]) job.getJobDefn();
session.addBatch(values);
}
session.executeBatch();
session.close();
}
public boolean addJob(Job job) {
if(jobList.size() < jobCapacity){
jobList.add(job);
return true;
}
return false;
}
}