Skip to content
Snippets Groups Projects
Commit 2dc9aead authored by Nikolaus Krismer's avatar Nikolaus Krismer
Browse files

aspect oriented changes in output interface (added

after/beforeCalculation methods)
parent 9e2e6e49
No related branches found
No related tags found
No related merge requests found
......@@ -128,6 +128,8 @@ public abstract class Isochrone {
* @return the computed output (stored in the output given by the parameter)
*/
public <T extends Output> T compute(final T output) {
output.beforeCalculation();
if (!query.getNodes().isEmpty()) {
exploreInitialNodes(query.getNodes());
} else {
......@@ -159,6 +161,7 @@ public abstract class Isochrone {
output.addNode(n);
}
output.afterCalculation();
return output;
}
......
......@@ -41,4 +41,15 @@ public class MemoryOutput implements Output {
public void addNode(final Node node) {
nodes.add(node);
}
@Override
public void afterCalculation() {
// No post-processing of calculated isochrone
}
@Override
public void beforeCalculation() {
// No pre-processing of calculated isochrone
}
}
......@@ -19,4 +19,16 @@ public interface Output {
*/
void addNode(Node node);
/**
* This is called after all links and nodes are stored in this output.
* Can be useful to save results in the database (or similar)
*/
void afterCalculation();
/**
* This is called before links and/or nodes are stored in this output.
* Can be useful to set up some datatypes (clear maps, ...).
*/
void beforeCalculation();
}
......@@ -20,20 +20,24 @@ import org.apache.commons.dbutils.DbUtils;
* An output which stores links and vertices to the database for calculating the bounding box.
*/
public class BBoxOutput extends MemoryOutput {
private BBox boundingBox;
private boolean isSavedInDatabase;
private final DatabaseWeb db;
private final Direction direction;
private final String query;
private final int serverSRID;
private BBox boundingBox;
private boolean isSavedInDatabase;
// Constructors
public BBoxOutput(final ConfigDataset config) {
public BBoxOutput(final ConfigDataset config, final DatabaseWeb db, final Direction direction) {
super();
final String cfgEdgeTable = config.getEdgeTableEntry().getTableName();
this.db = db;
this.direction = direction;
serverSRID = config.getServerSRID();
isSavedInDatabase = false;
final String cfgEdgeTable = config.getEdgeTableEntry().getTableName();
query = "SELECT ST_XMin(mbr.geo) min_x, ST_yMin(mbr.geo) min_y, ST_XMax(mbr.geo) max_x, ST_yMax(mbr.geo) max_y FROM "
+ "(SELECT st_transform(ST_SetSRID(st_extent(\"GEOMETRY\"),?),?) GEO FROM " + cfgEdgeTable + ") MBR";
}
......@@ -56,6 +60,15 @@ public class BBoxOutput extends MemoryOutput {
super.addNode(node);
}
@Override
public void afterCalculation() {
db.storeLinks(getLinks().values(), direction);
db.storeVertices(getNodes());
db.updateVertexTable();
isSavedInDatabase = true;
}
public BBox getBoundingBox() {
if (!isSavedInDatabase) {
throw new IllegalStateException("Can not calculate bounding box, since results have not been saved to database");
......@@ -67,6 +80,8 @@ public class BBoxOutput extends MemoryOutput {
return boundingBox;
}
// Private methods
private void calculateBoundingBox() {
final ConfigIsochrone configIso = ConfigIsochrone.getInstance();
final Connection connection = configIso.getConnection();
......@@ -93,12 +108,4 @@ public class BBoxOutput extends MemoryOutput {
DbUtils.closeQuietly(statement);
}
}
public void saveInDatabase(final DatabaseWeb db, final Direction direction) {
db.storeLinks(getLinks().values(), direction);
db.storeVertices(getNodes());
db.updateVertexTable();
isSavedInDatabase = true;
}
}
......@@ -56,7 +56,7 @@ public class ServiceIsochrone extends AbstractService<RequestIsochrone, Response
final ConfigClient config = ConfigClient.getInstance(clientId, dataset);
// register layers which have not been preregistered in ServiceConfiguration class
// register layers which have not been pre-registered in ServiceConfiguration class
if (!config.isRegistered()) {
registerTableAndLayers(ConfigIsochrone.getInstance().getConnection(), config);
}
......@@ -68,10 +68,8 @@ public class ServiceIsochrone extends AbstractService<RequestIsochrone, Response
truncateTables(config);
final Query query = new Query(direction, request.getSpeed(), request.getDmax(), request.getDate(), true, request.getMode());
query.setLocations(locationsFromQueryNodes(request.getQueryNodes(), db));
final Isochrone isochrone = getAlgorithm(request.getAlgorithm(), config, query);
final BBoxOutput output = isochrone.compute(new BBoxOutput(config));
output.saveInDatabase(db, direction);
final BBoxOutput output = isochrone.compute(new BBoxOutput(config, db, direction));
final long timeIsochrone = System.currentTimeMillis() - startComputationTiming;
long startCoverageTiming = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment