Merge branch 'private-event-sourcing-examples-51'
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
||||
|
||||
import com.mongodb.WriteResult;
|
||||
import io.eventuate.Int128;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.AccountChangeInfo;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.accounts.AccountTransactionInfo;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.transactions.TransferState;
|
||||
@@ -29,7 +30,7 @@ public class AccountInfoUpdateService {
|
||||
}
|
||||
|
||||
|
||||
public void create(String accountId, String customerId, String title, BigDecimal initialBalance, String description, String version) {
|
||||
public void create(String accountId, String customerId, String title, BigDecimal initialBalance, String description, Int128 version) {
|
||||
try {
|
||||
AccountChangeInfo ci = new AccountChangeInfo();
|
||||
ci.setAmount(toIntegerRepr(initialBalance));
|
||||
@@ -40,8 +41,8 @@ public class AccountInfoUpdateService {
|
||||
.set("description", description)
|
||||
.set("balance", toIntegerRepr(initialBalance))
|
||||
.push("changes", ci)
|
||||
.set("creationDate", getFromEventId(version))
|
||||
.set("version", version),
|
||||
.set("creationDate", new Date(version.getHi()))
|
||||
.set("version", version.asString()),
|
||||
AccountInfo.class);
|
||||
logger.info("Saved in mongo");
|
||||
|
||||
@@ -81,12 +82,4 @@ public class AccountInfoUpdateService {
|
||||
set("transactions." + transactionId + ".status", status),
|
||||
AccountInfo.class);
|
||||
}
|
||||
|
||||
private Date getFromEventId(String eventId) {
|
||||
String[] s = eventId.split("-");
|
||||
if (s.length != 2) {
|
||||
return new Date();
|
||||
}
|
||||
return new Date(Long.parseUnsignedLong(s[0], 16));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.ac
|
||||
import io.eventuate.DispatchedEvent;
|
||||
import io.eventuate.EventHandlerMethod;
|
||||
import io.eventuate.EventSubscriber;
|
||||
import io.eventuate.Int128;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.*;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.CreditRecordedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.DebitRecordedEvent;
|
||||
@@ -34,7 +35,7 @@ public class AccountQueryWorkflow {
|
||||
public void create(DispatchedEvent<AccountOpenedEvent> de) {
|
||||
AccountOpenedEvent event = de.getEvent();
|
||||
String id = de.getEntityId();
|
||||
String eventId = de.getEventId().asString();
|
||||
Int128 eventId = de.getEventId();
|
||||
logger.info("**************** account version=" + id + ", " + eventId);
|
||||
BigDecimal initialBalance = event.getInitialBalance();
|
||||
|
||||
@@ -57,8 +58,8 @@ public class AccountQueryWorkflow {
|
||||
String moneyTransferId = de.getEntityId();
|
||||
String fromAccountId = de.getEvent().getDetails().getFromAccountId();
|
||||
String toAccountId = de.getEvent().getDetails().getToAccountId();
|
||||
logger.info("**************** account version=" + fromAccountId + ", " + de.getEventId().asString());
|
||||
logger.info("**************** account version=" + toAccountId + ", " + de.getEventId().asString());
|
||||
logger.info("**************** account version=" + fromAccountId + ", " + eventId);
|
||||
logger.info("**************** account version=" + toAccountId + ", " + eventId);
|
||||
|
||||
AccountTransactionInfo ti = new AccountTransactionInfo(moneyTransferId,
|
||||
fromAccountId,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
||||
|
||||
import io.eventuate.Int128;
|
||||
import io.eventuate.javaclient.spring.jdbc.EventuateJdbcEventStoreConfiguration;
|
||||
import io.eventuate.javaclient.spring.jdbc.IdGenerator;
|
||||
import io.eventuate.javaclient.spring.jdbc.IdGeneratorImpl;
|
||||
@@ -46,7 +47,7 @@ public class AccountInfoUpdateServiceTest {
|
||||
IdGenerator x = new IdGeneratorImpl();
|
||||
String accountId = x.genId().asString();
|
||||
String customerId = x.genId().asString();
|
||||
String version = x.genId().asString();
|
||||
Int128 version = x.genId();
|
||||
|
||||
String title = "Checking account";
|
||||
BigDecimal initialBalance = new BigDecimal("1345");
|
||||
@@ -63,7 +64,7 @@ public class AccountInfoUpdateServiceTest {
|
||||
assertEquals(initialBalance.longValue() * 100, accountInfo.getBalance());
|
||||
assertEquals(1, accountInfo.getChanges().size());
|
||||
assertTrue(accountInfo.getTransactions().isEmpty());
|
||||
assertEquals(version, accountInfo.getVersion());
|
||||
assertEquals(version.asString(), accountInfo.getVersion());
|
||||
|
||||
|
||||
String changeId = x.genId().asString();
|
||||
@@ -99,7 +100,7 @@ public class AccountInfoUpdateServiceTest {
|
||||
IdGenerator x = new IdGeneratorImpl();
|
||||
String accountId = x.genId().asString();
|
||||
String customerId = x.genId().asString();
|
||||
String version = x.genId().asString();
|
||||
Int128 version = x.genId();
|
||||
|
||||
String title = "Checking account";
|
||||
BigDecimal initialBalance = new BigDecimal("1345");
|
||||
@@ -114,7 +115,7 @@ public class AccountInfoUpdateServiceTest {
|
||||
IdGenerator x = new IdGeneratorImpl();
|
||||
String accountId = x.genId().asString();
|
||||
String customerId = x.genId().asString();
|
||||
String version = x.genId().asString();
|
||||
Int128 version = x.genId();
|
||||
|
||||
String title = "Checking account";
|
||||
BigDecimal initialBalance = new BigDecimal("1345");
|
||||
|
||||
@@ -5,5 +5,5 @@ eventuateMavenRepoUrl=http://mavenrepo.eventuate.io/release
|
||||
|
||||
springBootVersion=1.3.5.RELEASE
|
||||
|
||||
eventuateClientVersion=0.10.0.RELEASE
|
||||
eventuateClientVersion=0.12.0.RELEASE
|
||||
eventuateLocalVersion=0.4.0.RELEASE
|
||||
|
||||
Reference in New Issue
Block a user