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
2e14765f
Commit
2e14765f
authored
Dec 18, 2025
by
Luna Riegel
Browse files
Feature: Implement DB configuration handling
parent
0423dc6a
Changes
3
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/database/EmbeddedDatabaseConfiguration.java
View file @
2e14765f
...
...
@@ -20,8 +20,9 @@ import java.io.File;
public
record
EmbeddedDatabaseConfiguration
(
String
databaseName
,
String
databaseDirectory
,
int
connectionPoolSize
,
boolean
inMemoryMode
,
boolean
attemptFallback
,
boolean
debugMode
,
boolean
tempFileMode
)
{
private
static
final
String
IN_MEMORY_PREFIX
=
"
jdbc:h2:
mem"
;
private
static
final
String
IN_MEMORY_PREFIX
=
"mem
:
"
;
private
static
final
String
AUTO_SERVER_PARAMETER
=
";AUTO_SERVER=TRUE"
;
private
static
final
String
FILE_PREFIX
=
"file://"
;
/**
* Instantiates the default configuration for the embedded database.
*/
...
...
@@ -40,7 +41,7 @@ public record EmbeddedDatabaseConfiguration(String databaseName, String database
}
public
String
getH2FileUrl
(){
return
databaseDirectory
+
databaseName
;
return
FILE_PREFIX
+
databaseDirectory
+
databaseName
;
}
public
String
getH2ParametersSuffix
(){
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/database/EmbeddedDatabaseHandler.java
View file @
2e14765f
...
...
@@ -19,9 +19,12 @@ import org.h2gis.utilities.wrapper.DataSourceWrapper;
import
javax.sql.DataSource
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InvalidClassException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
...
...
@@ -38,12 +41,23 @@ public class EmbeddedDatabaseHandler {
private
static
final
Logger
logger
=
LogManager
.
getLogger
(
EmbeddedDatabaseHandler
.
class
);
private
final
EmbeddedDatabaseConfiguration
config
;
private
DataSourceWrapper
dataSource
;
private
File
tempLoc
=
null
;
public
EmbeddedDatabaseHandler
(
EmbeddedDatabaseConfiguration
dbConfig
){
config
=
dbConfig
;
String
jdbcUrl
;
try
{
jdbcUrl
=
createEmbeddedDataBase
(
config
.
getH2FileUrl
());
if
(
config
.
inMemoryMode
())
{
jdbcUrl
=
createEmbeddedDataBase
(
config
.
getInMemoryH2Url
());
}
else
if
(
config
.
tempFileMode
()){
Path
tmpDir
=
Files
.
createTempDirectory
(
config
.
databaseDirectory
());
tmpDir
.
toFile
().
deleteOnExit
();
String
tempFileUrl
=
tmpDir
.
resolve
(
config
.
databaseName
()).
toFile
().
getAbsolutePath
();
jdbcUrl
=
createEmbeddedDataBase
(
tempFileUrl
);
tempLoc
=
new
File
(
tempFileUrl
);
}
else
{
jdbcUrl
=
createEmbeddedDataBase
(
config
.
getH2FileUrl
());
}
logger
.
debug
(
"1] {}"
,
jdbcUrl
);
}
catch
(
Exception
e
)
{
...
...
@@ -86,6 +100,10 @@ public class EmbeddedDatabaseHandler {
}
}
public
File
getTempLoc
(){
return
this
.
tempLoc
;
}
public
void
setupFeaturesTable
()
{
try
(
Connection
con
=
dataSource
.
getConnection
())
{
...
...
CityDoctorParent/CityDoctorModel/src/test/java/de/hft/stuttgart/citydoctor2/database/EmbeddedDataBaseHandlerTest.java
View file @
2e14765f
...
...
@@ -24,7 +24,10 @@ import java.util.List;
import
static
de
.
hft
.
stuttgart
.
citydoctor2
.
database
.
SerializationTest
.
assertCityObjectEquality
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
public
class
EmbeddedDataBaseHandlerTest
{
...
...
@@ -38,7 +41,26 @@ public class EmbeddedDataBaseHandlerTest {
fail
(
e
.
getMessage
());
}
}
//TODO: FIX Test failures
@Test
public
void
testTempFileConfiguration
(){
EmbeddedDatabaseConfiguration
tempFileconfig
=
new
EmbeddedDatabaseConfiguration
(
"database"
,
"inTempConfig"
,
1
,
false
,
false
,
false
,
true
);
assertNull
(
handler
.
getTempLoc
());
EmbeddedDatabaseHandler
tempHandler
=
new
EmbeddedDatabaseHandler
(
tempFileconfig
);
assertTrue
(
tempHandler
.
getTempLoc
().
exists
());
}
@Test
public
void
testInMemoryConfiguration
(){
EmbeddedDatabaseConfiguration
inMemoryConfig
=
new
EmbeddedDatabaseConfiguration
(
"database"
,
"irrelevant"
,
1
,
true
,
false
,
false
,
false
);
EmbeddedDatabaseHandler
memHandler
=
new
EmbeddedDatabaseHandler
(
inMemoryConfig
);
assertFalse
(
memHandler
.
getTempLoc
().
exists
());
}
@Test
public
void
testGetBboxIntersectingObjects
()
{
...
...
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