Java Reference
In-Depth Information
import org.springframework.jdbc.core.JdbcTemplate;
public class ColumnRangePartitioner extends JdbcTemplate implements Partitioner {
private String column;
private String table;
private int gridSize;
public Map<String, ExecutionContext> partition(int arg0) {
int min = queryForInt("SELECT MIN(" + column + ") from "
+ table);
int max = queryForInt("SELECT MAX(" + column + ") from "
+ table);
int targetSize = (max - min) / gridSize;
Map<String, ExecutionContext> result = new HashMap<String, ExecutionContext>();
int number = 0;
int start = min;
int end = start + targetSize - 1;
while (start <= max) {
ExecutionContext value = new ExecutionContext();
result.put("partition" + number, value);
if (end >= max) {
end = max;
}
value.putInt("minValue", start);
value.putInt("maxValue", end);
start += targetSize;
end += targetSize;
number++;
}
return result;
}
public void setColumn(String column) {
this.column = column;
}
public void setTable(String table) {
this.table = table;
}
public void setGridSize(int gridSize) {
this.gridSize = gridSize;
}
}
Search WWH ::




Custom Search