#315 - Polishing.
Used default directory for code generation. Formatting. Simplified asserts with some AssertJ trickery. Original pull request: #385.
This commit is contained in:
@@ -1,75 +1,74 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-data-jdbc-jooq</artifactId>
|
||||
<artifactId>spring-data-jdbc-jooq</artifactId>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.data.examples</groupId>
|
||||
<artifactId>spring-data-jdbc-examples</artifactId>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>org.springframework.data.examples</groupId>
|
||||
<artifactId>spring-data-jdbc-examples</artifactId>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<name>Spring Data JDBC - Usage with jOOQ</name>
|
||||
<description>Sample project demonstrating Spring Data JDBC features</description>
|
||||
<name>Spring Data JDBC - Usage with jOOQ</name>
|
||||
<description>Sample project demonstrating Spring Data JDBC features</description>
|
||||
|
||||
<properties>
|
||||
<jooq.version>3.11.0</jooq.version>
|
||||
<spring-boot-starter-jooq.version>2.0.3.RELEASE</spring-boot-starter-jooq.version>
|
||||
</properties>
|
||||
<properties>
|
||||
<jooq.version>3.11.0</jooq.version>
|
||||
<spring-boot-starter-jooq.version>2.0.3.RELEASE</spring-boot-starter-jooq.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq</artifactId>
|
||||
<version>${jooq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jooq</artifactId>
|
||||
<version>${spring-boot-starter-jooq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq-meta-extensions</artifactId>
|
||||
<version>${jooq.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq</artifactId>
|
||||
<version>${jooq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jooq</artifactId>
|
||||
<version>${spring-boot-starter-jooq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq-meta-extensions</artifactId>
|
||||
<version>${jooq.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq-codegen-maven</artifactId>
|
||||
<version>${jooq.version}</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq-codegen-maven</artifactId>
|
||||
<version>${jooq.version}</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
<configuration>
|
||||
<generator>
|
||||
<database>
|
||||
<name>org.jooq.meta.extensions.ddl.DDLDatabase</name>
|
||||
<properties>
|
||||
<property>
|
||||
<key>scripts</key>
|
||||
<value>${basedir}/src/main/resources/schema.sql</value>
|
||||
</property>
|
||||
</properties>
|
||||
</database>
|
||||
<target>
|
||||
<packageName>example.springdata.jdbc.basics.simpleentity.domain</packageName>
|
||||
<directory>${basedir}/gensrc/main/java</directory>
|
||||
</target>
|
||||
</generator>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<configuration>
|
||||
<generator>
|
||||
<database>
|
||||
<name>org.jooq.meta.extensions.ddl.DDLDatabase</name>
|
||||
<properties>
|
||||
<property>
|
||||
<key>scripts</key>
|
||||
<value>${basedir}/src/main/resources/schema.sql</value>
|
||||
</property>
|
||||
</properties>
|
||||
</database>
|
||||
<target>
|
||||
<packageName>example.springdata.jdbc.basics.simpleentity.domain</packageName>
|
||||
</target>
|
||||
</generator>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -19,11 +19,9 @@ package example.springdata.jdbc.jooq;
|
||||
* Age group for which a LegoSet is intended.
|
||||
*
|
||||
* @author Jens Schauder
|
||||
* @author Florian Lüdiger
|
||||
*/
|
||||
public enum AgeGroup {
|
||||
|
||||
_0to3,
|
||||
_3to8,
|
||||
_8to12,
|
||||
_12andOlder
|
||||
_0to3, _3to8, _8to12, _12andOlder
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package example.springdata.jdbc.jooq;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package example.springdata.jdbc.jooq;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.jooq.impl.DataSourceConnectionProvider;
|
||||
import org.jooq.impl.DefaultConfiguration;
|
||||
import org.jooq.impl.DefaultDSLContext;
|
||||
@@ -29,8 +31,6 @@ import org.springframework.data.jdbc.repository.config.JdbcConfiguration;
|
||||
import org.springframework.data.relational.core.mapping.event.RelationalEvent;
|
||||
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* Contains infrastructure necessary for creating repositories and two listeners.
|
||||
* <p>
|
||||
@@ -45,18 +45,7 @@ import javax.sql.DataSource;
|
||||
@Import(JdbcConfiguration.class)
|
||||
public class CategoryConfiguration {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Bean
|
||||
public ApplicationListener<?> loggingListener() {
|
||||
|
||||
return (ApplicationListener<ApplicationEvent>) event -> {
|
||||
if (event instanceof RelationalEvent) {
|
||||
System.out.println("Received an event: " + event);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Autowired private DataSource dataSource;
|
||||
|
||||
@Bean
|
||||
public DataSourceConnectionProvider connectionProvider() {
|
||||
|
||||
@@ -22,5 +22,4 @@ import org.springframework.data.repository.CrudRepository;
|
||||
*
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
interface CategoryRepository extends CrudRepository<Category, Long>, JooqRepository {
|
||||
}
|
||||
interface CategoryRepository extends CrudRepository<Category, Long>, JooqRepository {}
|
||||
|
||||
@@ -2,6 +2,9 @@ package example.springdata.jdbc.jooq;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Florian Lüdiger
|
||||
*/
|
||||
public interface JooqRepository {
|
||||
List<Category> getCategoriesWithAgeGroup(AgeGroup ageGroup);
|
||||
List<Category> getCategoriesWithAgeGroup(AgeGroup ageGroup);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package example.springdata.jdbc.jooq;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import static example.springdata.jdbc.basics.simpleentity.domain.tables.Category.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static example.springdata.jdbc.basics.simpleentity.domain.tables.Category.CATEGORY;
|
||||
import org.jooq.DSLContext;
|
||||
|
||||
/**
|
||||
* Implementations for custom repository access using jOOQ.
|
||||
@@ -13,17 +13,14 @@ import static example.springdata.jdbc.basics.simpleentity.domain.tables.Category
|
||||
*/
|
||||
public class JooqRepositoryImpl implements JooqRepository {
|
||||
|
||||
private final DSLContext dslContext;
|
||||
private final DSLContext dslContext;
|
||||
|
||||
public JooqRepositoryImpl(DSLContext dslContext) {
|
||||
this.dslContext = dslContext;
|
||||
}
|
||||
public JooqRepositoryImpl(DSLContext dslContext) {
|
||||
this.dslContext = dslContext;
|
||||
}
|
||||
|
||||
public List<Category> getCategoriesWithAgeGroup(AgeGroup ageGroup) {
|
||||
return this.dslContext
|
||||
.select()
|
||||
.from(CATEGORY)
|
||||
.where(CATEGORY.AGE_GROUP.equal(ageGroup.name()))
|
||||
.fetchInto(Category.class);
|
||||
}
|
||||
public List<Category> getCategoriesWithAgeGroup(AgeGroup ageGroup) {
|
||||
return this.dslContext.select().from(CATEGORY).where(CATEGORY.AGE_GROUP.equal(ageGroup.name()))
|
||||
.fetchInto(Category.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
*/
|
||||
package example.springdata.jdbc.jooq;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -23,11 +28,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Demonstrates simple CRUD operations with a simple entity without any references.
|
||||
*
|
||||
@@ -40,16 +40,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ComponentScan
|
||||
public class SimpleEntityTests {
|
||||
|
||||
@Autowired
|
||||
CategoryRepository repository;
|
||||
@Autowired CategoryRepository repository;
|
||||
|
||||
@Test
|
||||
public void exerciseRepositoryForSimpleEntity() {
|
||||
|
||||
// create some categories
|
||||
Category cars = new Category(null,"Cars", "Anything that has approximately 4 wheels", AgeGroup._3to8);
|
||||
Category cars = new Category(null, "Cars", "Anything that has approximately 4 wheels", AgeGroup._3to8);
|
||||
|
||||
Category buildings = new Category(null,"Buildings", null, AgeGroup._12andOlder);
|
||||
Category buildings = new Category(null, "Buildings", null, AgeGroup._12andOlder);
|
||||
|
||||
// save categories
|
||||
repository.saveAll(asList(cars, buildings));
|
||||
@@ -64,9 +63,11 @@ public class SimpleEntityTests {
|
||||
Output.list(repository.findAll(), "`Buildings` has a description");
|
||||
|
||||
List<Category> categoryList = repository.getCategoriesWithAgeGroup(AgeGroup._3to8);
|
||||
assertThat(categoryList.size()).isEqualTo(1);
|
||||
assertThat(categoryList.get(0).getName()).isEqualTo(cars.getName());
|
||||
assertThat(categoryList.get(0).getDescription()).isEqualTo(cars.getDescription());
|
||||
assertThat(categoryList.get(0).getAgeGroup()).isEqualTo(cars.getAgeGroup());
|
||||
|
||||
assertThat(categoryList) //
|
||||
.extracting(Category::getName, Category::getDescription, Category::getAgeGroup) //
|
||||
.containsExactly( //
|
||||
tuple(cars.getName(), cars.getDescription(), cars.getAgeGroup()) //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user