-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for queries defined in intermediate classes
for our work on the Jakarta Data TCK Signed-off-by: Gavin King <gavin@hibernate.org>
- Loading branch information
Showing
7 changed files
with
260 additions
and
79 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...l-generator/src/jakartaData/java/org/hibernate/processor/test/data/namedquery/Author.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,21 @@ | ||
package org.hibernate.processor.test.data.namedquery; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.ManyToMany; | ||
|
||
import java.util.Set; | ||
|
||
@Entity | ||
public class Author { | ||
@Id | ||
String ssn; | ||
String name; | ||
|
||
// @Embedded | ||
// Address address; | ||
|
||
@ManyToMany | ||
Set<Book> books; | ||
} | ||
|
43 changes: 43 additions & 0 deletions
43
...del-generator/src/jakartaData/java/org/hibernate/processor/test/data/namedquery/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,43 @@ | ||
package org.hibernate.processor.test.data.namedquery; | ||
|
||
import jakarta.persistence.Basic; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.ManyToMany; | ||
import jakarta.persistence.Table; | ||
import org.hibernate.annotations.NaturalId; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDate; | ||
import java.util.Set; | ||
|
||
@Entity | ||
@Table(name = "books") | ||
public class Book { | ||
@Id | ||
String isbn; | ||
|
||
@NaturalId | ||
@Basic(optional = false) | ||
String title; | ||
|
||
@Basic(optional = false) | ||
String text; | ||
|
||
@NaturalId | ||
LocalDate publicationDate; | ||
|
||
@ManyToMany(mappedBy = "books") | ||
Set<Author> authors; | ||
|
||
BigDecimal price; | ||
|
||
int pages; | ||
|
||
public Book(String isbn, String title, String text) { | ||
this.isbn = isbn; | ||
this.title = title; | ||
this.text = text; | ||
} | ||
Book() {} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../jakartaData/java/org/hibernate/processor/test/data/namedquery/BookAuthorRepository$.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,13 @@ | ||
package org.hibernate.processor.test.data.namedquery; | ||
|
||
import jakarta.data.repository.Query; | ||
import jakarta.data.repository.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository(dataStore = "myds") | ||
public interface BookAuthorRepository$ extends BookAuthorRepository { | ||
@Override | ||
@Query("from Book where title like :title") | ||
List<Book> findByTitleLike(String title); | ||
} |
30 changes: 30 additions & 0 deletions
30
...c/jakartaData/java/org/hibernate/processor/test/data/namedquery/BookAuthorRepository.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,30 @@ | ||
package org.hibernate.processor.test.data.namedquery; | ||
|
||
import jakarta.data.Limit; | ||
import jakarta.data.Order; | ||
import jakarta.data.Sort; | ||
import jakarta.data.page.CursoredPage; | ||
import jakarta.data.page.Page; | ||
import jakarta.data.page.PageRequest; | ||
import jakarta.data.repository.By; | ||
import jakarta.data.repository.Delete; | ||
import jakarta.data.repository.Find; | ||
import jakarta.data.repository.Insert; | ||
import jakarta.data.repository.OrderBy; | ||
import jakarta.data.repository.Param; | ||
import jakarta.data.repository.Query; | ||
import jakarta.data.repository.Repository; | ||
import jakarta.data.repository.Save; | ||
import jakarta.data.repository.Update; | ||
import org.hibernate.StatelessSession; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
@Repository(dataStore = "myds") | ||
public interface BookAuthorRepository { | ||
List<Book> findByTitleLike(String title); | ||
} |
36 changes: 36 additions & 0 deletions
36
...tor/src/jakartaData/java/org/hibernate/processor/test/data/namedquery/NamedQueryTest.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,36 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.processor.test.data.namedquery; | ||
|
||
import org.hibernate.processor.test.util.CompilationTest; | ||
import org.hibernate.processor.test.util.WithClasses; | ||
import org.junit.Test; | ||
|
||
import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor; | ||
import static org.hibernate.processor.test.util.TestUtil.assertNoMetamodelClassGeneratedFor; | ||
import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString; | ||
|
||
/** | ||
* @author Gavin King | ||
*/ | ||
public class NamedQueryTest extends CompilationTest { | ||
@Test | ||
@WithClasses({ Author.class, Book.class, BookAuthorRepository.class, BookAuthorRepository$.class }) | ||
public void test() { | ||
System.out.println( getMetaModelSourceAsString( Author.class ) ); | ||
System.out.println( getMetaModelSourceAsString( Book.class ) ); | ||
System.out.println( getMetaModelSourceAsString( Author.class, true ) ); | ||
System.out.println( getMetaModelSourceAsString( Book.class, true ) ); | ||
System.out.println( getMetaModelSourceAsString( BookAuthorRepository.class ) ); | ||
assertMetamodelClassGeneratedFor( Author.class, true ); | ||
assertMetamodelClassGeneratedFor( Book.class, true ); | ||
assertMetamodelClassGeneratedFor( Author.class ); | ||
assertMetamodelClassGeneratedFor( Book.class ); | ||
assertMetamodelClassGeneratedFor( BookAuthorRepository.class ); | ||
assertNoMetamodelClassGeneratedFor( BookAuthorRepository$.class ); | ||
} | ||
} |
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
Oops, something went wrong.