Skip to content

Commit

Permalink
Merge pull request #38 from svencc/feature/add-h2-db
Browse files Browse the repository at this point in the history
Feature/add h2 db
  • Loading branch information
svencc authored Mar 13, 2024
2 parents d6e8a9f + e2a8c72 commit 8d5055e
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 17 deletions.
21 changes: 19 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
# TODO LIST

# 1
* add authentication failed message to CLIENT!!!!!!!!
* make stepSize Integer!!!!!!!! (client + server)

* topography:
* map has to be stored in chunks
* if enough data are send, a chunk is stored in db
* client asks always for next chunk before it is created.
* chunk size 1000x1000

* dbcache forest and structure provider!!!
* call to load/prepare caches for specific map

* make step size an int (minimum 1 meter); so no float and rounding will be used anymore in code > in client as well
* move mysql -> integrated h2
*


* dbBache layers (input configuration parameters)
* Merge Layer Transparency
* add transparency of forest and structure merging
* add transparency of merging layers to configuration!

* /api/v1/configuration/map-tools/resources/forest?mapName= tooks way too long; does it already make use of the resource_name, class_name and prefab_name tables?
* cache forest and/or spatialForestMap > eclipseStore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class LandMapRasterizer implements MapLayerRasterizer {
private MapLayerRasterizerConfiguration mapLayerRasterizerConfiguration = MapLayerRasterizerConfiguration.builder()
.rasterizerName(getClass().getSimpleName())
.layerOrder(LayerOrder.LAND_MAP)
.enabled(false)
.build();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class SlopeMapRasterizer implements MapLayerRasterizer {
private MapLayerRasterizerConfiguration mapLayerRasterizerConfiguration = MapLayerRasterizerConfiguration.builder()
.rasterizerName(getClass().getSimpleName())
.layerOrder(LayerOrder.SLOPE_MAP)
.visible(false)
.enabled(false)
.build();


Expand Down
43 changes: 38 additions & 5 deletions services/recom-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope>
</dependency>
<!-- DATA LAYER / DATABASE -->


Expand Down Expand Up @@ -166,6 +161,44 @@

</dependencies>

<profiles>
<profile>
<id>h2-dev</id>
<properties>
<activated.profile>local</activated.profile>
<env.spring.datasource.url>jdbc:h2:file:C:/Users/Sven/RECOMBackend/recomh2;AUTO_SERVER=TRUE;AUTO_SERVER_PORT=8034;USER=username;PASSWORD=password</env.spring.datasource.url>
<env.spring.datasource.username>username</env.spring.datasource.username>
<env.spring.datasource.password>password</env.spring.datasource.password>
<env.spring.h2.console.enabled>false</env.spring.h2.console.enabled>
</properties>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>mariadb-dev</id>
<properties>
<activated.profile>local</activated.profile>
<env.spring.datasource.url>jdbc:mariadb://127.0.0.1:8033/recom_db</env.spring.datasource.url>
<env.spring.datasource.username>root</env.spring.datasource.username>
<env.spring.datasource.password>recomRootPwd</env.spring.datasource.password>
<env.spring.h2.console.enabled>false</env.spring.h2.console.enabled>
</properties>
<dependencies>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>


<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class Configuration implements Persistable<Long>, Serializable {
private ConfigurationType type;

@Lob
@Column(insertable = true, updatable = true, nullable = false, columnDefinition = "LONGTEXT")
// @Column(insertable = true, updatable = true, nullable = false, columnDefinition = "LONGTEXT") // MARIA DB
@Column(name = "conf_value", insertable = true, updatable = true, nullable = false) // H2 CHARACTER LARGE OBJECT
private String value;

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class DBCachedItem implements Persistable<Long>, Serializable {
private String cacheName;

@Lob
@Column(insertable = true, updatable = true, nullable = false, columnDefinition = "LONGBLOB")
// @Column(insertable = true, updatable = true, nullable = false, columnDefinition = "LONGBLOB") // MARIA DB
@Column(insertable = true, updatable = true, nullable = false) // H2 BINARY LARGE OBJECT
private byte[] cachedValue;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class Message implements Persistable<UUID>, Serializable {

@Id
// @GeneratedValue(strategy = GenerationType.AUTO)
// @GeneratedValue(strategy = GenerationType.AUTO)
@Column(insertable = true, updatable = false, nullable = false)
private UUID uuid;

Expand All @@ -39,7 +39,8 @@ public class Message implements Persistable<UUID>, Serializable {
private MessageType messageType;

@Lob
@Column(insertable = true, updatable = true, nullable = true, columnDefinition = "LONGTEXT")
// @Column(insertable = true, updatable = true, nullable = true, columnDefinition = "LONGTEXT") // MARIA DB
@Column(insertable = true, updatable = true, nullable = true) // H2 CHARACTER LARGE OBJECT
private String payload;

@Column(insertable = true, updatable = false, nullable = true, columnDefinition = "DATETIME(6) DEFAULT NOW(6)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class MapTopography implements Persistable<Long>, Serializable, MapRelate
private GameMap gameMap;

@Lob
@Column(insertable = true, updatable = true, nullable = false, columnDefinition = "LONGBLOB")
// @Column(insertable = true, updatable = true, nullable = false, columnDefinition = "LONGBLOB")
@Column(insertable = true, updatable = true, nullable = false) // H2 BINARY LARGE OBJECT
private byte[] data;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ private static List<RequestMatcher> publicEndpoints() {
@NonNull
private static List<RequestMatcher> swaggerEndpoints() {
return List.of(
// AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/favicon.ico"),
// AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/h2-console"),
// AntPathRequestMatcher.antMatcher(HttpMethod.POST, "/h2-console"),
// AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/h2-console/**"),
// AntPathRequestMatcher.antMatcher(HttpMethod.POST, "/h2-console/**"),

AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/swagger-ui.html"),
AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/swagger-ui/**"),
AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/v3/api-docs/**"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,21 @@ private ConfigurationMapToolsService.AddResourcesTuple mergeWithExistingConfigur
.toList();
final List<String> matchedResourcesByPrefabs = mapStructurePersistenceLayer.findAllByPrefabIn(gameMap, matchedPrefabs).stream()
.map(MapStructureEntity::getResourceName)
.filter(Objects::nonNull)
.map(ResourceNameEntity::getName)
.filter(Objects::nonNull)
.toList();
resourcesToAdd.addAll(matchedResourcesByPrefabs);

final List<String> matchedClasses = gameMapService.provideGameMapMetaData(gameMap).getUtilizedClasses().stream()
.filter(utilizedPrefab -> utilizedPrefab.toLowerCase().matches(entityMatcher.toLowerCase()))
.toList();
final List<String> matchedResourcesByClasses = mapStructurePersistenceLayer.findAllByClassIn(gameMap, matchedClasses).stream()
List<MapStructureEntity> allByClassIn = mapStructurePersistenceLayer.findAllByClassIn(gameMap, matchedClasses);
final List<String> matchedResourcesByClasses = allByClassIn.stream()
.map(MapStructureEntity::getResourceName)
.filter(Objects::nonNull)
.map(ResourceNameEntity::getName)
.filter(Objects::nonNull)
.toList();
resourcesToAdd.addAll(matchedResourcesByClasses);

Expand All @@ -95,7 +100,9 @@ private ConfigurationMapToolsService.AddResourcesTuple mergeWithExistingConfigur
.toList();
final List<String> matchedResourcesByMapDescriptorTypes = mapStructurePersistenceLayer.findAllByMapDescriptorTypeIn(gameMap, matchedMapDescriptorTypes).stream()
.map(MapStructureEntity::getResourceName)
.filter(Objects::nonNull)
.map(ResourceNameEntity::getName)
.filter(Objects::nonNull)
.toList();
resourcesToAdd.addAll(matchedResourcesByMapDescriptorTypes);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
server.port=8080

spring.datasource.url=jdbc:mariadb://127.0.0.1:8033/recom_db
spring.datasource.username=root
spring.datasource.password=recomRootPwd
spring.datasource.url=@env.spring.datasource.url@
spring.datasource.username=@env.spring.datasource.username@
spring.datasource.password=@env.spring.datasource.password@

# executes data.sql AFTER hibernate DDL
spring.jpa.defer-datasource-initialization=true
# run data.sql on every startup (not only on first startup)
spring.sql.init.mode=always

spring.h2.console.enabled=@env.spring.h2.console.enabled@


spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
Expand Down
3 changes: 3 additions & 0 deletions services/recom-backend/src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MERGE INTO account (account_uuid, access_key)
KEY (account_uuid)
VALUES ('d7840e5e-7fd8-48ee-a3f8-86ff15aacd0d', '06c6db2a-e49e-4153-906a-14beb0e8fc29');

0 comments on commit 8d5055e

Please sign in to comment.