1

Split project into sub-projects

This commit is contained in:
2018-05-04 17:23:08 +03:00
parent a3e6f119e7
commit fb4baec57f
28 changed files with 119 additions and 42 deletions

View File

@@ -0,0 +1,15 @@
package com.devsoap.dbt.demo
import org.flywaydb.core.Flyway
import ratpack.service.Service
import ratpack.service.StartEvent
import javax.sql.DataSource
class DatabaseService implements Service {
@Override
void onStart(StartEvent event){
new Flyway(dataSource: event.registry.get(DataSource)).migrate()
}
}

View File

@@ -0,0 +1,4 @@
create table LOGS (
LOG_ID int not null,
LOG_VALUE varchar(100) not null
);

View File

@@ -0,0 +1,61 @@
import com.devsoap.dbt.DBTModule
import com.devsoap.dbt.demo.DatabaseService
import com.devsoap.dbt.config.DBTConfig
import com.devsoap.dbt.services.TransactionManagerService
import org.h2.jdbcx.JdbcDataSource
import ratpack.session.SessionModule
import javax.sql.DataSource
import static ratpack.groovy.Groovy.ratpack
ratpack {
serverConfig {
sysProps()
require('/dbt', DBTConfig)
}
bindings {
module SessionModule
module (DBTModule) {
it.ledger.remoteUrl = 'http://localhost:5050/ledger'
it.executor.remoteUrl = 'http://localhost:5050/executor'
}
bindInstance(DataSource, new JdbcDataSource(url: 'jdbc:h2:mem:dbtdb;DB_CLOSE_DELAY=-1', user: ''))
bind DatabaseService
}
handlers {
/**
* Consumer services
*/
get('frontend') {
get(TransactionManagerService).execute { transaction ->
transaction.query("INSERT INTO LOGS(LOG_ID,LOG_VALUE) VALUES (${new Random().nextInt()}, 'HELLO')")
}.then {
redirect("/gateway/${it['id'].textValue()}")
}
}
get('gateway/:transactionId?') {
get(TransactionManagerService).execute(pathTokens.transactionId, { transaction ->
transaction.query("INSERT INTO LOGS(LOG_ID,LOG_VALUE) VALUES (${new Random().nextInt()}, 'WORLD')")
}).then {
redirect("/gateway2/${it['id'].textValue()}")
}
}
get('gateway2/:transactionId?') {
get(TransactionManagerService).execute(pathTokens.transactionId, { transaction ->
transaction.query("SELECT * FROM LOGS")
transaction.complete()
}).then {
render it.toString()
}
}
}
}