Merge pull request #9728 from sampada07/JAVA-66

JAVA-66: Split or move persistence-modules/spring-data-jpa-2 module
This commit is contained in:
Josh Cummings 2020-07-29 08:55:04 -06:00 committed by GitHub
commit 1fb83e7188
336 changed files with 961 additions and 1554 deletions

View File

@ -59,11 +59,12 @@
<module>spring-data-elasticsearch</module>
<module>spring-data-gemfire</module>
<module>spring-data-geode</module>
<module>spring-data-jpa</module>
<module>spring-data-jpa-2</module>
<module>spring-data-jpa-3</module>
<module>spring-data-jpa-4</module>
<module>spring-data-jpa-5</module>
<module>spring-data-jpa-annotations</module>
<module>spring-data-jpa-crud</module>
<module>spring-data-jpa-enterprise</module>
<module>spring-data-jpa-filtering</module>
<module>spring-data-jpa-query</module>
<module>spring-data-jpa-repo</module>
<module>spring-data-keyvalue</module>
<module>spring-data-mongodb</module>
<module>spring-data-neo4j</module>

View File

@ -1,12 +0,0 @@
### Relevant Articles:
- [Spring Data JPA Derived Delete Methods](https://www.baeldung.com/spring-data-jpa-deleteby)
- [JPA Join Types](https://www.baeldung.com/jpa-join-types)
- [Case Insensitive Queries with Spring Data Repository](https://www.baeldung.com/spring-data-case-insensitive-queries)
- [The Exists Query in Spring Data](https://www.baeldung.com/spring-data-exists-query)
- [Spring Data JPA Repository Populators](https://www.baeldung.com/spring-data-jpa-repository-populators)
- [Spring Data JPA and Null Parameters](https://www.baeldung.com/spring-data-jpa-null-parameters)
- [Spring Data JPA Projections](https://www.baeldung.com/spring-data-jpa-projections)
- [JPA @Embedded And @Embeddable](https://www.baeldung.com/jpa-embedded-embeddable)
- [Spring Data JPA Delete and Relationships](https://www.baeldung.com/spring-data-jpa-delete)
- [Spring Data JPA and Named Entity Graphs](https://www.baeldung.com/spring-data-jpa-named-entity-graphs)
- [Customizing the Result of JPA Queries with Aggregation Functions](https://www.baeldung.com/jpa-queries-custom-result-with-aggregation-functions)

View File

@ -1,42 +0,0 @@
package com.baeldung.model;
import javax.persistence.*;
import java.util.Set;
@Entity
@Table(name = "users")
public class BasicUser {
@Id
@GeneratedValue
private Long id;
private String username;
@ElementCollection
private Set<String> permissions;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Set<String> getPermissions() {
return permissions;
}
public void setPermissions(Set<String> permissions) {
this.permissions = permissions;
}
}

View File

@ -1,13 +0,0 @@
package com.baeldung.multipledb.dao.product;
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.baeldung.multipledb.model.product.Product;
public interface ProductRepository extends PagingAndSortingRepository<Product, Integer> {
List<Product> findAllByPrice(double price, Pageable pageable);
}

View File

@ -1,14 +0,0 @@
package com.baeldung.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import com.baeldung.model.BasicUser;
public interface UserRepository extends JpaRepository<BasicUser, Long> {
Optional<BasicUser> findSummaryByUsername(String username);
Optional<BasicUser> findByUsername(String username);
}

View File

@ -1,142 +0,0 @@
package com.baeldung.multipledb;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
import com.baeldung.multipledb.dao.product.ProductRepository;
import com.baeldung.multipledb.model.product.Product;
@RunWith(SpringRunner.class)
@SpringBootTest(classes=MultipleDbApplication.class)
@EnableTransactionManagement
public class ProductRepositoryIntegrationTest {
@Autowired
private ProductRepository productRepository;
@Before
@Transactional("productTransactionManager")
public void setUp() {
productRepository.save(Product.from(1001, "Book", 21));
productRepository.save(Product.from(1002, "Coffee", 10));
productRepository.save(Product.from(1003, "Jeans", 30));
productRepository.save(Product.from(1004, "Shirt", 32));
productRepository.save(Product.from(1005, "Bacon", 10));
}
@Test
public void whenRequestingFirstPageOfSizeTwo_ThenReturnFirstPage() {
Pageable pageRequest = PageRequest.of(0, 2);
Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(2));
assertTrue(result.stream()
.map(Product::getId)
.allMatch(id -> Arrays.asList(1001, 1002)
.contains(id)));
}
@Test
public void whenRequestingSecondPageOfSizeTwo_ThenReturnSecondPage() {
Pageable pageRequest = PageRequest.of(1, 2);
Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(2));
assertTrue(result.stream()
.map(Product::getId)
.allMatch(id -> Arrays.asList(1003, 1004)
.contains(id)));
}
@Test
public void whenRequestingLastPage_ThenReturnLastPageWithRemData() {
Pageable pageRequest = PageRequest.of(2, 2);
Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(1));
assertTrue(result.stream()
.map(Product::getId)
.allMatch(id -> Arrays.asList(1005)
.contains(id)));
}
@Test
public void whenSortingByNameAscAndPaging_ThenReturnSortedPagedResult() {
Pageable pageRequest = PageRequest.of(0, 3, Sort.by("name"));
Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(3));
assertThat(result.getContent()
.stream()
.map(Product::getId)
.collect(Collectors.toList()), equalTo(Arrays.asList(1005, 1001, 1002)));
}
@Test
public void whenSortingByPriceDescAndPaging_ThenReturnSortedPagedResult() {
Pageable pageRequest = PageRequest.of(0, 3, Sort.by("price")
.descending());
Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(3));
assertThat(result.getContent()
.stream()
.map(Product::getId)
.collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001)));
}
@Test
public void whenSortingByPriceDescAndNameAscAndPaging_ThenReturnSortedPagedResult() {
Pageable pageRequest = PageRequest.of(0, 5, Sort.by("price")
.descending()
.and(Sort.by("name")));
Page<Product> result = productRepository.findAll(pageRequest);
assertThat(result.getContent(), hasSize(5));
assertThat(result.getContent()
.stream()
.map(Product::getId)
.collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001, 1005, 1002)));
}
@Test
public void whenRequestingFirstPageOfSizeTwoUsingCustomMethod_ThenReturnFirstPage() {
Pageable pageRequest = PageRequest.of(0, 2);
List<Product> result = productRepository.findAllByPrice(10, pageRequest);
assertThat(result, hasSize(2));
assertTrue(result.stream()
.map(Product::getId)
.allMatch(id -> Arrays.asList(1002, 1005)
.contains(id)));
}
}

View File

@ -1,4 +0,0 @@
# configuration for test containers testing
spring.datasource.url=${DB_URL}
spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}

View File

@ -1,4 +0,0 @@
# configuration for Test Containers testing
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false

View File

@ -1,2 +0,0 @@
create table PERSON (ID int8 not null, FIRST_NAME varchar(255), LAST_NAME varchar(255), primary key (ID))
create table person (id int8 not null, first_name varchar(255), last_name varchar(255), primary key (id))

View File

@ -1,15 +0,0 @@
### Relevant Articles:
- [Spring JPA @Embedded and @EmbeddedId](https://www.baeldung.com/spring-jpa-embedded-method-parameters)
- [Generate Database Schema with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-generate-db-schema)
- [Partial Data Update with Spring Data](https://www.baeldung.com/spring-data-partial-update)
### Eclipse Config
After importing the project into Eclipse, you may see the following error:
"No persistence xml file found in project"
This can be ignored:
- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project"
Or:
- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator

View File

@ -0,0 +1,23 @@
## Spring Data JPA - Annotations
This module contains articles about annotations used in Spring Data JPA
### Relevant articles
- [Spring Data Annotations](https://www.baeldung.com/spring-data-annotations)
- [DDD Aggregates and @DomainEvents](https://www.baeldung.com/spring-data-ddd)
- [JPA @Embedded And @Embeddable](https://www.baeldung.com/jpa-embedded-embeddable)
- [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation)
- [Spring JPA @Embedded and @EmbeddedId](https://www.baeldung.com/spring-jpa-embedded-method-parameters)
- [Programmatic Transaction Management in Spring](https://www.baeldung.com/spring-programmatic-transaction-management)
- [JPA Entity Lifecycle Events](https://www.baeldung.com/jpa-entity-lifecycle-events)
### Eclipse Config
After importing the project into Eclipse, you may see the following error:
"No persistence xml file found in project"
This can be ignored:
- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project"
Or:
- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator

View File

@ -0,0 +1,77 @@
<?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>
<artifactId>spring-data-jpa-annotations</artifactId>
<name>spring-data-jpa-annotations</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<!-- Test containers only dependencies -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>${testcontainers.postgresql.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!-- Test containers only dependencies -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
<properties>
<start-class>com.baeldung.boot.Application</start-class>
<testcontainers.postgresql.version>1.10.6</testcontainers.postgresql.version>
<postgresql.version>42.2.5</postgresql.version>
<guava.version>21.0</guava.version>
</properties>
</project>

View File

@ -1,14 +1,15 @@
## Spring Data JPA - CRUD
This module contains articles about CRUD operations in Spring Data JPA
### Relevant Articles:
- [Limiting Query Results with JPA and Spring Data JPA](https://www.baeldung.com/jpa-limit-query-results)
- [Sorting Query Results with Spring Data](https://www.baeldung.com/spring-data-sorting)
- [Spring Data JPA Derived Delete Methods](https://www.baeldung.com/spring-data-jpa-deleteby)
- [Spring Data JPA Delete and Relationships](https://www.baeldung.com/spring-data-jpa-delete)
- [INSERT Statement in JPA](https://www.baeldung.com/jpa-insert)
- [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting)
- [Spring Data JPA Query by Example](https://www.baeldung.com/spring-data-query-by-example)
- [DB Integration Tests with Spring Boot and Testcontainers](https://www.baeldung.com/spring-boot-testcontainers-integration-test)
- [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation)
- [Spring Data JPA Batch Inserts](https://www.baeldung.com/spring-data-jpa-batch-inserts)
- [Batch Insert/Update with Hibernate/JPA](https://www.baeldung.com/jpa-hibernate-batch-insert-update)
- [Difference Between save() and saveAndFlush() in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-save-saveandflush)
- [Generate Database Schema with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-generate-db-schema)
### Eclipse Config
After importing the project into Eclipse, you may see the following error:

View File

@ -4,8 +4,8 @@
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>
<artifactId>spring-data-jpa-3</artifactId>
<name>spring-data-jpa-3</name>
<artifactId>spring-data-jpa-crud</artifactId>
<name>spring-data-jpa-crud</name>
<parent>
<groupId>com.baeldung</groupId>

View File

@ -0,0 +1,14 @@
spring.main.allow-bean-definition-overriding=true
spring.jpa.properties.hibernate.jdbc.batch_size=4
spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.order_updates=true
spring.jpa.properties.hibernate.generate_statistics=true
# JPA-Schema-Generation
# Use below configuration to generate database schema create commands based on the entity models
# and export them into the create.sql file
#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql
#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-source=metadata
#spring.jpa.properties.hibernate.format_sql=true

View File

@ -1,12 +1,17 @@
## Spring Data JPA - Enterprise
This module contains articles about Spring Data JPA used in enterprise applications such as transactions, sessions, naming conventions and more
### Relevant Articles:
- [Derived Query Methods in Spring Data JPA Repositories](https://www.baeldung.com/spring-data-derived-queries)
- [LIKE Queries in Spring JPA Repositories](https://www.baeldung.com/spring-jpa-like-queries)
- [Spring JPA Multiple Databases](https://www.baeldung.com/spring-data-jpa-multiple-databases)
- [Spring Data Java 8 Support](https://www.baeldung.com/spring-data-java-8)
- [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting)
- [DB Integration Tests with Spring Boot and Testcontainers](https://www.baeldung.com/spring-boot-testcontainers-integration-test)
- [A Guide to Springs Open Session In View](https://www.baeldung.com/spring-open-session-in-view)
- [Programmatic Transaction Management in Spring](https://www.baeldung.com/spring-programmatic-transaction-management)
- [JPA Entity Lifecycle Events](https://www.baeldung.com/jpa-entity-lifecycle-events)
- [Working with Lazy Element Collections in JPA](https://www.baeldung.com/java-jpa-lazy-collections)
- [Calling Stored Procedures from Spring Data JPA Repositories](https://www.baeldung.com/spring-data-jpa-stored-procedures)
- [Custom Naming Convention with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-custom-naming)
- [Partial Data Update with Spring Data](https://www.baeldung.com/spring-data-partial-update)
### Eclipse Config
After importing the project into Eclipse, you may see the following error:
@ -16,3 +21,4 @@ This can be ignored:
- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project"
Or:
- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator

View File

@ -3,8 +3,8 @@
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>
<artifactId>spring-data-jpa-5</artifactId>
<name>spring-data-jpa-5</name>
<artifactId>spring-data-jpa-enterprise</artifactId>
<name>spring-data-jpa-enterprise</name>
<parent>
<groupId>com.baeldung</groupId>
@ -39,6 +39,17 @@
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
@ -46,6 +57,20 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Test containers only dependencies -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<!-- Test containers only dependencies -->
</dependencies>
<build>
@ -75,6 +100,8 @@
<spring-geode-starter-version>1.1.1.RELEASE</spring-geode-starter-version>
<spring.boot.starter.version>2.1.9.RELEASE</spring.boot.starter.version>
<mapstruct.version>1.3.1.Final</mapstruct.version>
<guava.version>21.0</guava.version>
<testcontainers.version>1.12.2</testcontainers.version>
</properties>
</project>

View File

@ -1,14 +1,13 @@
package com.baeldung.multipledb;
package com.baeldung;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MultipleDbApplication {
public class Application {
public static void main(String[] args) {
SpringApplication.run(MultipleDbApplication.class, args);
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@EnableJpaRepositories("com.baeldung")
@EntityScan("com.baeldung")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

Some files were not shown because too many files have changed in this diff Show More