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

splitting configurations of webfrontend and backend into separate files

fixed some problems in web application according to database connections
parent 71fb5133
No related branches found
No related tags found
No related merge requests found
...@@ -73,7 +73,7 @@ public final class ConfigIsochrone { ...@@ -73,7 +73,7 @@ public final class ConfigIsochrone {
@NotNull @NotNull
@DefaultValue("") @DefaultValue("")
@PropertyValue("cfg.clientPrefix") @PropertyValue("prefix")
private String prefix; private String prefix;
@NotNull @NotNull
......
...@@ -61,8 +61,8 @@ public class Database { ...@@ -61,8 +61,8 @@ public class Database {
protected final ConfigDataset config; protected final ConfigDataset config;
protected Mode mode; protected Mode mode;
protected boolean isIncoming; protected boolean isIncoming;
protected Connection connection; /** The connection the the database. It is lazy-loaded by {@link #getPstmt(String)} method. */
private Map<String, PreparedStatement> pstmtsCacheMap; private Map<String, PreparedStatement> pstmtsCacheMap;
private Connection connection; /** The connection the the database. It is lazy-loaded by {@link #getPstmt(String)} method. */
// Constructor // Constructor
public Database(final ConfigDataset config, final Mode mode, final Direction direction) { public Database(final ConfigDataset config, final Mode mode, final Direction direction) {
...@@ -633,10 +633,7 @@ public class Database { ...@@ -633,10 +633,7 @@ public class Database {
// FIXME: Find a fix for prepared statements with parameters // FIXME: Find a fix for prepared statements with parameters
// (we should NOT set strings in preparedStatemens just because we want to cache something) // (we should NOT set strings in preparedStatemens just because we want to cache something)
protected PreparedStatement getPstmt(final String query) { protected PreparedStatement getPstmt(final String query) {
if (connection == null) { initConnection();
// lazy-loading of the database connection (so it is not created on object construction)
connection = ConfigIsochrone.getInstance().getConnection();
}
if (pstmtsCacheMap == null) { if (pstmtsCacheMap == null) {
pstmtsCacheMap = new HashMap<String, PreparedStatement>(); pstmtsCacheMap = new HashMap<String, PreparedStatement>();
} }
...@@ -656,6 +653,18 @@ public class Database { ...@@ -656,6 +653,18 @@ public class Database {
return null; return null;
} }
protected void initConnection() {
if (connection == null) {
// lazy-loading of the database connection (so it is not created on object construction)
connection = ConfigIsochrone.getInstance().getConnection();
}
}
protected Connection getConnection() {
initConnection();
return connection;
}
// Private methods // Private methods
private Link createLinkFromResultSet(final int nodeId, final int adjNodeId, final ResultSet rs) throws SQLException { private Link createLinkFromResultSet(final int nodeId, final int adjNodeId, final ResultSet rs) throws SQLException {
...@@ -678,25 +687,7 @@ public class Database { ...@@ -678,25 +687,7 @@ public class Database {
return new Link(linkId, start, end, routeId); return new Link(linkId, start, end, routeId);
} }
// Private static methods // Protected static methods
/**
* Prepares a number of place holders for a prepared statement.
*
* @param length The number of placeholders that is needed
* @return a string with the placeholders plugged in to a statement.
*/
private static String preparePlaceHolders(final int length) {
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; ++i) {
builder.append("?");
if ((i + 1) < length) {
builder.append(",");
}
}
return builder.toString();
}
/** /**
* Sets the values in the placeholders in a prepared statement, generated by * Sets the values in the placeholders in a prepared statement, generated by
...@@ -717,6 +708,26 @@ public class Database { ...@@ -717,6 +708,26 @@ public class Database {
return startIdx + values.length; return startIdx + values.length;
} }
// Private static methods
/**
* Prepares a number of place holders for a prepared statement.
*
* @param length The number of placeholders that is needed
* @return a string with the placeholders plugged in to a statement.
*/
private static String preparePlaceHolders(final int length) {
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; ++i) {
builder.append("?");
if ((i + 1) < length) {
builder.append(",");
}
}
return builder.toString();
}
/** /**
* Adds a node to the network. * Adds a node to the network.
* *
......
package it.unibz.inf.isoga.config; package it.unibz.inf.isoga.config;
import com.tngtech.configbuilder.ConfigBuilder;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertiesFiles;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyExtension;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLocations;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertySuffixes;
import com.tngtech.configbuilder.annotation.valueextractor.DefaultValue;
import com.tngtech.configbuilder.annotation.valueextractor.PropertyValue;
import it.geosolutions.geoserver.rest.GeoServerRESTManager; import it.geosolutions.geoserver.rest.GeoServerRESTManager;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.GeoServerRESTReader; import it.geosolutions.geoserver.rest.GeoServerRESTReader;
...@@ -13,19 +21,11 @@ import javax.validation.constraints.NotNull; ...@@ -13,19 +21,11 @@ import javax.validation.constraints.NotNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.tngtech.configbuilder.ConfigBuilder;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertiesFiles;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyExtension;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertyLocations;
import com.tngtech.configbuilder.annotation.propertyloaderconfiguration.PropertySuffixes;
import com.tngtech.configbuilder.annotation.valueextractor.DefaultValue;
import com.tngtech.configbuilder.annotation.valueextractor.PropertyValue;
/** /**
* @author Nikolaus Krismer * @author Nikolaus Krismer
* @version 3 * @version 3
*/ */
@PropertiesFiles({ "config", "config-test" }) @PropertiesFiles({ "configWeb", "configWeb-test" })
@PropertyLocations(fromClassLoader = true) @PropertyLocations(fromClassLoader = true)
@PropertyExtension("xml") @PropertyExtension("xml")
@PropertySuffixes(extraSuffixes = { }, hostNames = false) @PropertySuffixes(extraSuffixes = { }, hostNames = false)
......
...@@ -90,6 +90,7 @@ public class DatabaseWeb extends Database { ...@@ -90,6 +90,7 @@ public class DatabaseWeb extends Database {
// Public methods // Public methods
public void createBuffer(final String bufferTable, final String edgeTable, final double bufferSize) { public void createBuffer(final String bufferTable, final String edgeTable, final double bufferSize) {
final Connection connection = getConnection();
final StringBuilder b = new StringBuilder("INSERT INTO ").append(bufferTable); final StringBuilder b = new StringBuilder("INSERT INTO ").append(bufferTable);
b.append(" SELECT 1,ST_Multi(ST_UNION(ST_BUFFER(\"GEOMETRY\", ").append(bufferSize).append("))) \"GEOMETRY\" FROM ").append(edgeTable); b.append(" SELECT 1,ST_Multi(ST_UNION(ST_BUFFER(\"GEOMETRY\", ").append(bufferSize).append("))) \"GEOMETRY\" FROM ").append(edgeTable);
...@@ -136,8 +137,9 @@ public class DatabaseWeb extends Database { ...@@ -136,8 +137,9 @@ public class DatabaseWeb extends Database {
return edges; return edges;
} }
@Override
public Connection getConnection() { public Connection getConnection() {
return connection; return super.getConnection();
} }
@SuppressFBWarnings( @SuppressFBWarnings(
...@@ -313,12 +315,13 @@ public class DatabaseWeb extends Database { ...@@ -313,12 +315,13 @@ public class DatabaseWeb extends Database {
*/ */
public void storeArea(final int areaId, final List<Point> points, final double bufferSize) { public void storeArea(final int areaId, final List<Point> points, final double bufferSize) {
final Connection connection = getConnection();
final Geometry geometry = PgHelper.asPgGeometry(points); final Geometry geometry = PgHelper.asPgGeometry(points);
final String geometryString = geometry.getTypeString() + geometry.getValue(); final String geometryString = geometry.getTypeString() + geometry.getValue();
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
b.append("INSERT INTO ").append(config.getAreaBufferTableEntry().getTableName()); b.append("INSERT INTO ").append(config.getAreaBufferTableEntry().getTableName());
b.append("(\"ID\",\"GEOMETRY\") VALUES(?,ST_MULTI(ST_Buffer(ST_MakeValid(ST_GeomFromText(?," + config.getServerSRID() + ")),?,'endcap=round join=round')))"); b.append("(\"ID\",\"GEOMETRY\") VALUES(?,ST_MULTI(ST_Buffer(ST_MakeValid(ST_GeomFromText(?," + config.getServerSRID() + ")),?,'endcap=round join=round')))");
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
statement = getPstmt(b.toString()); statement = getPstmt(b.toString());
...@@ -337,7 +340,9 @@ public class DatabaseWeb extends Database { ...@@ -337,7 +340,9 @@ public class DatabaseWeb extends Database {
} }
public final void storeLinks(final Collection<Link> links, final Direction direction) { public final void storeLinks(final Collection<Link> links, final Direction direction) {
final Connection connection = getConnection();
final boolean isIncoming = direction == Direction.INCOMING; final boolean isIncoming = direction == Direction.INCOMING;
PreparedStatement statementPartial = null; PreparedStatement statementPartial = null;
PreparedStatement statementFull = null; PreparedStatement statementFull = null;
try { try {
...@@ -388,6 +393,7 @@ public class DatabaseWeb extends Database { ...@@ -388,6 +393,7 @@ public class DatabaseWeb extends Database {
} }
public void storeVertices(final Set<Node> nodes) { public void storeVertices(final Set<Node> nodes) {
final Connection connection = getConnection();
PreparedStatement insertVerticesStatement = null; PreparedStatement insertVerticesStatement = null;
PreparedStatement insertVertexAnnotationStatement = null; PreparedStatement insertVertexAnnotationStatement = null;
...@@ -427,11 +433,14 @@ public class DatabaseWeb extends Database { ...@@ -427,11 +433,14 @@ public class DatabaseWeb extends Database {
} }
public Point transform(final Point p) { public Point transform(final Point p) {
final Connection connection = getConnection();
final String query = "SELECT ST_X(P.GEO) X, ST_Y(P.GEO) Y FROM (SELECT ST_Transform(ST_PointFromText(?,?),?) GEO ) P"; final String query = "SELECT ST_X(P.GEO) X, ST_Y(P.GEO) Y FROM (SELECT ST_Transform(ST_PointFromText(?,?),?) GEO ) P";
return DatabaseWeb.transform(connection, config, p, getPstmt(query)); return DatabaseWeb.transform(connection, config, p, getPstmt(query));
} }
public void updateVertexTable() { public void updateVertexTable() {
final Connection connection = getConnection();
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
statement = getPstmt(queryUpdateVertices); statement = getPstmt(queryUpdateVertices);
......
...@@ -61,10 +61,9 @@ public class ServiceIsochrone extends AbstractService<RequestIsochrone, Response ...@@ -61,10 +61,9 @@ public class ServiceIsochrone extends AbstractService<RequestIsochrone, Response
if (!config.isRegistered()) { if (!config.isRegistered()) {
registerTableAndLayers(db.getConnection(), config); registerTableAndLayers(db.getConnection(), config);
} }
// Timing start
truncateTables(db.getConnection(), config); truncateTables(db.getConnection(), config);
// create query and calculate isochrone
final Query query = new Query(direction, request.getSpeed(), request.getDmax(), request.getDate(), true, request.getMode()); final Query query = new Query(direction, request.getSpeed(), request.getDmax(), request.getDate(), true, request.getMode());
query.setStartLocations(locationsFromQueryNodes(request.getQueryNodes(), db)); query.setStartLocations(locationsFromQueryNodes(request.getQueryNodes(), db));
final Isochrone isochrone = getAlgorithm(request.getAlgorithm(), config, db, query); final Isochrone isochrone = getAlgorithm(request.getAlgorithm(), config, db, query);
...@@ -83,11 +82,12 @@ public class ServiceIsochrone extends AbstractService<RequestIsochrone, Response ...@@ -83,11 +82,12 @@ public class ServiceIsochrone extends AbstractService<RequestIsochrone, Response
} }
} }
db.close();
final ResponseIsochrone response = new ResponseIsochrone(); final ResponseIsochrone response = new ResponseIsochrone();
response.setBoundingBox(output.getBoundingBox()); response.setBoundingBox(output.getBoundingBox());
// now that bbox is calculated, we can close the database connection
db.close();
final long currentTime = System.currentTimeMillis(); final long currentTime = System.currentTimeMillis();
final long totalRequestTime = currentTime - startRequestTiming; final long totalRequestTime = currentTime - startRequestTiming;
final long timeCoveraging = (startComputationTiming <= 0) ? 0 : currentTime - startCoverageTiming; final long timeCoveraging = (startComputationTiming <= 0) ? 0 : currentTime - startCoverageTiming;
......
...@@ -12,14 +12,6 @@ ...@@ -12,14 +12,6 @@
<entry key="org.postgresql.password">secretPhdPassword#2014!</entry> <entry key="org.postgresql.password">secretPhdPassword#2014!</entry>
<entry key="org.postgresql.port">5432</entry> <entry key="org.postgresql.port">5432</entry>
<!-- Rendering engine properties --> <!-- Postgres/Geoserver prefix -->
<entry key="rendering.server.rest.url">http://localhost:8080/geoserver</entry> <entry key="tablePrefix"></entry>
<entry key="rendering.server.rest.username">admin</entry>
<entry key="rendering.server.rest.password">geoserver</entry>
<entry key="rendering.server.rest.workspace">isochrone</entry>
<entry key="rendering.server.rest.datastore">sessions</entry>
<!-- Configuration parameters -->
<entry key="cfg.clientSRID">3857</entry>
<entry key="cfg.clientPrefix"></entry>
</properties> </properties>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<!-- Rendering engine properties -->
<entry key="rendering.server.rest.url">http://localhost:8080/geoserver</entry>
<entry key="rendering.server.rest.username">admin</entry>
<entry key="rendering.server.rest.password">geoserver</entry>
<entry key="rendering.server.rest.workspace">isochrone</entry>
<entry key="rendering.server.rest.datastore">sessions</entry>
<!-- Configuration parameters -->
<entry key="cfg.clientSRID">3857</entry>
</properties>
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
<!-- Postgres database --> <!-- Postgres database -->
<entry key="org.postgresql.servername">dbis-isochrone.uibk.ac.at</entry> <entry key="org.postgresql.servername">dbis-isochrone.uibk.ac.at</entry>
<!-- Geoserver/PostgisLayer prefix --> <!-- Postgres/Geoserver prefix -->
<entry key="cfg.clientPrefix">test</entry> <entry key="prefix">test</entry>
</properties> </properties>
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