Commit d99ede5d authored by Riegel's avatar Riegel
Browse files

Fix: Determining target class for deserialization

parent adb25c45
...@@ -28,6 +28,10 @@ public class DatabaseHandler { ...@@ -28,6 +28,10 @@ public class DatabaseHandler {
private static final String DB_NAME = "cd_db"; private static final String DB_NAME = "cd_db";
private DatabaseHandler() {
}
/** /**
* Sets up a new, empty embedded database. Will override an existing embedded database. * Sets up a new, empty embedded database. Will override an existing embedded database.
*/ */
...@@ -39,6 +43,7 @@ public class DatabaseHandler { ...@@ -39,6 +43,7 @@ public class DatabaseHandler {
} catch (Exception e) { } catch (Exception e) {
logger.fatal("FATAL ERROR: Creation of embedded database failed!"); logger.fatal("FATAL ERROR: Creation of embedded database failed!");
logger.fatal(e.getMessage()); logger.fatal(e.getMessage());
// TODO: implement popup and shutdown
} }
...@@ -70,12 +75,12 @@ public class DatabaseHandler { ...@@ -70,12 +75,12 @@ public class DatabaseHandler {
try (Connection con = new ConnectionWrapper(H2GISDBFactory.openSpatialDataBase(DB_NAME))) { try (Connection con = new ConnectionWrapper(H2GISDBFactory.openSpatialDataBase(DB_NAME))) {
try (PreparedStatement ps = con.prepareStatement("MERGE INTO features VALUES (?, ?, ?, ?)")) { try (PreparedStatement ps = con.prepareStatement("MERGE INTO features VALUES (?, ?, ?, ?)")) {
ps.setString(1, co.getGmlId().toString()); ps.setString(1, co.getGmlId().toString());
String bbox = BoundingBox.of(co.getHighestLodGeometry().getPolygons()).toWktShadow(); String bbox = BoundingBox.of(co.getHighestLodGeometry().getPolygons()).to2DWkt();
ps.setString(2, bbox); ps.setString(2, bbox);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Attempting to serialize city object {} ", co); logger.debug("Attempting to serialize city object {} ", co);
} }
ps.setString(4, co.getClass().getSimpleName()); ps.setString(4, co.getClass().getName());
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (ObjectOutputStream out = new ObjectOutputStream(bos)) { try (ObjectOutputStream out = new ObjectOutputStream(bos)) {
out.writeObject(co); out.writeObject(co);
...@@ -201,6 +206,7 @@ public class DatabaseHandler { ...@@ -201,6 +206,7 @@ public class DatabaseHandler {
private static CityObject deserializeCityObject(ObjectInputStream ois, String className) throws IOException, ClassNotFoundException { private static CityObject deserializeCityObject(ObjectInputStream ois, String className) throws IOException, ClassNotFoundException {
Class<?> type = Class.forName(className); Class<?> type = Class.forName(className);
return (CityObject) type.cast(ois.readObject()); CityObject castCo = (CityObject) type.cast(ois.readObject());
return castCo.getTopLevelCityObject();
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment