git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngine@84935 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
607cb8a086
commit
b87996cb5e
|
@ -165,6 +165,37 @@ public class DatabaseUtils {
|
|||
return "insert into " + table + " (" + columnsNames + ") values " + values;
|
||||
}
|
||||
|
||||
public static void insertChunksIntoTable(String table, String columnsNames, List<String[]> values, int chunkSize,SessionFactory dbconnection) throws Exception{
|
||||
|
||||
int valuesize = values.size();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int stopIndex =0;
|
||||
for (int i=0;i<valuesize;i++){
|
||||
String[] row = values.get(i);
|
||||
sb.append("(");
|
||||
for (int j=0;j<row.length;j++){
|
||||
sb.append("'"+row[j]+"'");
|
||||
if (j<row.length-1)
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(")");
|
||||
if (stopIndex%chunkSize==0){
|
||||
DatabaseFactory.executeSQLUpdate(insertFromBuffer(table, columnsNames, sb), dbconnection);
|
||||
stopIndex=chunkSize;
|
||||
sb = new StringBuffer();
|
||||
}
|
||||
else if (i<valuesize-1)
|
||||
sb.append(",");
|
||||
}
|
||||
|
||||
if (stopIndex<valuesize-1){
|
||||
List<String[]> sublist = values.subList(stopIndex+1, valuesize);
|
||||
insertChunksIntoTable(table, columnsNames, sublist, chunkSize,dbconnection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String insertFromString(String table, String columnsNames, String values) {
|
||||
|
||||
return "insert into " + table + " (" + columnsNames + ") values " + values;
|
||||
|
|
Loading…
Reference in New Issue