add tests reflecting things in Jakarta Data TCK

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-04-04 10:50:41 +02:00
parent e748619dd6
commit ff0e676825
4 changed files with 14 additions and 0 deletions

View File

@ -25,6 +25,9 @@ public interface Bookshop extends CrudRepository<Book,String> {
@Query("select count(this) where this.title like ?1 order by this.isbn") @Query("select count(this) where this.title like ?1 order by this.isbn")
long count2(String title); long count2(String title);
@Query("select count(this)")
long countAll();
@Query("where isbn in :isbns and type = Book") @Query("where isbn in :isbns and type = Book")
List<Book> books(List<String> isbns); List<Book> books(List<String> isbns);

View File

@ -14,6 +14,8 @@ import java.util.Set;
@Entity @Entity
@Table(name = "books") @Table(name = "books")
public class Book { public class Book {
public enum Type { Book, Magazine, Journal }
@Id @Id
String isbn; String isbn;
@ -34,6 +36,8 @@ public class Book {
int pages; int pages;
Type type;
public Book(String isbn, String title, String text) { public Book(String isbn, String title, String text) {
this.isbn = isbn; this.isbn = isbn;
this.title = title; this.title = title;

View File

@ -4,10 +4,14 @@ import jakarta.data.repository.Query;
import jakarta.data.repository.Repository; import jakarta.data.repository.Repository;
import java.util.List; import java.util.List;
import java.util.Set;
@Repository(dataStore = "myds") @Repository(dataStore = "myds")
public interface BookAuthorRepository$ extends BookAuthorRepository { public interface BookAuthorRepository$ extends BookAuthorRepository {
@Override @Override
@Query("from Book where title like :title") @Query("from Book where title like :title")
List<Book> findByTitleLike(String title); List<Book> findByTitleLike(String title);
@Override
@Query("from Book where type in :types")
List<Book> findByTypeIn(Set<Book.Type> types);
} }

View File

@ -17,14 +17,17 @@ import jakarta.data.repository.Repository;
import jakarta.data.repository.Save; import jakarta.data.repository.Save;
import jakarta.data.repository.Update; import jakarta.data.repository.Update;
import org.hibernate.StatelessSession; import org.hibernate.StatelessSession;
import org.hibernate.processor.test.data.namedquery.Book.Type;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
@Repository(dataStore = "myds") @Repository(dataStore = "myds")
public interface BookAuthorRepository { public interface BookAuthorRepository {
List<Book> findByTitleLike(String title); List<Book> findByTitleLike(String title);
List<Book> findByTypeIn(Set<Type> types);
} }