77import jakarta .persistence .Entity ;
88import jakarta .persistence .Id ;
99import jakarta .persistence .metamodel .SingularAttribute ;
10- import org .hibernate .query .Order ;
11- import org .hibernate .query .Restriction ;
12- import org .hibernate .query .range .Range ;
1310import org .hibernate .testing .orm .junit .DomainModel ;
1411import org .hibernate .testing .orm .junit .SessionFactory ;
1512import org .hibernate .testing .orm .junit .SessionFactoryScope ;
1613import org .junit .jupiter .api .Test ;
1714
1815import java .util .List ;
1916
17+ import static org .hibernate .query .Order .asc ;
18+ import static org .hibernate .query .Order .desc ;
19+ import static org .hibernate .query .Restriction .all ;
20+ import static org .hibernate .query .Restriction .any ;
21+ import static org .hibernate .query .Restriction .between ;
22+ import static org .hibernate .query .Restriction .contains ;
23+ import static org .hibernate .query .Restriction .endWith ;
24+ import static org .hibernate .query .Restriction .equal ;
25+ import static org .hibernate .query .Restriction .equalIgnoringCase ;
26+ import static org .hibernate .query .Restriction .greaterThan ;
27+ import static org .hibernate .query .Restriction .in ;
28+ import static org .hibernate .query .Restriction .like ;
29+ import static org .hibernate .query .Restriction .restrict ;
30+ import static org .hibernate .query .Restriction .unrestricted ;
31+ import static org .hibernate .query .range .Range .singleCaseInsensitiveValue ;
2032import static org .junit .jupiter .api .Assertions .assertEquals ;
2133
2234@ SessionFactory
@@ -41,81 +53,81 @@ void test(SessionFactoryScope scope) {
4153
4254 Book book = scope .fromSession ( session ->
4355 session .createSelectionQuery ( "from Book" , Book .class )
44- .addRestriction ( Restriction . equal ( isbn , "9781932394153" ) )
56+ .addRestriction ( equal ( isbn , "9781932394153" ) )
4557 .getSingleResult () );
4658 assertEquals ( "Hibernate in Action" , book .title );
4759 List <Book > books = scope .fromSession ( session ->
4860 session .createSelectionQuery ( "from Book" , Book .class )
49- .addRestriction ( Restriction . like ( title , "%Hibernate%" ) )
50- .setOrder ( Order . desc ( title ) )
61+ .addRestriction ( like ( title , "%Hibernate%" ) )
62+ .setOrder ( desc ( title ) )
5163 .getResultList () );
5264 assertEquals ( 2 , books .size () );
5365 assertEquals ( "Java Persistence with Hibernate" , books .get (0 ).title );
5466 assertEquals ( "Hibernate in Action" , books .get (1 ).title );
5567 List <Book > booksByIsbn = scope .fromSession ( session ->
5668 session .createSelectionQuery ( "from Book" , Book .class )
57- .addRestriction ( Restriction . in ( isbn , List .of ("9781932394153" , "9781617290459" ) ) )
58- .setOrder ( Order . asc ( title ) )
69+ .addRestriction ( in ( isbn , List .of ("9781932394153" , "9781617290459" ) ) )
70+ .setOrder ( asc ( title ) )
5971 .getResultList () );
6072 assertEquals ( 2 , booksByIsbn .size () );
6173 assertEquals ( "Hibernate in Action" , booksByIsbn .get (0 ).title );
6274 assertEquals ( "Java Persistence with Hibernate" , booksByIsbn .get (1 ).title );
6375 List <Book > booksByPages = scope .fromSession ( session ->
6476 session .createSelectionQuery ( "from Book" , Book .class )
65- .addRestriction ( Restriction . greaterThan ( pages , 500 ) )
77+ .addRestriction ( greaterThan ( pages , 500 ) )
6678 .getResultList () );
6779 assertEquals ( 1 , booksByPages .size () );
6880 List <Book > booksByPageRange = scope .fromSession ( session ->
6981 session .createSelectionQuery ( "from Book" , Book .class )
70- .addRestriction ( Restriction . between ( pages , 150 , 400 ) )
82+ .addRestriction ( between ( pages , 150 , 400 ) )
7183 .getResultList () );
7284 assertEquals ( 1 , booksByPageRange .size () );
7385 Book bookByTitle = scope .fromSession ( session ->
7486 session .createSelectionQuery ( "from Book" , Book .class )
75- .addRestriction ( Restriction . equalIgnoringCase ( title , "hibernate in action" ) )
87+ .addRestriction ( equalIgnoringCase ( title , "hibernate in action" ) )
7688 .getSingleResultOrNull () );
7789 assertEquals ( "9781932394153" , bookByTitle .isbn );
7890 Book bookByTitleUnsafe = scope .fromSession ( session ->
7991 session .createSelectionQuery ( "from Book" , Book .class )
80- .addRestriction ( Restriction . restrict ( Book .class , "title" ,
81- Range . singleCaseInsensitiveValue ("hibernate in action" ) ) )
92+ .addRestriction ( restrict ( Book .class , "title" ,
93+ singleCaseInsensitiveValue ("hibernate in action" ) ) )
8294 .getSingleResultOrNull () );
8395 assertEquals ( "9781932394153" , bookByTitleUnsafe .isbn );
8496 List <Book > allBooks = scope .fromSession ( session ->
8597 session .createSelectionQuery ( "from Book" , Book .class )
86- .addRestriction ( Restriction . unrestricted () )
98+ .addRestriction ( unrestricted () )
8799 .getResultList () );
88100 assertEquals ( 2 , allBooks .size () );
89101 List <Book > noBooks = scope .fromSession ( session ->
90102 session .createSelectionQuery ( "from Book" , Book .class )
91- .addRestriction ( Restriction . unrestricted ().negated () )
103+ .addRestriction ( unrestricted ().negated () )
92104 .getResultList () );
93105 assertEquals ( 0 , noBooks .size () );
94106 List <Book > books1 = scope .fromSession ( session ->
95107 session .createSelectionQuery ( "from Book" , Book .class )
96- .addRestriction ( Restriction . endWith (title , "Hibernate" ) )
108+ .addRestriction ( endWith (title , "Hibernate" ) )
97109 .getResultList () );
98110 assertEquals ( 1 , books1 .size () );
99111 List <Book > books2 = scope .fromSession ( session ->
100112 session .createSelectionQuery ( "from Book" , Book .class )
101- .addRestriction ( Restriction . like (title , "*Hibernat?" , false , '?' , '*' ) )
113+ .addRestriction ( like (title , "*Hibernat?" , false , '?' , '*' ) )
102114 .getResultList () );
103115 assertEquals ( 1 , books2 .size () );
104116 List <Book > books3 = scope .fromSession ( session ->
105117 session .createSelectionQuery ( "from Book" , Book .class )
106- .addRestriction ( Restriction . contains (title , "Hibernate" ) )
118+ .addRestriction ( contains (title , "Hibernate" ) )
107119 .getResultList () );
108120 assertEquals ( 2 , books3 .size () );
109121 List <Book > booksByTitleAndIsbn = scope .fromSession ( session ->
110122 session .createSelectionQuery ( "from Book" , Book .class )
111- .addRestriction ( Restriction . all ( Restriction . contains (title , "Hibernate" ),
112- Restriction . equal ( isbn , "9781932394153" ) ) )
123+ .addRestriction ( all ( contains (title , "Hibernate" ),
124+ equal ( isbn , "9781932394153" ) ) )
113125 .getResultList () );
114126 assertEquals ( 1 , booksByTitleAndIsbn .size () );
115127 List <Book > booksByTitleOrIsbn = scope .fromSession ( session ->
116128 session .createSelectionQuery ( "from Book" , Book .class )
117- .addRestriction ( Restriction . any ( Restriction . contains (title , "Hibernate" ),
118- Restriction . equal ( isbn , "9781932394153" ) ) )
129+ .addRestriction ( any ( contains (title , "Hibernate" ),
130+ equal ( isbn , "9781932394153" ) ) )
119131 .getResultList () );
120132 assertEquals ( 2 , booksByTitleOrIsbn .size () );
121133 }
0 commit comments