Skip to content

Commit

Permalink
Storage config models
Browse files Browse the repository at this point in the history
  • Loading branch information
pavetok committed Oct 21, 2023
1 parent 0c82dde commit 870d258
Show file tree
Hide file tree
Showing 30 changed files with 208 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import smecalculus.bezmen.core.SepulkaMapper;
import smecalculus.bezmen.core.SepulkaMapperImpl;
import smecalculus.bezmen.core.SepulkaService;
import smecalculus.bezmen.core.SepulkaServiceImpl;
import smecalculus.bezmen.core.SepulkaSliceMapper;
import smecalculus.bezmen.core.SepulkaSliceMapperImpl;
import smecalculus.bezmen.messaging.SepulkaClient;
import smecalculus.bezmen.messaging.SepulkaClientImpl;
import smecalculus.bezmen.messaging.SepulkaMessageMapper;
Expand Down Expand Up @@ -53,12 +53,12 @@ SepulkaClient sepulkaClient(EdgeValidator validator, SepulkaMessageMapper mapper
}

@Bean
SepulkaSliceMapper sepulkaSliceMapper() {
return new SepulkaSliceMapperImpl();
SepulkaMapper sepulkaMapper() {
return new SepulkaMapperImpl();
}

@Bean
SepulkaService sepulkaService(SepulkaSliceMapper mapper, SepulkaDao dao) {
SepulkaService sepulkaService(SepulkaMapper mapper, SepulkaDao dao) {
return new SepulkaServiceImpl(mapper, dao);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class SepulkaServiceImpl implements SepulkaService {

@NonNull
private SepulkaSliceMapper mapper;
private SepulkaMapper mapper;

@NonNull
private SepulkaDao dao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import smecalculus.bezmen.configuration.StorageProps;
import smecalculus.bezmen.configuration.ServerSide.StorageProps;
import smecalculus.bezmen.storage.SepulkaDao;
import smecalculus.bezmen.storage.SepulkaDaoMyBatis;
import smecalculus.bezmen.storage.SepulkaDaoSpringData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@
import static smecalculus.bezmen.configuration.StorageProtocolMode.POSTGRES;

import org.springframework.context.annotation.Bean;
import smecalculus.bezmen.configuration.StorageProps;
import smecalculus.bezmen.configuration.StoragePropsEg;
import smecalculus.bezmen.configuration.ServerSide.StorageProps;
import smecalculus.bezmen.configuration.ServerSideEg;

public class StoragePropsBeans {

public static class SpringDataPostgres {
@Bean
public StorageProps storageProps() {
return StoragePropsEg.storageProps(SPRING_DATA, POSTGRES).build();
return ServerSideEg.storageProps(SPRING_DATA, POSTGRES).build();
}
}

public static class SpringDataH2 {
@Bean
public StorageProps storageProps() {
return StoragePropsEg.storageProps(SPRING_DATA, H2).build();
return ServerSideEg.storageProps(SPRING_DATA, H2).build();
}
}

public static class MyBatisPostgres {
@Bean
public StorageProps storageProps() {
return StoragePropsEg.storageProps(MY_BATIS, POSTGRES).build();
return ServerSideEg.storageProps(MY_BATIS, POSTGRES).build();
}
}

public static class MyBatisH2 {
@Bean
public StorageProps storageProps() {
return StoragePropsEg.storageProps(MY_BATIS, H2).build();
return ServerSideEg.storageProps(MY_BATIS, H2).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import smecalculus.bezmen.core.ServerSide.AggregateState;

@Mapper
public interface SepulkaSliceMapper {
public interface SepulkaMapper {
AggregateState.Builder toServer(RegistrationRequest request);

RegistrationResponse.Builder toClient(AggregateState state);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package smecalculus.bezmen.configuration;

import com.typesafe.config.Optional;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.ToString;
import smecalculus.bezmen.validation.ValueOfEnum;

public abstract class EdgeSide {

@Data
public static class StorageProps {

@NotNull
StorageProtocolProps protocol;

@NotNull
StateMappingProps mapping;
}

@Data
public static class StorageProtocolProps {

@ValueOfEnum(StorageProtocolMode.class)
String mode;

@Optional
H2Props h2;

@Optional
PostgresProps postgres;
}

@Data
public static class StateMappingProps {

@ValueOfEnum(StateMappingMode.class)
private String mode;
}

@Data
public static class PostgresProps {

@NotBlank
String url;

@NotBlank
String username;

@NotBlank
@ToString.Exclude
String password;
}

@Data
public static class H2Props {

@NotBlank
String url;

@NotBlank
String username;

@NotBlank
String password;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package smecalculus.bezmen.configuration;

import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA;
import static smecalculus.bezmen.configuration.StorageProtocolMode.H2;

import smecalculus.bezmen.configuration.EdgeSide.StateMappingProps;
import smecalculus.bezmen.configuration.EdgeSide.StorageProps;
import smecalculus.bezmen.configuration.EdgeSide.StorageProtocolProps;

public abstract class EdgeSideEg {

public static StorageProps storageProps() {
var propsEdge = new StorageProps();
propsEdge.setMapping(stateMappingProps());
propsEdge.setProtocol(storageProtocolProps());
return propsEdge;
}

public static StateMappingProps stateMappingProps() {
var propsEdge = new StateMappingProps();
propsEdge.setMode(SPRING_DATA.name());
return propsEdge;
}

public static StorageProtocolProps storageProtocolProps() {
var propsEdge = new StorageProtocolProps();
propsEdge.setMode(H2.name());
return propsEdge;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package smecalculus.bezmen.configuration;

import lombok.Builder;
import lombok.NonNull;
import lombok.ToString;

public abstract class ServerSide {

@Builder
public record StorageProps(@NonNull StorageProtocolProps protocolProps, @NonNull StateMappingProps mappingProps) {}

@Builder
public record StorageProtocolProps(
@NonNull StorageProtocolMode protocolMode, H2Props h2Props, PostgresProps postgresProps) {}

@Builder
public record StateMappingProps(@NonNull StateMappingMode mappingMode) {}

@Builder
public record H2Props(@NonNull String url, @NonNull String username, @NonNull String password) {}

@Builder
public record PostgresProps(
@NonNull String url, @NonNull String username, @NonNull @ToString.Exclude String password) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package smecalculus.bezmen.configuration;

import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA;
import static smecalculus.bezmen.configuration.StorageProtocolMode.H2;

import smecalculus.bezmen.configuration.ServerSide.H2Props;
import smecalculus.bezmen.configuration.ServerSide.PostgresProps;
import smecalculus.bezmen.configuration.ServerSide.StateMappingProps;
import smecalculus.bezmen.configuration.ServerSide.StorageProps;
import smecalculus.bezmen.configuration.ServerSide.StorageProtocolProps;

public abstract class ServerSideEg {
public static StorageProps.Builder storageProps() {
return StorageProps.builder()
.protocolProps(storageProtocolProps().build())
.mappingProps(stateMappingProps().build());
}

public static StorageProps.Builder storageProps(StateMappingMode mappingMode, StorageProtocolMode protocolMode) {
return storageProps()
.protocolProps(storageProtocolProps(protocolMode).build())
.mappingProps(stateMappingProps(mappingMode).build());
}

public static StateMappingProps.Builder stateMappingProps() {
return StateMappingProps.builder().mappingMode(SPRING_DATA);
}

public static StateMappingProps.Builder stateMappingProps(StateMappingMode mode) {
return stateMappingProps().mappingMode(mode);
}

public static StorageProtocolProps.Builder storageProtocolProps() {
return StorageProtocolProps.builder()
.protocolMode(H2)
.h2Props(H2Props.builder()
.url("jdbc:h2:mem:bezmen;DB_CLOSE_DELAY=-1")
.username("sa")
.password("sa")
.build())
.postgresProps(PostgresProps.builder()
.url("jdbc:postgresql://localhost:5432/bezmen")
.username("bezmen")
.password("bezmen")
.build());
}

public static StorageProtocolProps.Builder storageProtocolProps(StorageProtocolMode mode) {
return storageProtocolProps().protocolMode(mode);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 870d258

Please sign in to comment.