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
fcc98bad
Commit
fcc98bad
authored
Jul 24, 2025
by
Luna Riegel
Browse files
Refactor: Move method to Cache class
parent
786171a6
Pipeline
#11752
failed with stage
in 1 minute and 7 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/database/CityObjectCache.java
View file @
fcc98bad
...
@@ -2,7 +2,9 @@ package de.hft.stuttgart.citydoctor2.database;
...
@@ -2,7 +2,9 @@ package de.hft.stuttgart.citydoctor2.database;
import
de.hft.stuttgart.citydoctor2.datastructure.CityObject
;
import
de.hft.stuttgart.citydoctor2.datastructure.CityObject
;
import
de.hft.stuttgart.citydoctor2.datastructure.GmlId
;
import
de.hft.stuttgart.citydoctor2.datastructure.GmlId
;
import
de.hft.stuttgart.citydoctor2.utils.Pair
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.lang.ref.SoftReference
;
import
java.lang.ref.SoftReference
;
...
@@ -40,6 +42,17 @@ public class CityObjectCache {
...
@@ -40,6 +42,17 @@ public class CityObjectCache {
return
cityObject
;
return
cityObject
;
}
}
public
static
List
<
Pair
<
GmlId
,
List
<
GmlId
>>>
getCollidingObjectsList
()
{
List
<
Pair
<
GmlId
,
List
<
GmlId
>>>
collidingObjects
=
new
ArrayList
<>();
for
(
GmlId
id
:
DatabaseHandler
.
getAllGmlIds
())
{
List
<
GmlId
>
collidingIds
=
DatabaseHandler
.
getBBoxIntersectingObjects
(
id
);
if
(
collidingIds
!=
null
&&
!
collidingIds
.
isEmpty
())
{
collidingObjects
.
add
(
new
Pair
<>(
id
,
collidingIds
));
}
}
return
collidingObjects
;
}
public
void
remove
(
GmlId
id
)
{
public
void
remove
(
GmlId
id
)
{
cache
.
remove
(
id
);
cache
.
remove
(
id
);
}
}
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/database/DatabaseHandler.java
View file @
fcc98bad
...
@@ -125,6 +125,22 @@ public class DatabaseHandler {
...
@@ -125,6 +125,22 @@ public class DatabaseHandler {
return
cos
;
return
cos
;
}
}
public
static
List
<
GmlId
>
getAllGmlIds
()
{
List
<
GmlId
>
cos
=
new
ArrayList
<>();
try
(
Connection
con
=
new
ConnectionWrapper
(
H2GISDBFactory
.
openSpatialDataBase
(
DB_NAME
)))
{
try
(
PreparedStatement
ps
=
con
.
prepareStatement
(
"SELECT gmlid FROM features"
))
{
ResultSet
rs
=
ps
.
executeQuery
();
while
(
rs
.
next
())
{
cos
.
add
(
new
GmlId
(
rs
.
getString
(
"gmlid"
)));
}
}
}
catch
(
SQLException
e
)
{
logger
.
error
(
"Connection to database failed while trying to get all CityObjects!"
);
logger
.
debug
(
e
.
getMessage
());
}
return
cos
;
}
public
static
List
<
CityObject
>
getBufferIntersectingObjects
(
CityObject
co
,
double
bufferSize
)
{
public
static
List
<
CityObject
>
getBufferIntersectingObjects
(
CityObject
co
,
double
bufferSize
)
{
List
<
CityObject
>
intersectingObjects
=
new
ArrayList
<>();
List
<
CityObject
>
intersectingObjects
=
new
ArrayList
<>();
try
(
Connection
con
=
new
ConnectionWrapper
(
H2GISDBFactory
.
openSpatialDataBase
(
DB_NAME
)))
{
try
(
Connection
con
=
new
ConnectionWrapper
(
H2GISDBFactory
.
openSpatialDataBase
(
DB_NAME
)))
{
...
@@ -161,11 +177,26 @@ public class DatabaseHandler {
...
@@ -161,11 +177,26 @@ public class DatabaseHandler {
return
intersectingObjects
;
return
intersectingObjects
;
}
}
public
static
List
<
Pair
<
CityObject
,
List
<
CityObject
>>>
getCollidingObjects
()
{
public
static
List
<
GmlId
>
getBBoxIntersectingObjects
(
GmlId
id
)
{
List
<
Pair
<
CityObject
,
List
<
CityObject
>>>
collidingObjects
=
new
ArrayList
<>();
List
<
GmlId
>
intersectingObjects
=
new
ArrayList
<>();
// TODO: Implement query to return all Objects that have a collision and the list of whhich other objects collide
return
collidingObjects
;
try
(
Connection
con
=
new
ConnectionWrapper
(
H2GISDBFactory
.
openSpatialDataBase
(
DB_NAME
)))
{
try
(
PreparedStatement
ps
=
con
.
prepareStatement
(
"SELECT gmlid FROM features AS tab1"
+
" WHERE ST_INTERSECTS(tab1.bbox, (SELECT bbox FROM features WHERE gmlid = ?)) AND tab1.gmlid <> ?"
))
{
ps
.
setString
(
1
,
id
.
toString
());
ps
.
setString
(
2
,
id
.
toString
());
ResultSet
rs
=
ps
.
executeQuery
();
while
(
rs
.
next
())
{
intersectingObjects
.
add
(
new
GmlId
(
rs
.
getString
(
"gmlid"
)));
}
}
}
}
catch
(
SQLException
e
)
{
logger
.
error
(
"Connection to database failed while trying to get bbox intersecting objects!"
);
logger
.
debug
(
e
.
getMessage
());
}
return
intersectingObjects
;
}
public
static
int
getFeatureCount
()
{
public
static
int
getFeatureCount
()
{
int
count
=
-
1
;
int
count
=
-
1
;
...
...
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