diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index e9f5614b..b48f6c39 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -17,7 +17,7 @@ jpastreamer-parent com.speedment.jpastreamer - 3.0.3-SNAPSHOT + 3.0.4-SNAPSHOT 4.0.0 @@ -26,14 +26,7 @@ Maven http://maven.apache.org/ 2001 - - - - website - scp://webhost.company.com/www/website - - - + UTF-8 @@ -41,45 +34,43 @@ - org.hibernate + org.hibernate.orm hibernate-core 6.0.2.Final test - - org.hibernate + org.hibernate.validator hibernate-validator - 6.0.13.Final + 8.0.1.Final test - - org.hibernate.javax.persistence - hibernate-jpa-2.1-api - 1.0.2 - test + jakarta.el + jakarta.el-api + 5.0.1 + + + org.glassfish + jakarta.el + 5.0.0-M1 - net.bytebuddy byte-buddy 1.12.12 test - mysql mysql-connector-java 8.0.30 test - com.speedment.jpastreamer jpastreamer-core - 3.0.3-SNAPSHOT - test + ${jpa-streamer.version} diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/.env b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/.env new file mode 100644 index 00000000..0b3feabf --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/.env @@ -0,0 +1,4 @@ +MYSQL_ROOT_PASSWORD=password +MYSQL_DATABASE=testdb +MYSQL_USER=speedment +MYSQL_PASSWORD=password diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/InheritanceTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/InheritanceTest.java new file mode 100644 index 00000000..eb2ed928 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/InheritanceTest.java @@ -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 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 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 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 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); + } + + +} diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/docker-compose.yml b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/docker-compose.yml new file mode 100644 index 00000000..05ae15e4 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/docker-compose.yml @@ -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" diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/BlogPost.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/BlogPost.java new file mode 100644 index 00000000..3b7a05e0 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/BlogPost.java @@ -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; + } + +} diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/Book.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/Book.java new file mode 100644 index 00000000..c70850b1 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/Book.java @@ -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; + } +} diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/Publication.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/Publication.java new file mode 100644 index 00000000..f8510655 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/model/Publication.java @@ -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; + } +} diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/run-test.sh b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/run-test.sh new file mode 100644 index 00000000..51baf5be --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/run-test.sh @@ -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 diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/scripts/data.sql b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/scripts/data.sql new file mode 100644 index 00000000..b7e0c7a5 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/scripts/data.sql @@ -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); + diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/scripts/schema.sql b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/scripts/schema.sql new file mode 100644 index 00000000..90c3e24e --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance/scripts/schema.sql @@ -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 +); diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/.env b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/.env new file mode 100644 index 00000000..1e3da257 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/.env @@ -0,0 +1,4 @@ +MYSQL_ROOT_PASSWORD=password +MYSQL_DATABASE=testdb2 +MYSQL_USER=speedment +MYSQL_PASSWORD=password diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/InheritanceTest2.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/InheritanceTest2.java new file mode 100644 index 00000000..b9006629 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/InheritanceTest2.java @@ -0,0 +1,99 @@ +package com.speedment.jpastreamer.integration.test.inheritance2; + +import com.speedment.jpastreamer.application.JPAStreamer; +import com.speedment.jpastreamer.integration.test.inheritance.model.Publication; +import com.speedment.jpastreamer.integration.test.inheritance2.model.*; +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 InheritanceTest2 { + + final static protected JPAStreamer jpaStreamer = JPAStreamer.of("testdb2"); + + @Test + void countTest() { + + final List collect = jpaStreamer.stream(Book2.class).collect(Collectors.toList()); + + final long expected = collect.stream() + .filter(b -> b.getPages() > 300) + .count(); + + final long actual = jpaStreamer.stream(Book2.class) + .filter(Book2$.pages.greaterThan(300)) + .count(); + + assertEquals(expected, actual); + } + + @Test + void inheritanceTest() { + + final List collect = jpaStreamer.stream(Book2.class).collect(Collectors.toList()); + + final long expected = collect.stream() + .filter(b -> b.getTitle().contains("1")) + .count(); + + final long actual = jpaStreamer.stream(Book2.class) + .filter(Book2$.title.contains("1")) + .count(); + + assertEquals(expected, actual); + } + + @Test + void inheritanceTest2() { + + final List collect = jpaStreamer.stream(BlogPost2.class).collect(Collectors.toList()); + + final long expected = collect.stream() + .filter(b -> b.getTitle().contains("1")) + .count(); + + final long actual = jpaStreamer.stream(BlogPost2.class) + .filter(BlogPost2$.title.contains("1")) + .count(); + + assertEquals(expected, actual); + } + + + @Test + void inheritanceTest3() { + + final List collect = jpaStreamer.stream(BlogPost2.class).collect(Collectors.toList()); + + final long expected = collect.stream() + .filter(b -> b.getUrl().contains("www")) + .count(); + + final long actual = jpaStreamer.stream(BlogPost2.class) + .filter(BlogPost2$.url.contains("www")) + .count(); + + assertEquals(expected, actual); + } + + @Test + void inheritanceTest4() { + + final List collect = jpaStreamer.stream(Publication2.class) + .collect(Collectors.toList()); + + final long expected = collect.stream() + .filter(p -> p.getTitle().contains("1")) + .count(); + + final long actual = jpaStreamer.stream(Publication2.class) + .filter(Publication2$.title.contains("1")) + .count(); + + assertEquals(expected, actual); + } + +} diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/docker-compose.yml b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/docker-compose.yml new file mode 100644 index 00000000..719761c9 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3.8' + +services: + test-db-2: + container_name: test-db-2 + 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: + - "3304:3306" + expose: + - "3304" diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/Author.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/Author.java new file mode 100644 index 00000000..98c9a26a --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/Author.java @@ -0,0 +1,57 @@ +package com.speedment.jpastreamer.integration.test.inheritance2.model; + +import jakarta.persistence.*; + +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "author", schema = "publications2") +public class Author { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", nullable = false, columnDefinition = "int(6)") + protected Long id; + + @Column(name = "firstname", columnDefinition = "varchar(255)") + private String firstname; + + @Column(name = "lastname", columnDefinition = "varchar(255)") + private String lastname; + + @ManyToMany(mappedBy = "authors") + private List publications = new ArrayList<>(); + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getFirstname() { + return firstname; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + public String getLastname() { + return lastname; + } + + public void setLastname(String lastname) { + this.lastname = lastname; + } + + public List getPublications() { + return publications; + } + + public void setPublications(List publications) { + this.publications = publications; + } +} diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/BlogPost2.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/BlogPost2.java new file mode 100644 index 00000000..b381949f --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/BlogPost2.java @@ -0,0 +1,22 @@ +package com.speedment.jpastreamer.integration.test.inheritance2.model; + +import jakarta.persistence.Column; +import jakarta.persistence.DiscriminatorValue; +import jakarta.persistence.Entity; + +@Entity +@DiscriminatorValue("BlogPost") +public class BlogPost2 extends Publication2 { + + @Column(name = "url", columnDefinition = "varchar(255)") + private String url ; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + +} diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/Book2.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/Book2.java new file mode 100644 index 00000000..399c9bdf --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/Book2.java @@ -0,0 +1,21 @@ +package com.speedment.jpastreamer.integration.test.inheritance2.model; + +import jakarta.persistence.Column; +import jakarta.persistence.DiscriminatorValue; +import jakarta.persistence.Entity; + +@Entity +@DiscriminatorValue("Book") +public class Book2 extends Publication2 { + + @Column(name = "pages", columnDefinition = "int(6)") + private Integer pages; + + public Integer getPages() { + return pages; + } + + public void setPages(Integer pages) { + this.pages = pages; + } +} diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/Publication2.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/Publication2.java new file mode 100644 index 00000000..b731e8a6 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/model/Publication2.java @@ -0,0 +1,76 @@ +package com.speedment.jpastreamer.integration.test.inheritance2.model; + +import jakarta.persistence.*; + +import java.time.LocalDateTime; +import java.util.HashSet; +import java.util.Set; + +@Entity +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "publication_type") +public abstract class Publication2 { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id", nullable = false, columnDefinition = "int(6)") + protected Long id; + + @Column(name = "publishing_date", nullable = false, columnDefinition = "date") + protected LocalDateTime publishingDate; + + @Column(name = "title", nullable = false, columnDefinition = "varchar(255)") + private String title; + + @Version + @Column(name = "version", nullable = false, columnDefinition = "int(6)") + private Integer version; + + @ManyToMany(cascade = { CascadeType.ALL }) + @JoinTable( + name = "publication_author", + joinColumns = { @JoinColumn(name = "publication_id", referencedColumnName = "id")}, + inverseJoinColumns = { @JoinColumn(name = "author_id", referencedColumnName = "id")} + ) + private Set authors = new HashSet<>(); + + public Long getId() { + return id; + } + + public void setId(Long 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; + } + + public Set getAuthors() { + return authors; + } + + public void setAuthors(Set authors) { + this.authors = authors; + } +} diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/run-test.sh b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/run-test.sh new file mode 100755 index 00000000..4132d822 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/run-test.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +docker-compose rm -v -f -s test-db-2 && docker-compose up -d +mysql -h 127.0.0.1 -P 3304 -u speedment -ppassword testdb2 diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/scripts/data.sql b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/scripts/data.sql new file mode 100644 index 00000000..130ddda3 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/scripts/data.sql @@ -0,0 +1,34 @@ +INSERT INTO publication(id, publication_type, publishing_date, title, version, pages, url) +VALUES (1, 'Book', '2008-7-04', 'Book 1', 2, 213, null), + (2, 'Book', '2009-7-04', 'Book 2', 2, 234, null), + (3, 'Book', '2010-7-04', 'Book 3', 2, 643, null), + (4, 'Book', '2011-7-04', 'Book 4', 2, 211, null), + (5, 'Book', '2012-7-04', 'Book 5', 2, 887, null), + (6, 'Book', '2013-7-04', 'Book 6', 2, 123, null), + (7, 'Book', '2014-7-04', 'Book 7', 2, 312, null), + (8, 'BlogPost', '2015-7-04', 'BlogPost 1', 2, null, 'www.speedment.com'), + (9, 'BlogPost', '2016-7-04', 'BlogPost 2', 2, null, 'www.speedment.com'), + (10, 'BlogPost', '2017-7-04', 'BlogPost 3', 2, null, 'www.speedment.com'), + (11, 'BlogPost', '2018-7-04', 'BlogPost 4', 2, null, 'www.speedment.com'), + (12, 'BlogPost', '2019-7-04', 'BlogPost 5', 2, null, 'www.speedment.com'); + +INSERT INTO author (id, firstname, lastname, version) +VALUES (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); + +INSERT INTO publication_author(publication_id, author_id) +VALUES (1, 1), + (2, 2), + (3, 3), + (4, 4), + (5, 5), + (6, 1), + (7, 2), + (8, 3), + (9, 4), + (10, 5), + (11, 1), + (12, 2); diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/scripts/schema.sql b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/scripts/schema.sql new file mode 100644 index 00000000..a63ae362 --- /dev/null +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/inheritance2/scripts/schema.sql @@ -0,0 +1,26 @@ +CREATE TABLE publication ( + id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, + publication_type VARCHAR(31), + publishing_date DATE NOT NULL, + title VARCHAR(255) NOT NULL, + version INT(6), + pages INT(6) UNSIGNED, + url VARCHAR(255), + 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 +); + +CREATE TABLE publication_author ( + publication_id INT(6) UNSIGNED, + author_id INT(6) UNSIGNED, + PRIMARY KEY (publication_id, author_id), + FOREIGN KEY (publication_id) REFERENCES publication(id), + FOREIGN KEY (author_id) REFERENCES author(id) +); diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/CountTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/CountTest.java similarity index 89% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/CountTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/CountTest.java index c34adee2..07c32405 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/CountTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/CountTest.java @@ -10,12 +10,11 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; -import com.speedment.jpastreamer.application.JPAStreamer; import com.speedment.jpastreamer.application.StreamSupplier; -import com.speedment.jpastreamer.integration.test.model.Film; -import com.speedment.jpastreamer.integration.test.model.Film$; +import com.speedment.jpastreamer.integration.test.standard.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film$; import org.junit.jupiter.api.Test; import java.util.List; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/JPAStreamerTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/JPAStreamerTest.java similarity index 92% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/JPAStreamerTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/JPAStreamerTest.java index c8152939..dab9154d 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/JPAStreamerTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/JPAStreamerTest.java @@ -10,7 +10,7 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; import com.speedment.jpastreamer.application.JPAStreamer; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ManyToManyTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ManyToManyTest.java similarity index 88% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ManyToManyTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ManyToManyTest.java index aeaaa238..59776e68 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ManyToManyTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ManyToManyTest.java @@ -10,10 +10,10 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; -import com.speedment.jpastreamer.integration.test.model.Actor; -import com.speedment.jpastreamer.integration.test.model.Actor$; +import com.speedment.jpastreamer.integration.test.standard.model.Actor; +import com.speedment.jpastreamer.integration.test.standard.model.Actor$; import org.junit.jupiter.api.Test; import java.util.Comparator; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ManyToOneTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ManyToOneTest.java similarity index 88% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ManyToOneTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ManyToOneTest.java index 8b86763a..c92c9abc 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ManyToOneTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ManyToOneTest.java @@ -10,10 +10,10 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; -import com.speedment.jpastreamer.integration.test.model.Film; -import com.speedment.jpastreamer.integration.test.model.Film$; +import com.speedment.jpastreamer.integration.test.standard.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film$; import org.junit.jupiter.api.Test; import java.util.Comparator; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/MapCustomClassTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/MapCustomClassTest.java similarity index 92% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/MapCustomClassTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/MapCustomClassTest.java index e279cb89..8f5e06ae 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/MapCustomClassTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/MapCustomClassTest.java @@ -10,9 +10,9 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; -import com.speedment.jpastreamer.integration.test.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film; import org.junit.jupiter.api.Test; import java.util.Optional; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/MapToIntTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/MapToIntTest.java similarity index 87% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/MapToIntTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/MapToIntTest.java index 4a190132..6349f5c7 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/MapToIntTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/MapToIntTest.java @@ -10,15 +10,14 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; -import com.speedment.jpastreamer.integration.test.model.Film; -import com.speedment.jpastreamer.integration.test.model.Film$; +import com.speedment.jpastreamer.integration.test.standard.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film$; import org.junit.jupiter.api.Test; import java.util.Comparator; import java.util.List; -import java.util.OptionalInt; import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/OneToManyTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/OneToManyTest.java similarity index 84% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/OneToManyTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/OneToManyTest.java index ec7af671..c1fe4d08 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/OneToManyTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/OneToManyTest.java @@ -10,13 +10,12 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; -import com.speedment.jpastreamer.integration.test.model.Film; -import com.speedment.jpastreamer.integration.test.model.Film$; -import com.speedment.jpastreamer.integration.test.model.Language; -import com.speedment.jpastreamer.integration.test.model.Language$; -import org.junit.jupiter.api.Disabled; +import com.speedment.jpastreamer.integration.test.standard.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film$; +import com.speedment.jpastreamer.integration.test.standard.model.Language; +import com.speedment.jpastreamer.integration.test.standard.model.Language$; import org.junit.jupiter.api.Test; import java.util.Comparator; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/PaginationTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/PaginationTest.java similarity index 88% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/PaginationTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/PaginationTest.java index f4da0530..8874fe1f 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/PaginationTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/PaginationTest.java @@ -10,11 +10,11 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; import com.speedment.jpastreamer.application.StreamSupplier; -import com.speedment.jpastreamer.integration.test.model.Film; -import com.speedment.jpastreamer.integration.test.model.Film$; +import com.speedment.jpastreamer.integration.test.standard.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film$; import org.junit.jupiter.api.Test; import java.util.Comparator; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/PartitionTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/PartitionTest.java similarity index 88% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/PartitionTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/PartitionTest.java index a4f9ba04..65f85639 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/PartitionTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/PartitionTest.java @@ -10,11 +10,11 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; import com.speedment.jpastreamer.application.StreamSupplier; -import com.speedment.jpastreamer.integration.test.model.Film; -import com.speedment.jpastreamer.integration.test.model.Film$; +import com.speedment.jpastreamer.integration.test.standard.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film$; import org.junit.jupiter.api.Test; import java.util.List; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/PivotTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/PivotTest.java similarity index 84% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/PivotTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/PivotTest.java index 10e46e6e..c1a02897 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/PivotTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/PivotTest.java @@ -10,11 +10,11 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; -import com.speedment.jpastreamer.integration.test.model.Actor; -import com.speedment.jpastreamer.integration.test.model.Actor$; -import com.speedment.jpastreamer.integration.test.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Actor; +import com.speedment.jpastreamer.integration.test.standard.model.Actor$; +import com.speedment.jpastreamer.integration.test.standard.model.Film; import org.junit.jupiter.api.Test; import java.util.Map; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ProjectionTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ProjectionTest.java similarity index 91% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ProjectionTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ProjectionTest.java index dfd4796e..9d08f067 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ProjectionTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ProjectionTest.java @@ -10,20 +10,18 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; import com.speedment.jpastreamer.application.StreamSupplier; -import com.speedment.jpastreamer.integration.test.model.Film; -import com.speedment.jpastreamer.integration.test.model.Film$; +import com.speedment.jpastreamer.integration.test.standard.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film$; import com.speedment.jpastreamer.projection.Projection; import com.speedment.jpastreamer.streamconfiguration.StreamConfiguration; -import jakarta.persistence.Tuple; import org.junit.jupiter.api.Test; import java.util.List; import java.util.stream.Collectors; -import static java.util.Comparator.*; import static org.junit.jupiter.api.Assertions.*; public class ProjectionTest extends JPAStreamerTest { diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ReorderTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ReorderTest.java similarity index 98% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ReorderTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ReorderTest.java index eb5ce426..60513501 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/ReorderTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/ReorderTest.java @@ -10,11 +10,11 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; import com.speedment.jpastreamer.application.StreamSupplier; -import com.speedment.jpastreamer.integration.test.model.Film; -import com.speedment.jpastreamer.integration.test.model.Film$; +import com.speedment.jpastreamer.integration.test.standard.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film$; import org.junit.jupiter.api.Test; import java.util.Comparator; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/SquashTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/SquashTest.java similarity index 93% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/SquashTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/SquashTest.java index 6e414666..58fa3963 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/SquashTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/SquashTest.java @@ -10,11 +10,11 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; import com.speedment.jpastreamer.application.StreamSupplier; -import com.speedment.jpastreamer.integration.test.model.Film; -import com.speedment.jpastreamer.integration.test.model.Film$; +import com.speedment.jpastreamer.integration.test.standard.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film$; import org.junit.jupiter.api.Test; import java.util.Comparator; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/TermOpTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/TermOpTest.java similarity index 91% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/TermOpTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/TermOpTest.java index b850a209..2394edf7 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/TermOpTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/TermOpTest.java @@ -10,10 +10,10 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; -import com.speedment.jpastreamer.integration.test.model.Film; -import com.speedment.jpastreamer.integration.test.model.Film$; +import com.speedment.jpastreamer.integration.test.standard.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film$; import org.junit.jupiter.api.Test; import java.util.Optional; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/UnionTest.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/UnionTest.java similarity index 89% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/UnionTest.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/UnionTest.java index 65019f33..4eb010f5 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/UnionTest.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/UnionTest.java @@ -10,12 +10,11 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test; +package com.speedment.jpastreamer.integration.test.standard; -import com.speedment.jpastreamer.application.JPAStreamer; import com.speedment.jpastreamer.application.StreamSupplier; -import com.speedment.jpastreamer.integration.test.model.Film; -import com.speedment.jpastreamer.integration.test.model.Film$; +import com.speedment.jpastreamer.integration.test.standard.model.Film; +import com.speedment.jpastreamer.integration.test.standard.model.Film$; import com.speedment.jpastreamer.streamconfiguration.StreamConfiguration; import org.junit.jupiter.api.Test; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/Actor.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/Actor.java similarity index 97% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/Actor.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/Actor.java index 290f21f1..b3a5a0ad 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/Actor.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/Actor.java @@ -10,7 +10,7 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test.model; +package com.speedment.jpastreamer.integration.test.standard.model; import jakarta.persistence.*; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/Film.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/Film.java similarity index 94% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/Film.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/Film.java index 1661a8fd..b46578f5 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/Film.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/Film.java @@ -10,14 +10,15 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test.model; +package com.speedment.jpastreamer.integration.test.standard.model; -import com.speedment.jpastreamer.integration.test.model.groups.GroupA; -import com.speedment.jpastreamer.integration.test.model.groups.GroupB; +import com.speedment.jpastreamer.integration.test.standard.model.groups.GroupA; +import com.speedment.jpastreamer.integration.test.standard.model.groups.GroupB; import jakarta.persistence.*; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.Size; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; import java.io.Serializable; import java.time.LocalDateTime; import java.util.ArrayList; @@ -45,11 +46,11 @@ public Film(Integer filmId, String title) { private Integer filmId; @Column(name = "title", nullable = false, columnDefinition = "varchar(255)") - //@NotEmpty(message = "Title may not be empty", groups = {GroupA.class, GroupB.class}) - @NotNull(message = "Title may not be null", groups = {GroupA.class, GroupB.class}) + @NotEmpty(message = "Title may not be empty", groups = {GroupA.class, GroupB.class}) private String title; - + @Column(name = "description", nullable = false, columnDefinition = "text") + @NotBlank private String description; @ManyToOne diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/Language.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/Language.java similarity index 97% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/Language.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/Language.java index 5bdf45d6..39d55c88 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/Language.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/Language.java @@ -10,7 +10,7 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test.model; +package com.speedment.jpastreamer.integration.test.standard.model; import jakarta.persistence.*; diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/groups/GroupA.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/groups/GroupA.java similarity index 88% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/groups/GroupA.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/groups/GroupA.java index 90b5e2f7..dd4695f0 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/groups/GroupA.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/groups/GroupA.java @@ -10,7 +10,7 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test.model.groups; +package com.speedment.jpastreamer.integration.test.standard.model.groups; public interface GroupA { } diff --git a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/groups/GroupB.java b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/groups/GroupB.java similarity index 88% rename from integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/groups/GroupB.java rename to integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/groups/GroupB.java index daf01777..45bd4c4e 100644 --- a/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/model/groups/GroupB.java +++ b/integration-tests/src/test/java/com/speedment/jpastreamer/integration/test/standard/model/groups/GroupB.java @@ -10,6 +10,6 @@ * * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE */ -package com.speedment.jpastreamer.integration.test.model.groups; +package com.speedment.jpastreamer.integration.test.standard.model.groups; public interface GroupB { } diff --git a/integration-tests/src/test/resources/META-INF/persistence.xml b/integration-tests/src/test/resources/META-INF/persistence.xml index f707a062..39348bd5 100644 --- a/integration-tests/src/test/resources/META-INF/persistence.xml +++ b/integration-tests/src/test/resources/META-INF/persistence.xml @@ -18,7 +18,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"> - + Test org.hibernate.jpa.HibernatePersistenceProvider @@ -35,4 +35,40 @@ + + + Inheritance Test + org.hibernate.jpa.HibernatePersistenceProvider + + + + + + + + + + + + + + + + Inheritance Test 2 + org.hibernate.jpa.HibernatePersistenceProvider + + + + + + + + + + + + + + + diff --git a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java index 0253d4e4..d1aeaaab 100644 --- a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java +++ b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/InternalFieldGeneratorProcessor.java @@ -29,12 +29,14 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Lob; +import jakarta.persistence.MappedSuperclass; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.Messager; import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.RoundEnvironment; import javax.lang.model.element.*; +import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; @@ -96,6 +98,7 @@ public boolean process(Set annotations, RoundEnvironment } Set entities = roundEnv.getElementsAnnotatedWith(Entity.class); + Set superClasses = roundEnv.getElementsAnnotatedWith(MappedSuperclass.class); if (entities.isEmpty()) { messager.printMessage(Diagnostic.Kind.WARNING, "[JPAStreamer Field Generator Processor] Found no classes annotated with jakarta.persistence.Entity.\n"); @@ -124,13 +127,34 @@ public boolean process(Set annotations, RoundEnvironment } else { annotatedElementPackageName = packageElement.getQualifiedName().toString(); } - + String packageName = processingEnv.getOptions().getOrDefault("jpaStreamerPackage", annotatedElementPackageName); String qualifiedGenEntityName = packageName + "." + genEntityName; JavaFileObject builderFile = processingEnv.getFiler().createSourceFile(qualifiedGenEntityName); Writer writer = builderFile.openWriter(); - generateFields(ae, entityName, genEntityName, packageName, writer); + + TypeMirror type = ae.asType(); + List typeMirrors = processingEnvironment.getTypeUtils().directSupertypes(type); + + Optional superClass = typeMirrors.stream() + .filter(DeclaredType.class::isInstance) + .map(DeclaredType.class::cast) + .map(DeclaredType::asElement) + .filter(e -> e.getAnnotation(MappedSuperclass.class) != null || e.getAnnotation(Entity.class ) != null) + .map(e -> e.getSimpleName().toString()) + .findFirst(); + + Optional superClassElement = Optional.empty(); + if (superClass.isPresent()) { + // Entity should inherit fields from the superclass, retrieve element + superClassElement = Stream.concat(entities.stream(), superClasses.stream()) + .filter(sc -> sc.getKind() == ElementKind.CLASS) + .filter(sc -> sc.getSimpleName().toString().equals(superClass.get())) + .findFirst(); + } + + generateFields(ae, entityName, genEntityName, packageName, superClassElement, writer); writer.close(); } catch (IOException e) { e.printStackTrace(); @@ -140,8 +164,13 @@ public boolean process(Set annotations, RoundEnvironment return true; } - void generateFields(final Element annotatedElement, final String entityName, final String genEntityName, final String packageName, final Writer writer) throws IOException { - + void generateFields(final Element annotatedElement, + final String entityName, + final String genEntityName, + final String packageName, + final Optional superClass, + final Writer writer) throws IOException { + final Map getters = annotatedElement.getEnclosedElements().stream() .filter(ee -> ee.getKind() == ElementKind.METHOD) // Only consider methods with no parameters @@ -158,8 +187,15 @@ void generateFields(final Element annotatedElement, final String entityName, fin .map(Formatting::lcfirst) .collect(toSet()); + Stream fields = annotatedElement.getEnclosedElements().stream(); + + if (superClass.isPresent()) { + // Add parent fields + fields = Stream.concat(fields, superClass.get().getEnclosedElements().stream()); + } + // Retrieve all declared non-final instance fields of the annotated class - Map enclosedFields = annotatedElement.getEnclosedElements().stream() + Map enclosedFields = fields .filter(ee -> ee.getKind().isField() && !ee.getModifiers().contains(Modifier.STATIC) // Ignore static fields && !ee.getModifiers().contains(Modifier.FINAL)) // Ignore final fields @@ -168,8 +204,8 @@ void generateFields(final Element annotatedElement, final String entityName, fin Function.identity(), ee -> findGetter(ee, getters, isGetters, shortName(entityName), lombokGetterAvailable(annotatedElement, ee))) ); - - final File file = generatedEntity(enclosedFields, entityName, genEntityName, packageName); + + final File file = generatedEntity(annotatedElement, enclosedFields, entityName, genEntityName, packageName); writer.write(generator.on(file).orElseThrow(NoSuchElementException::new)); } @@ -220,7 +256,11 @@ private String findGetter(final Element field, return lambdaName + " -> {throw new " + IllegalJavaBeanException.class.getSimpleName() + "(" + entityName + ".class, \"" + fieldName + "\");}"; } - private File generatedEntity(final Map enclosedFields, final String entityName, final String genEntityName, final String packageName) { + private File generatedEntity(final Element annotatedElement, + final Map enclosedFields, + final String entityName, + final String genEntityName, + final String packageName) { final File file = packageName.isEmpty() ? File.of(genEntityName + ".java") : File.of(packageName + "/" + genEntityName + ".java"); @@ -345,7 +385,6 @@ private String trimAnnotations(Element field) { final String fieldType = field.asType().toString(); final List annotations = field.getAnnotationMirrors().stream() .map(Object::toString) - .filter(s -> !(s.contains("jakarta"))) .collect(Collectors.toList()); if (annotations.isEmpty() && !fieldType.contains("@")) { final int index = fieldType.lastIndexOf(' '); @@ -353,10 +392,12 @@ private String trimAnnotations(Element field) { } String result = fieldType; for (String annotation : annotations) { - result = result.replace(annotation, ""); + // ensure that trailing commas are removed + result = result.contains(annotation + ',') ? + result.replace(annotation + ',', "") : + result.replace(annotation, ""); } result = result.replace(" ", ""); - result = result.replace(",", ""); return result; } diff --git a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/pom.xml b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/pom.xml index f4a43eff..ab14e22d 100644 --- a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/pom.xml +++ b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/pom.xml @@ -60,9 +60,9 @@ - javax.validation - validation-api - 2.0.1.Final + org.hibernate.validator + hibernate-validator + 8.0.1.Final diff --git a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/BlogPost.java b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/BlogPost.java new file mode 100644 index 00000000..3836fdf2 --- /dev/null +++ b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/BlogPost.java @@ -0,0 +1,22 @@ +package com.speedment.jpastreamer.fieldgenerator.test; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +@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; + } + +} diff --git a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/Book.java b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/Book.java new file mode 100644 index 00000000..044aa1d3 --- /dev/null +++ b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/Book.java @@ -0,0 +1,21 @@ +package com.speedment.jpastreamer.fieldgenerator.test; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +@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; + } +} diff --git a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/Film.java b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/Film.java index 1fc7ef21..2ad837d4 100644 --- a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/Film.java +++ b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/Film.java @@ -13,9 +13,11 @@ package com.speedment.jpastreamer.fieldgenerator.test; import jakarta.persistence.*; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; import java.sql.Time; import java.time.LocalDateTime; import java.util.*; @@ -37,6 +39,7 @@ public class Film { private String title; @Column(name = "description", nullable = false, columnDefinition = "text") + @NotBlank private String description; @Column(name = "audienceScore", nullable = true, columnDefinition = "decimal(4,2)") @@ -73,6 +76,9 @@ public class Film { private Language originalLanguage; @Column(name = "complex_column") + @NotBlank + @NotEmpty + @NotNull private Map>, Integer>, Long> complexColumn; @Column(name = "rental_duration", columnDefinition = "smallint(5)") diff --git a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/Publication.java b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/Publication.java new file mode 100644 index 00000000..36e74a23 --- /dev/null +++ b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/Publication.java @@ -0,0 +1,56 @@ +package com.speedment.jpastreamer.fieldgenerator.test; + +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; + } +} diff --git a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/User2.java b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/User2.java index 7f7b4fcd..c103855d 100644 --- a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/User2.java +++ b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/com/speedment/jpastreamer/fieldgenerator/test/User2.java @@ -13,21 +13,21 @@ package com.speedment.jpastreamer.fieldgenerator.test; import jakarta.persistence.*; -import javax.validation.constraints.NotEmpty; import java.io.Serializable; +import jakarta.validation.constraints.NotEmpty; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; + @Entity @Table(name="user") @Data @Builder @NoArgsConstructor @AllArgsConstructor - public class User2 implements Serializable{ @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_shared") diff --git a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/module-info.java b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/module-info.java index 04c28657..4bc04091 100644 --- a/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/module-info.java +++ b/jpastreamer.fieldgenerator/jpastreamer.fieldgenerator.test/src/main/java/module-info.java @@ -17,7 +17,7 @@ requires jpastreamer.fieldgenerator.standard; requires jakarta.persistence; requires lombok; - requires java.validation; + requires jakarta.validation; requires transitive java.sql; requires transitive jpastreamer.field;