33
33
import static org .hibernate .reactive .testing .DBSelectionExtension .skipTestsFor ;
34
34
35
35
/**
36
- * Adapted from the test with the same name in Hibernate ORM: {@literal org.hibernate.orm.test.rowid.RowIdUpdateAndDeleteTest }
36
+ * Adapted from the test with the same name in Hibernate ORM: {@literal org.hibernate.orm.test.rowid.RowIdUpdateTest }
37
37
*/
38
- public class RowIdUpdateAndDeleteTest extends BaseReactiveTest {
38
+ public class RowIdUpdateTest extends BaseReactiveTest {
39
39
40
40
// Db2: Exception: IllegalStateException: Needed to have 6 in buffer but only had 0
41
41
// Oracle: Vert.x driver doesn't support RowId type parameters
@@ -52,7 +52,7 @@ protected Collection<Class<?>> annotatedEntities() {
52
52
@ Override
53
53
protected Configuration constructConfiguration () {
54
54
Configuration configuration = super .constructConfiguration ();
55
- sqlTracker = new SqlStatementTracker ( RowIdUpdateAndDeleteTest :: isRowIdQuery , configuration .getProperties () );
55
+ sqlTracker = new SqlStatementTracker ( RowIdUpdateTest :: isUsingRowId , configuration .getProperties () );
56
56
return configuration ;
57
57
}
58
58
@@ -61,17 +61,15 @@ protected void addServices(StandardServiceRegistryBuilder builder) {
61
61
sqlTracker .registerService ( builder );
62
62
}
63
63
64
- private static boolean isRowIdQuery (String s ) {
65
- return s .toLowerCase ().startsWith ( "update" ) || s . toLowerCase (). startsWith ( "delete" ) ;
64
+ private static boolean isUsingRowId (String s ) {
65
+ return s .toLowerCase ().startsWith ( "update" );
66
66
}
67
67
68
68
@ BeforeEach
69
69
public void prepareDb (VertxTestContext context ) {
70
70
test ( context , getMutinySessionFactory ().withTransaction ( session -> session .persistAll (
71
71
new SimpleEntity ( 1L , "initial_status" ),
72
- new ParentEntity ( 2L , new SimpleEntity ( 2L , "initial_status" ) ),
73
- new SimpleEntity ( 11L , "to_delete" ),
74
- new ParentEntity ( 12L , new SimpleEntity ( 12L , "to_delete" ) )
72
+ new ParentEntity ( 2L , new SimpleEntity ( 2L , "initial_status" ) )
75
73
) ) );
76
74
}
77
75
@@ -88,30 +86,11 @@ public void testSimpleUpdateSameTransaction(VertxTestContext context) {
88
86
.chain ( () -> getMutinySessionFactory ()
89
87
.withSession ( session -> session .find ( SimpleEntity .class , 3L ) ) )
90
88
// the update should have used the primary key, as the row-id value is not available
91
- .invoke ( RowIdUpdateAndDeleteTest :: shouldUsePrimaryKeyForUpdate )
89
+ .invoke ( RowIdUpdateTest :: shouldUsePrimaryKey )
92
90
.invoke ( entity -> assertThat ( entity ).hasFieldOrPropertyWithValue ( "status" , "new_status" ) )
93
91
);
94
92
}
95
93
96
- @ Test
97
- public void testSimpleDeleteSameTransaction (VertxTestContext context ) {
98
- sqlTracker .clear ();
99
- test ( context , getMutinySessionFactory ()
100
- .withTransaction ( session -> {
101
- final SimpleEntity simpleEntity = new SimpleEntity ( 13L , "to_delete" );
102
- return session .persist ( simpleEntity )
103
- .call ( session ::flush )
104
- .call ( () -> session .remove ( simpleEntity ) )
105
- .invoke ( () -> simpleEntity .setStatus ( "new_status" ) );
106
- } )
107
- .chain ( () -> getMutinySessionFactory ()
108
- .withSession ( session -> session .find ( SimpleEntity .class , 13L ) ) )
109
- // the update should have used the primary key, as the row-id value is not available
110
- .invoke ( RowIdUpdateAndDeleteTest ::shouldUsePrimaryKeyForDelete )
111
- .invoke ( entity -> assertThat ( entity ).isNull () )
112
- );
113
- }
114
-
115
94
@ Test
116
95
public void testRelatedUpdateSameTransaction (VertxTestContext context ) {
117
96
sqlTracker .clear ();
@@ -126,26 +105,11 @@ public void testRelatedUpdateSameTransaction(VertxTestContext context) {
126
105
.chain ( () -> getMutinySessionFactory ()
127
106
.withSession ( session -> session .find ( SimpleEntity .class , 4L ) ) )
128
107
// the update should have used the primary key, as the row-id value is not available
129
- .invoke ( RowIdUpdateAndDeleteTest :: shouldUsePrimaryKeyForUpdate )
108
+ .invoke ( RowIdUpdateTest :: shouldUsePrimaryKey )
130
109
.invoke ( entity -> assertThat ( entity ).hasFieldOrPropertyWithValue ( "status" , "new_status" ) )
131
110
);
132
111
}
133
112
134
- @ Test
135
- public void testSimpleDeleteDifferentTransaction (VertxTestContext context ) {
136
- sqlTracker .clear ();
137
- test ( context , getMutinySessionFactory ()
138
- .withTransaction ( session -> session
139
- .find ( SimpleEntity .class , 11L )
140
- .call ( session ::remove )
141
- )
142
- .chain ( () -> getMutinySessionFactory ()
143
- .withSession ( session -> session .find ( SimpleEntity .class , 11L ) ) )
144
- .invoke ( RowIdUpdateAndDeleteTest ::shouldUseRowIdForDelete )
145
- .invoke ( entity -> assertThat ( entity ).isNull () )
146
- );
147
- }
148
-
149
113
@ Test
150
114
public void testSimpleUpdateDifferentTransaction (VertxTestContext context ) {
151
115
sqlTracker .clear ();
@@ -156,7 +120,7 @@ public void testSimpleUpdateDifferentTransaction(VertxTestContext context) {
156
120
)
157
121
.chain ( () -> getMutinySessionFactory ()
158
122
.withSession ( session -> session .find ( SimpleEntity .class , 1L ) ) )
159
- .invoke ( RowIdUpdateAndDeleteTest :: shouldUseRowIdForUpdate )
123
+ .invoke ( RowIdUpdateTest :: shouldUseRowId )
160
124
.invoke ( entity -> assertThat ( entity ).hasFieldOrPropertyWithValue ( "status" , "new_status" ) )
161
125
);
162
126
}
@@ -169,7 +133,7 @@ public void testRelatedUpdateRelatedDifferentTransaction(VertxTestContext contex
169
133
.find ( ParentEntity .class , 2L )
170
134
.invoke ( entity -> entity .getChild ().setStatus ( "new_status" ) )
171
135
)
172
- .invoke ( RowIdUpdateAndDeleteTest :: shouldUseRowIdForUpdate )
136
+ .invoke ( RowIdUpdateTest :: shouldUseRowId )
173
137
.chain ( () -> getMutinySessionFactory ()
174
138
.withSession ( session -> session .find ( SimpleEntity .class , 2L ) ) )
175
139
.invoke ( entity -> assertThat ( entity )
@@ -178,19 +142,13 @@ public void testRelatedUpdateRelatedDifferentTransaction(VertxTestContext contex
178
142
);
179
143
}
180
144
181
- private static void shouldUsePrimaryKeyForUpdate () {
145
+ private static void shouldUsePrimaryKey () {
182
146
assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 1 );
183
147
assertThat ( sqlTracker .getLoggedQueries ().get ( 0 ) )
184
148
.matches ( "update SimpleEntity set status=.+ where primary_key=.+" );
185
149
}
186
150
187
- private static void shouldUsePrimaryKeyForDelete () {
188
- assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 1 );
189
- assertThat ( sqlTracker .getLoggedQueries ().get ( 0 ) )
190
- .matches ( "delete from SimpleEntity where primary_key=.+" );
191
- }
192
-
193
- private static void shouldUseRowIdForUpdate () {
151
+ private static void shouldUseRowId () {
194
152
// Not all databases have a rowId column
195
153
String rowId = getDialect ().rowId ( "" );
196
154
String column = rowId == null ? "primary_key" : rowId ;
@@ -199,15 +157,6 @@ private static void shouldUseRowIdForUpdate() {
199
157
.matches ( "update SimpleEntity set status=.+ where " + column + "=.+" );
200
158
}
201
159
202
- private static void shouldUseRowIdForDelete () {
203
- // Not all databases have a rowId column
204
- String rowId = getDialect ().rowId ( "" );
205
- String column = rowId == null ? "primary_key" : rowId ;
206
- assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 1 );
207
- assertThat ( sqlTracker .getLoggedQueries ().get ( 0 ) )
208
- .matches ( "delete from SimpleEntity where " + column + "=.+" );
209
- }
210
-
211
160
@ Entity (name = "SimpleEntity" )
212
161
@ Table (name = "SimpleEntity" )
213
162
@ RowId
0 commit comments