Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
d99ede5d
Commit
d99ede5d
authored
Jun 26, 2025
by
Riegel
Browse files
Fix: Determining target class for deserialization
parent
adb25c45
Changes
1
Show whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/database/DatabaseHandler.java
View file @
d99ede5d
...
@@ -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
()).
toWkt
Shadow
();
String
bbox
=
BoundingBox
.
of
(
co
.
getHighestLodGeometry
().
getPolygons
()).
to
2D
Wkt
();
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
().
get
Simple
Name
());
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
();
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment