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
3c2d02e8
Commit
3c2d02e8
authored
Jan 26, 2026
by
Luna Riegel
Browse files
Fix: Fix batch-unmarshalling
parent
d9d18caa
Changes
4
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/database/DatabaseCacheLoader.java
0 → 100644
View file @
3c2d02e8
package
de.hft.stuttgart.citydoctor2.database
;
import
com.github.benmanes.caffeine.cache.CacheLoader
;
import
de.hft.stuttgart.citydoctor2.exceptions.EmbeddedDatabaseHandlerException
;
import
org.jspecify.annotations.NonNull
;
import
java.util.Map
;
import
java.util.Set
;
public
class
DatabaseCacheLoader
<
K
,
V
>
implements
CacheLoader
<
K
,
V
>
{
private
final
Unmarshaller
<
K
,
V
>
unmarshaller
;
private
final
BatchUnmarshaller
<
K
,
V
>
batchUnmarshaller
;
public
DatabaseCacheLoader
(
Unmarshaller
<
K
,
V
>
unmarshaller
,
BatchUnmarshaller
<
K
,
V
>
batchUnmarshaller
){
this
.
unmarshaller
=
unmarshaller
;
this
.
batchUnmarshaller
=
batchUnmarshaller
;
}
@Override
public
@NonNull
V
load
(
@NonNull
K
key
)
throws
EmbeddedDatabaseHandlerException
{
return
unmarshaller
.
unmarshall
(
key
);
}
@Override
@NonNull
public
Map
<
K
,
V
>
loadAll
(
@NonNull
Set
<?
extends
K
>
keys
)
throws
EmbeddedDatabaseHandlerException
{
return
batchUnmarshaller
.
unmarshall
(
keys
);
}
public
interface
Unmarshaller
<
K
,
V
>
{
V
unmarshall
(
K
key
)
throws
EmbeddedDatabaseHandlerException
;
}
public
interface
BatchUnmarshaller
<
K
,
V
>
{
Map
<
K
,
V
>
unmarshall
(
Set
<?
extends
K
>
keys
)
throws
EmbeddedDatabaseHandlerException
;
}
}
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/database/EmbeddedDatabaseHandler.java
View file @
3c2d02e8
...
@@ -24,6 +24,7 @@ import java.io.InputStream;
...
@@ -24,6 +24,7 @@ import java.io.InputStream;
import
java.io.InvalidClassException
;
import
java.io.InvalidClassException
;
import
java.nio.file.Files
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.sql.Array
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
...
@@ -33,6 +34,7 @@ import java.util.ArrayList;
...
@@ -33,6 +34,7 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.Set
;
/**
/**
...
@@ -259,7 +261,9 @@ public class EmbeddedDatabaseHandler {
...
@@ -259,7 +261,9 @@ public class EmbeddedDatabaseHandler {
try
(
Connection
con
=
dataSource
.
getConnection
())
{
try
(
Connection
con
=
dataSource
.
getConnection
())
{
try
(
PreparedStatement
ps
=
con
.
prepareStatement
(
try
(
PreparedStatement
ps
=
con
.
prepareStatement
(
"SELECT data FROM features WHERE ARRAY_CONTAINS(? ,gmlid)"
))
{
"SELECT data FROM features WHERE ARRAY_CONTAINS(? ,gmlid)"
))
{
ps
.
setObject
(
1
,
ids
);
String
[]
idStrings
=
ids
.
stream
().
map
(
Objects:
:
toString
).
toArray
(
String
[]::
new
);
Array
array
=
con
.
createArrayOf
(
"VARCHAR(255)"
,
idStrings
);
ps
.
setArray
(
1
,
array
);
ResultSet
rs
=
ps
.
executeQuery
();
ResultSet
rs
=
ps
.
executeQuery
();
Map
<
GmlId
,
CityObject
>
objects
=
new
HashMap
<>();
Map
<
GmlId
,
CityObject
>
objects
=
new
HashMap
<>();
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/database/FeatureCache.java
View file @
3c2d02e8
...
@@ -8,9 +8,9 @@ import de.hft.stuttgart.citydoctor2.datastructure.GmlId;
...
@@ -8,9 +8,9 @@ import de.hft.stuttgart.citydoctor2.datastructure.GmlId;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
...
@@ -49,11 +49,13 @@ public class FeatureCache implements CityObjectCache{
...
@@ -49,11 +49,13 @@ public class FeatureCache implements CityObjectCache{
public
FeatureCache
(
EmbeddedDatabaseConfiguration
dbConfig
){
public
FeatureCache
(
EmbeddedDatabaseConfiguration
dbConfig
){
handler
=
new
EmbeddedDatabaseHandler
(
dbConfig
);
handler
=
new
EmbeddedDatabaseHandler
(
dbConfig
);
DatabaseCacheLoader
.
Unmarshaller
<
GmlId
,
CityObject
>
single
=
handler:
:
unmarshallCityObject
;
DatabaseCacheLoader
.
BatchUnmarshaller
<
GmlId
,
CityObject
>
batch
=
handler:
:
unmarshallAllIds
;
cache
=
Caffeine
.
newBuilder
().
maximumSize
(
3000
).
removalListener
((
GmlId
key
,
CityObject
value
,
RemovalCause
cause
)
->
{
cache
=
Caffeine
.
newBuilder
().
maximumSize
(
3000
).
removalListener
((
GmlId
key
,
CityObject
value
,
RemovalCause
cause
)
->
{
if
(
value
!=
null
&&
cause
.
wasEvicted
()
&&
isFeatureMarshallable
(
value
)){
if
(
value
!=
null
&&
cause
.
wasEvicted
()
&&
isFeatureMarshallable
(
value
)){
handler
.
marshallCityObject
(
value
);
handler
.
marshallCityObject
(
value
);
}
}
}).
build
(
handler:
:
unmarshallCityObject
);
}).
build
(
new
DatabaseCacheLoader
<>(
single
,
batch
)
);
}
}
/**
/**
...
@@ -119,7 +121,7 @@ public class FeatureCache implements CityObjectCache{
...
@@ -119,7 +121,7 @@ public class FeatureCache implements CityObjectCache{
@Override
@Override
public
Collection
<
CityObject
>
getAll
(
List
<
GmlId
>
ids
){
public
Collection
<
CityObject
>
getAll
(
List
<
GmlId
>
ids
){
Map
<
GmlId
,
CityObject
>
map
=
cache
.
getAll
(
ids
,
handler:
:
unmarshallAllI
ds
);
Map
<
GmlId
,
CityObject
>
map
=
cache
.
getAll
(
new
HashSet
<>(
i
ds
)
)
;
return
map
.
values
();
return
map
.
values
();
}
}
...
...
CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/checks/util/CollectionUtils.java
View file @
3c2d02e8
...
@@ -20,7 +20,9 @@ package de.hft.stuttgart.citydoctor2.checks.util;
...
@@ -20,7 +20,9 @@ package de.hft.stuttgart.citydoctor2.checks.util;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.stream.IntStream
;
public
class
CollectionUtils
{
public
class
CollectionUtils
{
...
@@ -40,4 +42,11 @@ public class CollectionUtils {
...
@@ -40,4 +42,11 @@ public class CollectionUtils {
return
set
;
return
set
;
}
}
public
static
<
T
>
List
<
List
<
T
>>
partition
(
List
<
T
>
list
,
int
chunkSize
){
return
IntStream
.
iterate
(
0
,
i
->
i
<
list
.
size
(),
i
->
i
+
chunkSize
)
.
mapToObj
(
i
->
list
.
subList
(
i
,
Math
.
min
(
i
+
chunkSize
,
list
.
size
())))
.
toList
();
}
}
}
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