Split project into sub-projects
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
create table LOGS (
|
||||
LOG_ID int not null,
|
||||
LOG_VALUE varchar(100) not null
|
||||
);
|
||||
61
dbt-demo/src/ratpack/Ratpack.groovy
Normal file
61
dbt-demo/src/ratpack/Ratpack.groovy
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user