Skip to content

Commit 4bfd62c

Browse files
committed
fix deprecations in reactive tests
1 parent b888ad6 commit 4bfd62c

File tree

57 files changed

+225
-230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+225
-230
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchFetchTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ protected Collection<Class<?>> annotatedEntities() {
5454
@AfterEach
5555
public void cleanDb(VertxTestContext context) {
5656
test( context, getSessionFactory()
57-
.withTransaction( s -> s.createQuery( "delete from Element" ).executeUpdate()
58-
.thenCompose( v -> s.createQuery( "delete from Node" ).executeUpdate() ) ) );
57+
.withTransaction( s -> s.createMutationQuery( "delete from Element" ).executeUpdate()
58+
.thenCompose( v -> s.createMutationQuery( "delete from Node" ).executeUpdate() ) ) );
5959
}
6060

6161
@Test
@@ -71,7 +71,7 @@ public void testQuery(VertxTestContext context) {
7171
test( context, getSessionFactory()
7272
.withTransaction( s -> s.persist( basik ) )
7373
.thenCompose( v -> openSession() )
74-
.thenCompose( s -> s.createQuery( "from Node n order by id", Node.class )
74+
.thenCompose( s -> s.createSelectionQuery( "from Node n order by id", Node.class )
7575
.getResultList()
7676
.thenCompose( list -> {
7777
assertEquals( list.size(), 2 );
@@ -88,7 +88,7 @@ public void testQuery(VertxTestContext context) {
8888
} )
8989
)
9090
.thenCompose( v -> openSession() )
91-
.thenCompose( s -> s.createQuery( "from Element e order by id", Element.class )
91+
.thenCompose( s -> s.createSelectionQuery( "from Element e order by id", Element.class )
9292
.getResultList()
9393
.thenCompose( list -> {
9494
assertEquals( list.size(), 5 );
@@ -147,7 +147,7 @@ public void testWithCollection(VertxTestContext context) {
147147
.withTransaction( s -> s.persist( node ) )
148148
.thenCompose( v -> getSessionFactory()
149149
.withTransaction( s -> s
150-
.createQuery( "from Node n order by id", Node.class )
150+
.createSelectionQuery( "from Node n order by id", Node.class )
151151
.getResultList()
152152
.thenCompose( list -> {
153153
assertEquals( list.size(), 1 );

hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchQueryOnConnectionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public CompletionStage<List<List<Object[]>>> doBatchInserts(VertxTestContext con
119119
return stage
120120
.thenCompose( ignore -> openSession() )
121121
.thenCompose( s -> s
122-
.createQuery( "select count(*) from DataPoint" ).getSingleResult()
123-
.thenAccept( result -> assertEquals( (long) nEntities, result ) ) )
122+
.createSelectionQuery( "select count(*) from DataPoint", Long.class ).getSingleResult()
123+
.thenAccept( result -> assertEquals( nEntities, result ) ) )
124124
.thenApply( v -> paramsBatches );
125125
}
126126

hibernate-reactive-core/src/test/java/org/hibernate/reactive/BatchingConnectionTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void testBatchingWithPersistAll(VertxTestContext context) {
7676
)
7777
// Auto-flush
7878
.thenCompose( v -> s
79-
.createQuery( "select name from GuineaPig" )
79+
.createSelectionQuery( "select name from GuineaPig", String.class )
8080
.getResultList()
8181
.thenAccept( names -> {
8282
assertThat( names ).containsExactlyInAnyOrder( "One", "Two", "Three" );
@@ -101,7 +101,7 @@ public void testBatching(VertxTestContext context) {
101101
.thenCompose( v -> s.persist( new GuineaPig(22, "Two") ) )
102102
.thenCompose( v -> s.persist( new GuineaPig(33, "Three") ) )
103103
// Auto-flush
104-
.thenCompose( v -> s.createQuery("select name from GuineaPig")
104+
.thenCompose( v -> s.createSelectionQuery("select name from GuineaPig", String.class )
105105
.getResultList()
106106
.thenAccept( names -> {
107107
assertThat( names ).containsExactlyInAnyOrder( "One", "Two", "Three" );
@@ -114,10 +114,10 @@ public void testBatching(VertxTestContext context) {
114114
)
115115
)
116116
.thenCompose( v -> openSession() )
117-
.thenCompose( s -> s.<GuineaPig>createQuery("from GuineaPig")
117+
.thenCompose( s -> s.createSelectionQuery("from GuineaPig", GuineaPig.class)
118118
.getResultList()
119119
.thenAccept( list -> list.forEach( pig -> pig.setName("Zero") ) )
120-
.thenCompose( v -> s.<Long>createQuery("select count(*) from GuineaPig where name='Zero'")
120+
.thenCompose( v -> s.createSelectionQuery("select count(*) from GuineaPig where name='Zero'", Long.class)
121121
.getSingleResult()
122122
.thenAccept( count -> {
123123
assertEquals( 3L, count);
@@ -130,10 +130,10 @@ public void testBatching(VertxTestContext context) {
130130
} )
131131
) )
132132
.thenCompose( v -> openSession() )
133-
.thenCompose( s -> s.<GuineaPig>createQuery("from GuineaPig")
133+
.thenCompose( s -> s.createSelectionQuery("from GuineaPig", GuineaPig.class)
134134
.getResultList()
135135
.thenCompose( list -> loop( list, s::remove ) )
136-
.thenCompose( v -> s.<Long>createQuery("select count(*) from GuineaPig")
136+
.thenCompose( v -> s.createSelectionQuery("select count(*) from GuineaPig", Long.class)
137137
.getSingleResult()
138138
.thenAccept( count -> {
139139
assertEquals( 0L, count);

hibernate-reactive-core/src/test/java/org/hibernate/reactive/CacheTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testCacheWithHQL(VertxTestContext context) {
6464
} )
6565
//populate the cache
6666
.thenCompose( v -> getSessionFactory().withSession(
67-
s -> s.createQuery( "from Named" ).getResultList()
67+
s -> s.createSelectionQuery( "from Named", Named.class ).getResultList()
6868
.thenAccept( list -> assertEquals( 3, list.size() ) )
6969
) )
7070
.thenAccept( v -> {
@@ -83,7 +83,7 @@ public void testCacheWithHQL(VertxTestContext context) {
8383
) )
8484
//change the database
8585
.thenCompose( v -> getSessionFactory().withSession(
86-
s -> s.createQuery( "update Named set name='x'||name" ).executeUpdate()
86+
s -> s.createMutationQuery( "update Named set name='x'||name" ).executeUpdate()
8787
) )
8888
.thenAccept( v -> {
8989
assertFalse( cache.contains( Named.class, 1 ) );
@@ -111,7 +111,7 @@ public void testCacheWithHQL(VertxTestContext context) {
111111
} )
112112
//repopulate the cache
113113
.thenCompose( v -> getSessionFactory().withSession(
114-
s -> s.createQuery( "from Named" ).getResultList()
114+
s -> s.createSelectionQuery( "from Named", Named.class ).getResultList()
115115
.thenAccept( list -> assertEquals( 3, list.size() ) )
116116
) )
117117
.thenAccept( v -> {
@@ -125,7 +125,7 @@ public void testCacheWithHQL(VertxTestContext context) {
125125
) )
126126
//change the database
127127
.thenCompose( v -> getSessionFactory().withSession(
128-
s -> s.createQuery( "delete Named" ).executeUpdate()
128+
s -> s.createMutationQuery( "delete Named" ).executeUpdate()
129129
) )
130130
.thenAccept( v -> {
131131
assertFalse( cache.contains( Named.class, 1 ) );

hibernate-reactive-core/src/test/java/org/hibernate/reactive/CachedQueryResultsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static CriteriaQuery<Fruit> criteriaQuery(CriteriaBuilder criteriaBuilder
139139
}
140140

141141
private static Uni<List<Fruit>> findAllWithCacheableQuery(Mutiny.Session session) {
142-
return session.createQuery( "FROM Fruit f ORDER BY f.name ASC", Fruit.class )
142+
return session.createSelectionQuery( "FROM Fruit f ORDER BY f.name ASC", Fruit.class )
143143
.setCacheable( true )
144144
.getResultList();
145145
}

hibernate-reactive-core/src/test/java/org/hibernate/reactive/CascadeTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ public void testQuery(VertxTestContext context) {
6767
.thenCompose(s -> s.persist(basik).thenCompose(v -> s.flush()))
6868
.thenCompose( v -> openSession() )
6969
.thenCompose( s -> s.createQuery("select distinct n from Node n left join fetch n.elements").getResultList())
70-
.thenAccept( list -> assertEquals( list.size(), 2 ) )
70+
.thenAccept( list -> assertEquals( 2, list.size() ) )
7171
.thenCompose( v -> openSession() )
72-
.thenCompose( s -> s.createQuery("select distinct n, e from Node n join n.elements e").getResultList())
73-
.thenAccept( list -> assertEquals( list.size(), 3 ) )
72+
.thenCompose( s -> s.createSelectionQuery("select distinct n, e from Node n join n.elements e", Object[].class).getResultList())
73+
.thenAccept( list -> assertEquals( 3, list.size() ) )
7474
.thenCompose( v -> openSession() )
75-
.thenCompose( s -> s.createQuery("select distinct n.id, e.id from Node n join n.elements e").getResultList())
76-
.thenAccept( list -> assertEquals( list.size(), 3 ) )
75+
.thenCompose( s -> s.createSelectionQuery("select distinct n.id, e.id from Node n join n.elements e", Object[].class).getResultList())
76+
.thenAccept( list -> assertEquals( 3, list.size() ) )
7777
.thenCompose( v -> openSession() )
78-
.thenCompose( s -> s.createQuery("select max(e.id), min(e.id), sum(e.id) from Node n join n.elements e group by n.id order by n.id").getResultList())
79-
.thenAccept( list -> assertEquals( list.size(), 1 ) )
78+
.thenCompose( s -> s.createSelectionQuery("select max(e.id), min(e.id), sum(e.id) from Node n join n.elements e group by n.id order by n.id", Object[].class).getResultList())
79+
.thenAccept( list -> assertEquals( 1, list.size() ) )
8080
);
8181
}
8282

@@ -129,7 +129,7 @@ public void testCascade(VertxTestContext context) {
129129
return s2.fetch( node.parent )
130130
.thenCompose( parent -> {
131131
assertNotNull( parent );
132-
return s2.createQuery("update Node set string = upper(string)").executeUpdate()
132+
return s2.createMutationQuery("update Node set string = upper(string)").executeUpdate()
133133
.thenCompose(v -> s2.refresh(node))
134134
.thenAccept(v -> {
135135
assertEquals( node.getString(), "ADOPTED" );

hibernate-reactive-core/src/test/java/org/hibernate/reactive/CompositeIdManyToOneTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void reactivePersist(VertxTestContext context) {
5454
.thenCompose( s -> s.persist( gl )
5555
.thenCompose( v -> s.flush() )
5656
).thenCompose( v -> openSession() )
57-
.thenCompose( s -> s.createQuery("from ShoppingItem si where si.groceryList.id = :gl")
57+
.thenCompose( s -> s.createSelectionQuery("from ShoppingItem si where si.groceryList.id = :gl", ShoppingItem.class)
5858
.setParameter("gl", gl.id)
5959
.getResultList() )
6060
.thenAccept( list -> assertEquals( 1, list.size() ) )

hibernate-reactive-core/src/test/java/org/hibernate/reactive/CompositeIdTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,36 @@ private CompletionStage<String> selectNameFromId(Integer id) {
5050
}
5151

5252
private CompletionStage<String> selectNameFromId(Stage.Session session, Integer id) {
53-
return session.createQuery( "SELECT name FROM GuineaPig WHERE id = " + id )
53+
return session.createSelectionQuery( "SELECT name FROM GuineaPig WHERE id = " + id, String.class )
5454
.getResultList()
5555
.thenApply( CompositeIdTest::nameFromResult );
5656
}
5757

58-
private static String nameFromResult(List<Object> rowSet) {
58+
private static String nameFromResult(List<String> rowSet) {
5959
switch ( rowSet.size() ) {
6060
case 0:
6161
return null;
6262
case 1:
63-
return (String) rowSet.get( 0 );
63+
return rowSet.get( 0 );
6464
default:
6565
throw new AssertionError( "More than one result returned: " + rowSet.size() );
6666
}
6767
}
6868

6969
private CompletionStage<Double> selectWeightFromId(Integer id) {
7070
return getSessionFactory().withSession(
71-
session -> session.createQuery("SELECT weight FROM GuineaPig WHERE id = " + id )
71+
session -> session.createSelectionQuery("SELECT weight FROM GuineaPig WHERE id = " + id, Double.class )
7272
.getResultList()
7373
.thenApply( CompositeIdTest::weightFromResult )
7474
);
7575
}
7676

77-
private static Double weightFromResult(List<Object> rowSet) {
77+
private static Double weightFromResult(List<Double> rowSet) {
7878
switch ( rowSet.size() ) {
7979
case 0:
8080
return null;
8181
case 1:
82-
return (Double) rowSet.get(0);
82+
return rowSet.get(0);
8383
default:
8484
throw new AssertionError("More than one result returned: " + rowSet.size());
8585
}

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ protected Configuration constructConfiguration() {
6363
@Override
6464
protected CompletionStage<Void> cleanDb() {
6565
return getSessionFactory()
66-
.withTransaction( s -> s.createQuery( "delete from Element" ).executeUpdate()
67-
.thenCompose( v -> s.createQuery( "delete from Node" ).executeUpdate() )
66+
.withTransaction( s -> s.createMutationQuery( "delete from Element" ).executeUpdate()
67+
.thenCompose( v -> s.createMutationQuery( "delete from Node" ).executeUpdate() )
6868
.thenCompose( CompletionStages::voidFuture ) );
6969
}
7070

@@ -127,7 +127,7 @@ public void testEagerParentFetchQuery(VertxTestContext context) {
127127
openSession()
128128
.thenCompose(s -> s.persist(basik).thenCompose(v -> s.flush()))
129129
.thenCompose( v -> openSession() )
130-
.thenCompose(s -> s.createQuery( "from Element", Element.class ).getResultList())
130+
.thenCompose(s -> s.createSelectionQuery( "from Element", Element.class ).getResultList())
131131
.thenAccept( elements -> {
132132
for (Element element: elements) {
133133
assertTrue( Hibernate.isInitialized( element.getNode() ) );
@@ -151,18 +151,18 @@ public void testEagerFetchQuery(VertxTestContext context) {
151151
openSession()
152152
.thenCompose(s -> s.persist(basik).thenCompose(v -> s.flush()))
153153
.thenCompose( v -> openSession() )
154-
.thenCompose(s -> s.createQuery("from Node order by id", Node.class).getResultList())
154+
.thenCompose(s -> s.createSelectionQuery("from Node order by id", Node.class).getResultList())
155155
.thenAccept(list -> {
156156
assertEquals(list.size(), 2);
157157
assertTrue( Hibernate.isInitialized( list.get(0).getElements() ) );
158158
assertEquals(list.get(0).getElements().size(), 3);
159159
assertEquals(list.get(1).getElements().size(), 0);
160160
})
161161
.thenCompose( v -> openSession() )
162-
.thenCompose(s -> s.createQuery("select distinct n, e from Node n join n.elements e order by n.id").getResultList())
162+
.thenCompose(s -> s.createSelectionQuery("select distinct n, e from Node n join n.elements e order by n.id", Object[].class).getResultList())
163163
.thenAccept(list -> {
164164
assertEquals(list.size(), 3);
165-
Object[] tup = (Object[]) list.get(0);
165+
Object[] tup = list.get(0);
166166
assertTrue( Hibernate.isInitialized( ((Node) tup[0]).getElements() ) );
167167
assertEquals(((Node) tup[0]).getElements().size(), 3);
168168
})

hibernate-reactive-core/src/test/java/org/hibernate/reactive/FetchModeSubselectEagerTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ protected Configuration constructConfiguration() {
6363
@Override
6464
protected CompletionStage<Void> cleanDb() {
6565
return getSessionFactory()
66-
.withTransaction( s -> s.createQuery( "delete from Element" ).executeUpdate()
67-
.thenCompose( v -> s.createQuery( "delete from Node" ).executeUpdate() )
66+
.withTransaction( s -> s.createMutationQuery( "delete from Element" ).executeUpdate()
67+
.thenCompose( v -> s.createMutationQuery( "delete from Node" ).executeUpdate() )
6868
.thenCompose( CompletionStages::voidFuture ) );
6969
}
7070

@@ -130,19 +130,19 @@ public void testEagerFetchQuery(VertxTestContext context) {
130130
openSession()
131131
.thenCompose( s -> s.persist( basik ).thenCompose( v -> s.flush() ) )
132132
.thenCompose( v -> openSession() )
133-
.thenCompose( s -> s.createQuery( "from Node order by id", Node.class ).getResultList() )
133+
.thenCompose( s -> s.createSelectionQuery( "from Node order by id", Node.class ).getResultList() )
134134
.thenAccept( list -> {
135135
assertEquals( list.size(), 2 );
136136
assertTrue( Hibernate.isInitialized( list.get( 0 ).elements ) );
137137
assertEquals( list.get( 0 ).elements.size(), 3 );
138138
assertEquals( list.get( 1 ).elements.size(), 0 );
139139
} )
140140
.thenCompose( v -> openSession() )
141-
.thenCompose( s -> s.createQuery(
142-
"select distinct n, e from Node n join n.elements e order by n.id" ).getResultList() )
141+
.thenCompose( s -> s.createSelectionQuery(
142+
"select distinct n, e from Node n join n.elements e order by n.id", Object[].class ).getResultList() )
143143
.thenAccept( list -> {
144144
assertEquals( list.size(), 3 );
145-
Object[] tup = (Object[]) list.get( 0 );
145+
Object[] tup = list.get( 0 );
146146
assertTrue( Hibernate.isInitialized( ( (Node) tup[0] ).elements ) );
147147
assertEquals( ( (Node) tup[0] ).elements.size(), 3 );
148148
} )

hibernate-reactive-core/src/test/java/org/hibernate/reactive/FetchedAssociationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void testWithMutiny(VertxTestContext context) {
7878
} )
7979
.call( () -> getMutinySessionFactory()
8080
.withTransaction( s -> s
81-
.createQuery( "From Parent", Parent.class )
81+
.createSelectionQuery( "From Parent", Parent.class )
8282
.getSingleResult()
8383
.call( parent -> {
8484
Child child = new Child();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/FilterTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ protected Configuration constructConfiguration() {
5959
@Override
6060
protected CompletionStage<Void> cleanDb() {
6161
return getSessionFactory()
62-
.withTransaction( s -> s.createQuery( "delete from Element" ).executeUpdate()
63-
.thenCompose( v -> s.createQuery( "delete from Node" ).executeUpdate() )
62+
.withTransaction( s -> s.createMutationQuery( "delete from Element" ).executeUpdate()
63+
.thenCompose( v -> s.createMutationQuery( "delete from Node" ).executeUpdate() )
6464
.thenCompose( CompletionStages::voidFuture ) );
6565
}
6666

@@ -80,18 +80,18 @@ public void testFilter(VertxTestContext context) {
8080
.thenCompose( v -> openSession()
8181
.thenCompose( s -> {
8282
s.enableFilter( "current" );
83-
return s.createQuery( "select distinct n from Node n left join fetch n.elements order by n.id" )
83+
return s.createSelectionQuery( "select distinct n from Node n left join fetch n.elements order by n.id", Node.class )
8484
.setComment( "Hello World!" )
8585
.getResultList();
8686
} ) )
8787
.thenAccept( list -> {
8888
assertEquals( list.size(), 2 );
89-
assertEquals( ( (Node) list.get( 0 ) ).elements.size(), 2 );
89+
assertEquals( list.get( 0 ).elements.size(), 2 );
9090
} )
9191
.thenCompose( v -> openSession()
9292
.thenCompose( s -> {
9393
s.enableFilter( "current" );
94-
return s.createQuery( "select distinct n, e from Node n join n.elements e" )
94+
return s.createSelectionQuery( "select distinct n, e from Node n join n.elements e", Object[].class )
9595
.getResultList();
9696
} ) )
9797
.thenAccept( list -> assertEquals( list.size(), 2 ) )
@@ -119,8 +119,8 @@ public void testFilterWithParameter(VertxTestContext context) {
119119
.thenCompose( v -> openSession()
120120
.thenCompose( s -> {
121121
s.enableFilter( "region" ).setParameter( "region", "oceania" );
122-
return s.createQuery(
123-
"select distinct n from Node n left join fetch n.elements order by n.id" )
122+
return s.createSelectionQuery(
123+
"select distinct n from Node n left join fetch n.elements order by n.id", Node.class )
124124
.setComment( "Hello World!" )
125125
.getResultList();
126126
} ) )
@@ -131,7 +131,7 @@ public void testFilterWithParameter(VertxTestContext context) {
131131
.thenCompose( v -> openSession()
132132
.thenCompose( s -> {
133133
s.enableFilter( "region" ).setParameter( "region", "oceania" );
134-
return s.createQuery( "select distinct n, e from Node n join n.elements e" )
134+
return s.createSelectionQuery( "select distinct n, e from Node n join n.elements e", Object[].class )
135135
.getResultList();
136136
} ) )
137137
.thenAccept( list -> assertEquals( list.size(), 2 ) )

0 commit comments

Comments
 (0)