Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from speedment/jpa-inheritance
Improve handling of JPA inheritance and annotation processing
- Loading branch information
Showing
49 changed files
with
905 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/.env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MYSQL_ROOT_PASSWORD=password | ||
MYSQL_DATABASE=testdb | ||
MYSQL_USER=speedment | ||
MYSQL_PASSWORD=password |
85 changes: 85 additions & 0 deletions
85
...src/test/java/com/speedment/jpastreamer/integration/test/inheritance/InheritanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.speedment.jpastreamer.integration.test.inheritance; | ||
|
||
import com.speedment.jpastreamer.application.JPAStreamer; | ||
import com.speedment.jpastreamer.integration.test.inheritance.model.BlogPost; | ||
import com.speedment.jpastreamer.integration.test.inheritance.model.BlogPost$; | ||
import com.speedment.jpastreamer.integration.test.inheritance.model.Book; | ||
import com.speedment.jpastreamer.integration.test.inheritance.model.Book$; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class InheritanceTest { | ||
|
||
final static protected JPAStreamer jpaStreamer = JPAStreamer.of("testdb"); | ||
|
||
@Test | ||
void countTest() { | ||
|
||
final List<Book> collect = jpaStreamer.stream(Book.class).collect(Collectors.toList()); | ||
|
||
final long expected = collect.stream() | ||
.filter(b -> b.getPages() > 300) | ||
.count(); | ||
|
||
final long actual = jpaStreamer.stream(Book.class) | ||
.filter(Book$.pages.greaterThan(300)) | ||
.count(); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void inheritanceTest() { | ||
|
||
final List<Book> collect = jpaStreamer.stream(Book.class).collect(Collectors.toList()); | ||
|
||
final long expected = collect.stream() | ||
.filter(b -> b.getTitle().contains("1")) | ||
.count(); | ||
|
||
final long actual = jpaStreamer.stream(Book.class) | ||
.filter(Book$.title.contains("1")) | ||
.count(); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void inheritanceTest2() { | ||
|
||
final List<BlogPost> collect = jpaStreamer.stream(BlogPost.class).collect(Collectors.toList()); | ||
|
||
final long expected = collect.stream() | ||
.filter(b -> b.getTitle().contains("1")) | ||
.count(); | ||
|
||
final long actual = jpaStreamer.stream(BlogPost.class) | ||
.filter(BlogPost$.title.contains("1")) | ||
.count(); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
void inheritanceTest3() { | ||
|
||
final List<BlogPost> collect = jpaStreamer.stream(BlogPost.class) | ||
.collect(Collectors.toList()); | ||
|
||
final long expected = collect.stream() | ||
.filter(b -> b.getTitle().contains("1")) | ||
.count(); | ||
|
||
final long actual = jpaStreamer.stream(BlogPost.class) | ||
.filter(BlogPost$.title.contains("1")) | ||
.count(); | ||
|
||
assertEquals(expected, actual); | ||
} | ||
|
||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...s/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
version: '3.8' | ||
|
||
services: | ||
test-db: | ||
container_name: test-db | ||
image: mysql:8.0 | ||
command: --default-authentication-plugin=mysql_native_password | ||
restart: always | ||
volumes: | ||
- "./scripts/schema.sql:/docker-entrypoint-initdb.d/1.sql" | ||
- "./scripts/data.sql:/docker-entrypoint-initdb.d/2.sql" | ||
environment: | ||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} | ||
MYSQL_DATABASE: ${MYSQL_DATABASE} | ||
MYSQL_USER: ${MYSQL_USER} | ||
MYSQL_PASSWORD: ${MYSQL_PASSWORD} | ||
ports: | ||
- "3305:3306" | ||
expose: | ||
- "3305" |
20 changes: 20 additions & 0 deletions
20
.../src/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/BlogPost.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.speedment.jpastreamer.integration.test.inheritance.model; | ||
|
||
import jakarta.persistence.*; | ||
|
||
@Entity | ||
@Table(name = "blogpost", schema = "publications") | ||
public class BlogPost extends Publication { | ||
|
||
@Column(name = "url", nullable = false, updatable = false, columnDefinition = "varchar(255)") | ||
private String url ; | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public void setUrl(String url) { | ||
this.url = url; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...ests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.speedment.jpastreamer.integration.test.inheritance.model; | ||
|
||
import jakarta.persistence.*; | ||
|
||
@Entity | ||
@Table(name = "books", schema = "publications") | ||
public class Book extends Publication { | ||
|
||
@Column(name = "pages", nullable = false, updatable = false, columnDefinition = "int(6)") | ||
private Integer pages; | ||
|
||
public Integer getPages() { | ||
return pages; | ||
} | ||
|
||
public void setPages(Integer pages) { | ||
this.pages = pages; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...c/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/Publication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.speedment.jpastreamer.integration.test.inheritance.model; | ||
|
||
import jakarta.persistence.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@MappedSuperclass | ||
public abstract class Publication { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id", nullable = false, updatable = false, columnDefinition = "int(6)") | ||
protected Integer id; | ||
|
||
@Column(name = "publishing_date", nullable = false, updatable = false, columnDefinition = "date") | ||
protected LocalDateTime publishingDate; | ||
|
||
@Column(name = "title", nullable = false, updatable = false, columnDefinition = "varchar(255)") | ||
private String title; | ||
|
||
@Version | ||
@Column(name = "version", nullable = false, updatable = false, columnDefinition = "int(6)") | ||
private Integer version; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public LocalDateTime getPublishingDate() { | ||
return publishingDate; | ||
} | ||
|
||
public void setPublishingDate(LocalDateTime publishingDate) { | ||
this.publishingDate = publishingDate; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public Integer getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(Integer version) { | ||
this.version = version; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...on-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/run-test.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
|
||
docker-compose rm -v -f -s test-db && docker-compose up -d | ||
mysql -h 127.0.0.1 -P 3305 -u speedment -ppassword publications |
35 changes: 35 additions & 0 deletions
35
...sts/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/scripts/data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
INSERT INTO books (id, publishing_date, title, version, pages) | ||
VALUES (1, '2008-7-04', 'Book 1', 2, 213), | ||
(2, '2009-7-04', 'Book 2', 2, 234), | ||
(3, '2010-7-04', 'Book 3', 2, 643), | ||
(4, '2011-7-04', 'Book 4', 2, 211), | ||
(5, '2012-7-04', 'Book 5', 2, 887), | ||
(6, '2013-7-04', 'Book 6', 2, 123), | ||
(7, '2014-7-04', 'Book 7', 2, 312), | ||
(8, '2015-7-04', 'Book 8', 2, 11), | ||
(9, '2016-7-04', 'Book 9', 2, 523), | ||
(10, '2017-7-04', 'Book 10', 2, 432), | ||
(11, '2018-7-04', 'Book 11', 2, 322), | ||
(12, '2019-7-04', 'Book 12', 2, 121); | ||
|
||
INSERT INTO blogposts (id, publishing_date, title, version, url) | ||
VALUES (1, '2008-7-04', 'Blog Post 1', 2, 'http://speedment.com'), | ||
(2, '2009-7-04', 'Blog Post 2', 2, 'http://speedment.com'), | ||
(3, '2010-7-04', 'Blog Post 3', 2, 'http://speedment.com'), | ||
(4, '2011-7-04', 'Blog Post 4', 2, 'http://speedment.com'), | ||
(5, '2012-7-04', 'Blog Post 5', 2, 'http://speedment.com'), | ||
(6, '2013-7-04', 'Blog Post 6', 2, 'http://speedment.com'), | ||
(7, '2014-7-04', 'Blog Post 7', 2, 'http://speedment.com'), | ||
(8, '2015-7-04', 'Blog Post 8', 2, 'http://speedment.com'), | ||
(9, '2016-7-04', 'Blog Post 9', 2, 'http://speedment.com'), | ||
(10, '2017-7-04', 'Blog Post 10', 2, 'http://speedment.com'), | ||
(11, '2018-7-04', 'Blog Post 11', 2, 'http://speedment.com'), | ||
(12, '2019-7-04', 'Blog Post 12', 2, 'http://speedment.com'), | ||
|
||
INSERT INTO author (id, firstname, lastname, version) | ||
(1, 'Author 1', 'Lastname', 2), | ||
(2, 'Author 2', 'Blog Post 2', 2), | ||
(3, 'Author 3', 'Blog Post 3', 2), | ||
(4, 'Author 5', 'Blog Post 4', 2), | ||
(5, 'Author 6', 'Blog Post 5', 2); | ||
|
25 changes: 25 additions & 0 deletions
25
...s/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/scripts/schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
CREATE TABLE books ( | ||
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
publishing_date DATE NOT NULL, | ||
title VARCHAR(255) NOT NULL, | ||
version INT(6), | ||
pages INT(6), | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TABLE blogpost ( | ||
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
publishing_date DATE NOT NULL, | ||
title VARCHAR(255) NOT NULL, | ||
version INT(6), | ||
url VARCHAR(255) NOT NULL, | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); | ||
|
||
CREATE TABLE author ( | ||
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
firstname VARCHAR(255) NOT NULL, | ||
lastname VARCHAR(255) NOT NULL, | ||
version INT(6), | ||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
); |
4 changes: 4 additions & 0 deletions
4
integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/.env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MYSQL_ROOT_PASSWORD=password | ||
MYSQL_DATABASE=testdb2 | ||
MYSQL_USER=speedment | ||
MYSQL_PASSWORD=password |
Oops, something went wrong.