Skip to content

Commit

Permalink
fixes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpestano committed Aug 27, 2016
1 parent 0e0a696 commit bdfcd9d
Show file tree
Hide file tree
Showing 38 changed files with 318 additions and 288 deletions.
10 changes: 6 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,10 @@ Snapshots are available in maven central, to use it just add the following snipp
</repositories>
----

== Other examples
== Examples

. DBUnit Rules https://github.com/rmpestano/dbunit-rules/tree/master/examples[examples module^]
. https://github.com/rmpestano/dbunit-tomee-appcomposer-sample[DBUnit Rules Application Composer^]
. https://github.com/rmpestano/jOOQ-DBUnit-flyway-example/[jOOQ Flyway DBUnit^]
Take a look at examples module which contains:
* https://github.com/rmpestano/dbunit-rules/tree/master/examples/jpa-productivity-boosters[JPA productivity boosters^]
* https://github.com/rmpestano/dbunit-rules/tree/master/examples/dbunit-tomee-appcomposer-sample[DBUnit Rules Application Composer^]
* https://github.com/rmpestano/dbunit-rules/tree/master/examples//jOOQ-DBUnit-flyway-example/[jOOQ Flyway DBUnit^]
* Each module contain a lot of tests that you can use as examples
1 change: 1 addition & 0 deletions examples/dbunit-tomee-appcomposer-sample
Submodule dbunit-tomee-appcomposer-sample added at 2f95d6
1 change: 1 addition & 0 deletions examples/jOOQ-DBUnit-flyway-example
Submodule jOOQ-DBUnit-flyway-example added at 8bfd63
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
= DBUnit rules Examples
= JPA Productivity Boosters

DBUnit rules integration tests for https://jaxenter.com/top-3-jpa-productivity-boosters-for-java-ee-developers-deltaspike-data-116136.html[top 3 jpa productivity boosters^] project.
205 changes: 205 additions & 0 deletions examples/jpa-productivity-boosters/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>


<parent>
<groupId>com.github.dbunit-rules</groupId>
<artifactId>examples</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>jpa-productivity-boosters</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-data-module-api</artifactId>
<version>${ds.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-data-module-impl</artifactId>
<version>${ds.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-jpa-module-api</artifactId>
<version>${ds.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-jpa-module-impl</artifactId>
<version>${ds.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.2.RELEASE</version>
</dependency>

<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-core</artifactId>
<version>3.6.2</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>3.6.2</version>
</dependency>

<!-- test deps -->

<dependency>
<groupId>com.github.dbunit-rules</groupId>
<artifactId>core</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<!-- see DeltaspikeUsingInterceptorIt -->
<groupId>com.github.dbunit-rules</groupId>
<artifactId>cdi</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.dbunit-rules</groupId>
<artifactId>cucumber</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-test-control-module-api</artifactId>
<version>${ds.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-impl</artifactId>
<version>${ds.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.deltaspike.modules</groupId>
<artifactId>deltaspike-test-control-module-impl</artifactId>
<version>${ds.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.deltaspike.cdictrl</groupId>
<artifactId>deltaspike-cdictrl-weld</artifactId>
<version>${ds.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>2.2.14.Final</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.8.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.8.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.3.Final</version>
<type>pom</type>
</dependency>


<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>1.2.2.Final</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<id>querydsl</id>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/querydsl</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
<execution>
<id>metamodel</id>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/metamodel</outputDirectory>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.8.Final</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies>
</plugin>

</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.example;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
*
* @author Matti Tahvonen
*/
public class CdiConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.example.jpadomain;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.*;

@MappedSuperclass
public abstract class AbstractEntity implements Serializable, Cloneable {
Expand All @@ -11,7 +11,7 @@ public abstract class AbstractEntity implements Serializable, Cloneable {
@GeneratedValue(strategy = GenerationType.AUTO)
@SequenceGenerator(name = "test")
public Long id;

public Long getId() {
return id;
}
Expand All @@ -25,7 +25,7 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if(this.id == null) {
if (this.id == null) {
return false;
}

Expand All @@ -42,5 +42,5 @@ public int hashCode() {
hash = 43 * hash + Objects.hashCode(this.id);
return hash;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import javax.persistence.Entity;

/**
*
* @author Matti Tahvonen
*/
@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.apache.deltaspike.data.api.EntityRepository;
import org.apache.deltaspike.data.api.Repository;
import org.example.jpadomain.Company;
import org.example.jpadomain.Contact;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.example.service.deltaspike;

import java.util.List;
import org.apache.deltaspike.data.api.EntityRepository;
import org.apache.deltaspike.data.api.QueryResult;
import org.apache.deltaspike.data.api.Repository;
import org.example.jpadomain.Company;
import org.example.jpadomain.Contact;

import java.util.List;

@Repository(forEntity = Contact.class)
public interface ContactRepository extends EntityRepository<Contact, Long> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.example.service.deltaspike;

import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;

import org.apache.deltaspike.jpa.api.transaction.Transactional;
import org.example.jpadomain.Company;
import org.example.jpadomain.Contact;

import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.List;

/**
* EJB to hide JPA related stuff from the UI layer.
*/
Expand Down Expand Up @@ -44,7 +44,7 @@ public List<Contact> findByCompanyAndName(Company company, String filter) {
}

public List<Contact> findPageByCompanyAndName(Company company, String filter,
int firstrow, int maxrows) {
int firstrow, int maxrows) {
return repository.findByCompanyAndNameLikeIgnoreCase(company,
"%" + filter + "%").firstResult(firstrow).maxResults(maxrows).
getResultList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package org.example.service.querydsl;

import org.example.service.springdata.CompanyRepository;
import org.example.service.springdata.ContactRepository;
import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import org.example.jpadomain.Company;
import org.example.jpadomain.Contact;
import org.example.jpadomain.QContact;
import org.example.service.springdata.CompanyRepository;
import org.example.service.springdata.ContactRepository;
import org.springframework.data.domain.PageRequest;

import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.List;

/**
* Spring Data + QueryDSL based implementation. QueryDSL can also be used alone,
* but its sweet spot is as a compliment to the "repository helpers" like Spring
* Data and DeltaSpike Data. Here we just implement couple of queries with it
* and rely simple stuff to Spring Data. We also use built in QueryDSL
* integration in Spring Data so we only need to construct the predicate part.
*
* <p>
* The Q prefixed classess, on which the QueryDSL magic is based on, are
* autogenerated based on entity classes, see pom.xml for a setup.
*/
Expand All @@ -31,10 +30,10 @@ public class QueryDslContactService {
CompanyRepository companyRepository;

public List<Contact> findPageByCompanyAndName(Company company, String filter,
int firstrow, int maxrows) {
int firstrow, int maxrows) {
QContact c = QContact.contact;
return repository.findAll(c.company.eq(company).and(c.name.
containsIgnoreCase(filter)),
containsIgnoreCase(filter)),
new PageRequest(firstrow / maxrows, maxrows)
).getContent();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.example.service.springdata;

import java.util.List;
import org.example.jpadomain.Company;
import org.example.jpadomain.Contact;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;

import java.util.List;

public interface ContactRepository extends JpaRepository<Contact, Long>,
QueryDslPredicateExecutor {

Expand Down
Loading

0 comments on commit bdfcd9d

Please sign in to comment.