Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ public DefaultEventStore(StoredEventRepository storedEventRepository) {
this.storedEventRepository = storedEventRepository;
}

@Override
public List<StoredEvent> allStoredEventsBetween(long aLowStoredEventId, long aHighStoredEventId) {
return storedEventRepository.allStoredEventsBetween(aLowStoredEventId, aHighStoredEventId);
}

@Override
public List<StoredEvent> allStoredEventsSince(long aStoredEventId) {
return storedEventRepository.allStoredEventsSince(aStoredEventId);
}

@Override
public StoredEvent append(DomainEvent aDomainEvent) {
return storedEventRepository.save(null);
Expand All @@ -33,8 +23,4 @@ public void close() {
// DO NOTHING
}

@Override
public long countStoredEvents() {
return storedEventRepository.countStoredEvents();
}
}
6 changes: 0 additions & 6 deletions eventstore/src/main/java/net/slipp/ddd/events/EventStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@

public interface EventStore {

List<StoredEvent> allStoredEventsBetween(long aLowStoredEventId, long aHighStoredEventId);

List<StoredEvent> allStoredEventsSince(long aStoredEventId);

StoredEvent append(DomainEvent aDomainEvent);

void close();

long countStoredEvents();
}
60 changes: 18 additions & 42 deletions eventstore/src/main/java/net/slipp/ddd/events/StoredEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,17 @@

