Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
making committed Jun 2, 2019
1 parent b3e2e76 commit 3341134
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
15 changes: 7 additions & 8 deletions 03-r2dbc.md
Expand Up @@ -98,20 +98,19 @@ public class R2dbcExpenditureRepository implements ExpenditureRepository {
return ("postgres".equals(uri.getScheme()) ? databaseUrl.replace("postgres", "postgresql") : databaseUrl);
}

static void initializeDatabase(String name, DatabaseClient databaseClient) {
public static Mono<Void> initializeDatabase(String name, DatabaseClient databaseClient) {
if ("H2".equals(name)) {
databaseClient.execute()
return databaseClient.execute()
.sql("CREATE TABLE IF NOT EXISTS expenditure (expenditure_id INT PRIMARY KEY AUTO_INCREMENT, expenditure_name VARCHAR(255), unit_price INT NOT NULL, quantity INT NOT NULL, " +
"expenditure_date DATE NOT NULL)")
.then()
.subscribe();
.then();
} else if ("PostgreSQL".equals(name)) {
databaseClient.execute()
return databaseClient.execute()
.sql("CREATE TABLE IF NOT EXISTS expenditure (expenditure_id SERIAL PRIMARY KEY, expenditure_name VARCHAR(255), unit_price INT NOT NULL, quantity INT NOT NULL, " +
"expenditure_date DATE NOT NULL)")
.then()
.subscribe();
.then();
}
return Mono.error(new IllegalStateException(name + " is not supported."));
}
```

Expand All @@ -125,7 +124,7 @@ public class R2dbcExpenditureRepository implements ExpenditureRepository {
.build();
final TransactionalOperator transactionalOperator = TransactionalOperator.create(new R2dbcTransactionManager(connectionFactory));

initializeDatabase(connectionFactory.getMetadata().getName(), databaseClient);
initializeDatabase(connectionFactory.getMetadata().getName(), databaseClient).subscribe();

return new ExpenditureHandler(new R2dbcExpenditureRepository(databaseClient, transactionalOperator)).routes();
}
Expand Down
13 changes: 6 additions & 7 deletions 06-income-api.md
Expand Up @@ -133,25 +133,24 @@ public class IncomeBuilder {


```java
static void initializeDatabase(String name, DatabaseClient databaseClient) {
public static Mono<Void> initializeDatabase(String name, DatabaseClient databaseClient) {
if ("H2".equals(name)) {
databaseClient.execute()
return databaseClient.execute()
.sql("CREATE TABLE IF NOT EXISTS expenditure (expenditure_id INT PRIMARY KEY AUTO_INCREMENT, expenditure_name VARCHAR(255), unit_price INT NOT NULL, quantity INT NOT NULL, " +
"expenditure_date DATE NOT NULL)")
.then()
.then(databaseClient.execute()
.sql("CREATE TABLE IF NOT EXISTS income (income_id INT PRIMARY KEY AUTO_INCREMENT, income_name VARCHAR(255), amount INT NOT NULL, income_date DATE NOT NULL)")
.then())
.subscribe();
.then());
} else if ("PostgreSQL".equals(name)) {
databaseClient.execute()
return databaseClient.execute()
.sql("CREATE TABLE IF NOT EXISTS expenditure (expenditure_id SERIAL PRIMARY KEY, expenditure_name VARCHAR(255), unit_price INT NOT NULL, quantity INT NOT NULL, " +
"expenditure_date DATE NOT NULL)")
.then()
.then(databaseClient.execute()
.sql("CREATE TABLE IF NOT EXISTS income (income_id SERIAL PRIMARY KEY, income_name VARCHAR(255), amount INT NOT NULL, income_date DATE NOT NULL)")
.then())
.subscribe();
.then());
}
return Mono.error(new IllegalStateException(name + " is not supported."));
}
```

0 comments on commit 3341134

Please sign in to comment.