Skip to content

Commit

Permalink
Created jOOQ Spring Boot Configuration and moved related classes to c…
Browse files Browse the repository at this point in the history
…onfig package.

Moved service types to service package.
  • Loading branch information
JackG committed Jul 14, 2015
1 parent 783dc54 commit 1d63c5f
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 47 deletions.
Expand Up @@ -27,44 +27,4 @@ public static void main(String[] args) {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }


@Bean
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}

@Bean
public DSLContext dsl(org.jooq.Configuration config) {
return new DefaultDSLContext(config);
}

@Bean
public ConnectionProvider connectionProvider(DataSource dataSource) {
return new DataSourceConnectionProvider(new TransactionAwareDataSourceProxy(dataSource));
}

@Bean
public TransactionProvider transactionProvider() {
return new SpringTransactionProvider();
}

@Bean
public ExceptionTranslator exceptionTranslator() {
return new ExceptionTranslator();
}

@Bean
public ExecuteListenerProvider executeListenerProvider(ExceptionTranslator exceptionTranslator) {
return new DefaultExecuteListenerProvider(exceptionTranslator);
}

@Bean
public org.jooq.Configuration jooqConfig(ConnectionProvider connectionProvider,
TransactionProvider transactionProvider, ExecuteListenerProvider executeListenerProvider) {

return new DefaultConfiguration() //
.derive(connectionProvider) //
.derive(transactionProvider) //
.derive(executeListenerProvider) //
.derive(SQLDialect.H2);
}
} }
@@ -1,4 +1,4 @@
package org.jooq.example.spring; package org.jooq.example.spring.config;


import org.jooq.ExecuteContext; import org.jooq.ExecuteContext;
import org.jooq.SQLDialect; import org.jooq.SQLDialect;
Expand Down
@@ -0,0 +1,65 @@
package org.jooq.example.spring.config;

import org.jooq.ConnectionProvider;
import org.jooq.DSLContext;
import org.jooq.ExecuteListenerProvider;
import org.jooq.SQLDialect;
import org.jooq.TransactionProvider;
import org.jooq.impl.DataSourceConnectionProvider;
import org.jooq.impl.DefaultConfiguration;
import org.jooq.impl.DefaultDSLContext;
import org.jooq.impl.DefaultExecuteListenerProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;

import javax.sql.DataSource;

/**
* @author Jacques Gonzalez
*/
@Configuration
public class JooqSpringBootConfiguration {

@Bean
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}

@Bean
public DSLContext dsl(org.jooq.Configuration config) {
return new DefaultDSLContext(config);
}

@Bean
public ConnectionProvider connectionProvider(DataSource dataSource) {
return new DataSourceConnectionProvider(new TransactionAwareDataSourceProxy(dataSource));
}

@Bean
public TransactionProvider transactionProvider() {
return new SpringTransactionProvider();
}

@Bean
public ExceptionTranslator exceptionTranslator() {
return new ExceptionTranslator();
}

@Bean
public ExecuteListenerProvider executeListenerProvider(ExceptionTranslator exceptionTranslator) {
return new DefaultExecuteListenerProvider(exceptionTranslator);
}

@Bean
public org.jooq.Configuration jooqConfig(ConnectionProvider connectionProvider,
TransactionProvider transactionProvider, ExecuteListenerProvider executeListenerProvider) {

return new DefaultConfiguration() //
.derive(connectionProvider) //
.derive(transactionProvider) //
.derive(executeListenerProvider) //
.derive(SQLDialect.H2);
}
}
Expand Up @@ -38,7 +38,7 @@
* *
* *
*/ */
package org.jooq.example.spring; package org.jooq.example.spring.config;


import org.jooq.Transaction; import org.jooq.Transaction;
import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionStatus;
Expand Down
Expand Up @@ -38,7 +38,7 @@
* *
* *
*/ */
package org.jooq.example.spring; package org.jooq.example.spring.config;


import static org.springframework.transaction.TransactionDefinition.PROPAGATION_NESTED; import static org.springframework.transaction.TransactionDefinition.PROPAGATION_NESTED;


Expand Down
Expand Up @@ -38,7 +38,7 @@
* *
* *
*/ */
package org.jooq.example.spring; package org.jooq.example.spring.service;


import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;


Expand Down
@@ -1,4 +1,4 @@
package org.jooq.example.spring; package org.jooq.example.spring.service;


import static org.jooq.example.db.h2.Tables.BOOK; import static org.jooq.example.db.h2.Tables.BOOK;


Expand Down
Expand Up @@ -7,6 +7,8 @@
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;


import org.jooq.DSLContext; import org.jooq.DSLContext;
import org.jooq.example.spring.config.SpringTransactionProvider;
import org.jooq.example.spring.service.BookService;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
Expand Down Expand Up @@ -34,8 +36,10 @@ public class TransactionTest {


@Autowired DSLContext dsl; @Autowired DSLContext dsl;
@Autowired DataSourceTransactionManager txMgr; @Autowired DataSourceTransactionManager txMgr;
@Autowired SpringTransactionProvider txProvider; @Autowired
@Autowired BookService books; SpringTransactionProvider txProvider;
@Autowired
BookService books;


@After @After
public void teardown() { public void teardown() {
Expand Down

0 comments on commit 1d63c5f

Please sign in to comment.