public class StoredEvent {

private Long eventId;
private String eventBody;
private LocalDateTime occurredOn;
private String typeName;

public StoredEvent(String aTypeName, LocalDateTime anOccurredOn, String anEventBody) {
this();

this.setEventBody(anEventBody);
this.setOccurredOn(anOccurredOn);
this.setTypeName(aTypeName);
}

public StoredEvent(String aTypeName, LocalDateTime anOccurredOn, String anEventBody, Long anEventId) {
this(aTypeName, anOccurredOn, anEventBody);

this.setEventId(anEventId);
}
private Long id;
private final String eventId;
private final String eventBody;
private final LocalDateTime occurredOn;
private final String typeName;

public String eventBody() {
return this.eventBody;
}

public Long eventId() {
public String eventId() {
return this.eventId;
}

Expand Down Expand Up @@ -59,31 +46,20 @@ public String eventTypeName() {
}


public StoredEvent() {
super();
this.setEventId(-1);
public StoredEvent(Long id, String eventId, String eventBody, LocalDateTime occurredOn, String typeName) {
this.id = id;
this.eventId = eventId;
this.eventBody = eventBody;
this.occurredOn = occurredOn;
this.typeName = typeName;
}

protected void setEventBody(String anEventBody) {
//TODO this.assertArgumentNotEmpty(anEventBody, "The event body is required.");
//this.assertArgumentLength(anEventBody, 1, 65000, "The event body must be 65000 characters or less.");

this.eventBody = anEventBody;
}

protected void setEventId(long anEventId) {
this.eventId = anEventId;
}

protected void setOccurredOn(LocalDateTime anOccurredOn) {
//LocalDateTime.of()
this.occurredOn = anOccurredOn;
public StoredEvent(String eventId, String eventBody, LocalDateTime occurredOn, String typeName) {
super();
this.eventId = eventId;
this.eventBody = eventBody;
this.occurredOn = occurredOn;
this.typeName = typeName;
}

protected void setTypeName(String aTypeName) {
//TODO this.assertArgumentNotEmpty(aTypeName, "The event type name is required.");
//this.assertArgumentLength(aTypeName, 1, 100, "The event type name must be 100 characters or less.");

this.typeName = aTypeName;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
package net.slipp.ddd.events;

import java.util.List;
import java.util.Optional;

public interface StoredEventRepository {

StoredEvent save(StoredEvent anEvent);

List<StoredEvent> allStoredEventsBetween(long aLowStoredEventId, long aHighStoredEventId);

List<StoredEvent> allStoredEventsSince(long aStoredEventId);

long countStoredEvents();

Optional<StoredEvent> findByEventId(Long eventId);
}
14 changes: 11 additions & 3 deletions recruit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ repositories {
jcenter()
}

dependencyManagement {
dependencies {
dependency group: 'org.bgee.log4jdbc-log4j2', name: 'log4jdbc-log4j2-jdbc4.1', version: '1.16'
dependency group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '2.1.1'
}
}

dependencies {

implementation project(':assertions')
implementation project(':eventstore')

implementation 'org.springframework.boot:spring-boot-starter-aop'

implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter'

implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.projectlombok:lombok'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.10'
Expand All @@ -37,7 +45,7 @@ dependencies {

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'mysql:mysql-connector-java'
implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16'
implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1'
implementation "org.liquibase:liquibase-core"
liquibaseRuntime "org.liquibase:liquibase-core"
liquibaseRuntime "mysql:mysql-connector-java"
Expand Down
7 changes: 4 additions & 3 deletions recruit/src/main/docker/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ services:
slipping-mysql:
image: mysql:8.0.20
environment:
- MYSQL_USER=root
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=slipp
- MYSQL_PASSWORD=slipppw
- MYSQL_DATABASE=slipping
ports:
- 3377:3306
command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp
command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp --default-authentication-plugin=mysql_native_password
38 changes: 8 additions & 30 deletions recruit/src/main/java/net/slipp/moim/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import net.slipp.ddd.events.DefaultEventStore;
import net.slipp.ddd.events.EventStore;
import net.slipp.ddd.events.StoredEvent;
import net.slipp.ddd.events.StoredEventRepository;
import net.slipp.moim.port.repository.MybatisStoredEventRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
Expand All @@ -13,9 +13,6 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import java.util.List;
import java.util.Optional;

@SpringBootApplication
@EnableConfigurationProperties({ LiquibaseProperties.class })
public class App {
Expand All @@ -24,42 +21,23 @@ public static void main(String[] args) {
SpringApplication.run(App.class, args);
}


@EnableAspectJAutoProxy
@Configuration
static class AopConfiguration {
}

@Configuration
static class DomainEventConfiguration {
@Bean
public StoredEventRepository storedEventRepository() {
return new StoredEventRepository() {
@Override
public StoredEvent save(StoredEvent anEvent) {
return null;
}

@Override
public List<StoredEvent> allStoredEventsBetween(long aLowStoredEventId, long aHighStoredEventId) {
throw new UnsupportedOperationException();
}
private final MybatisStoredEventRepository mybatisStoredEventRepository;

@Override
public List<StoredEvent> allStoredEventsSince(long aStoredEventId) {
throw new UnsupportedOperationException();
}

@Override
public long countStoredEvents() {
throw new UnsupportedOperationException();
}
DomainEventConfiguration(MybatisStoredEventRepository mybatisStoredEventRepository) {
this.mybatisStoredEventRepository = mybatisStoredEventRepository;
}

@Override
public Optional<StoredEvent> findByEventId(Long eventId) {
throw new UnsupportedOperationException();
}
};
@Bean
public StoredEventRepository storedEventRepository() {
return mybatisStoredEventRepository;
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.slipp.moim.domain.model.sample;

import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@EqualsAndHashCode
@Builder
public class Sample {

private Long id;
private String name;
private String address;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.slipp.moim.domain.model.sample;

import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface SampleMapper {

List<Sample> findAll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.slipp.moim.domain.model.sample;

import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SampleService {

private final SampleMapper sampleMapper;

public SampleService(SampleMapper sampleMapper) {
this.sampleMapper = sampleMapper;
}

public List<Sample> findAll() {
return sampleMapper.findAll();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.slipp.moim.port.repository;

import net.slipp.ddd.events.StoredEvent;
import net.slipp.ddd.events.StoredEventRepository;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface MybatisStoredEventRepository extends StoredEventRepository {

@Override
default StoredEvent save(StoredEvent anEvent) {

this.insert(anEvent);
return this.findStoredEventByEventId(anEvent.eventId());
};

@Insert("insert into stored_event(event_id, event_body, occurred_on, type_name) values (#{eventId}, #{eventBody}, #{occurredOn}, #{typeName})")
void insert(StoredEvent anEvent);

@Select("select * from stored_event where event_id = #{eventId}")
StoredEvent findStoredEventByEventId(String eventId);
}
Loading