3333import static org .hibernate .reactive .testing .DBSelectionExtension .skipTestsFor ;
3434
3535/**
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 }
3737 */
38- public class RowIdUpdateAndDeleteTest extends BaseReactiveTest {
38+ public class RowIdUpdateTest extends BaseReactiveTest {
3939
4040 // Db2: Exception: IllegalStateException: Needed to have 6 in buffer but only had 0
4141 // Oracle: Vert.x driver doesn't support RowId type parameters
@@ -52,7 +52,7 @@ protected Collection<Class<?>> annotatedEntities() {
5252 @ Override
5353 protected Configuration constructConfiguration () {
5454 Configuration configuration = super .constructConfiguration ();
55- sqlTracker = new SqlStatementTracker ( RowIdUpdateAndDeleteTest :: isRowIdQuery , configuration .getProperties () );
55+ sqlTracker = new SqlStatementTracker ( RowIdUpdateTest :: isUsingRowId , configuration .getProperties () );
5656 return configuration ;
5757 }
5858
@@ -61,17 +61,15 @@ protected void addServices(StandardServiceRegistryBuilder builder) {
6161 sqlTracker .registerService ( builder );
6262 }
6363
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" );
6666 }
6767
6868 @ BeforeEach
6969 public void prepareDb (VertxTestContext context ) {
7070 test ( context , getMutinySessionFactory ().withTransaction ( session -> session .persistAll (
7171 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" ) )
7573 ) ) );
7674 }
7775
@@ -88,30 +86,11 @@ public void testSimpleUpdateSameTransaction(VertxTestContext context) {
8886 .chain ( () -> getMutinySessionFactory ()
8987 .withSession ( session -> session .find ( SimpleEntity .class , 3L ) ) )
9088 // the update should have used the primary key, as the row-id value is not available
91- .invoke ( RowIdUpdateAndDeleteTest :: shouldUsePrimaryKeyForUpdate )
89+ .invoke ( RowIdUpdateTest :: shouldUsePrimaryKey )
9290 .invoke ( entity -> assertThat ( entity ).hasFieldOrPropertyWithValue ( "status" , "new_status" ) )
9391 );
9492 }
9593
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-
11594 @ Test
11695 public void testRelatedUpdateSameTransaction (VertxTestContext context ) {
11796 sqlTracker .clear ();
@@ -126,26 +105,11 @@ public void testRelatedUpdateSameTransaction(VertxTestContext context) {
126105 .chain ( () -> getMutinySessionFactory ()
127106 .withSession ( session -> session .find ( SimpleEntity .class , 4L ) ) )
128107 // the update should have used the primary key, as the row-id value is not available
129- .invoke ( RowIdUpdateAndDeleteTest :: shouldUsePrimaryKeyForUpdate )
108+ .invoke ( RowIdUpdateTest :: shouldUsePrimaryKey )
130109 .invoke ( entity -> assertThat ( entity ).hasFieldOrPropertyWithValue ( "status" , "new_status" ) )
131110 );
132111 }
133112
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-
149113 @ Test
150114 public void testSimpleUpdateDifferentTransaction (VertxTestContext context ) {
151115 sqlTracker .clear ();
@@ -156,7 +120,7 @@ public void testSimpleUpdateDifferentTransaction(VertxTestContext context) {
156120 )
157121 .chain ( () -> getMutinySessionFactory ()
158122 .withSession ( session -> session .find ( SimpleEntity .class , 1L ) ) )
159- .invoke ( RowIdUpdateAndDeleteTest :: shouldUseRowIdForUpdate )
123+ .invoke ( RowIdUpdateTest :: shouldUseRowId )
160124 .invoke ( entity -> assertThat ( entity ).hasFieldOrPropertyWithValue ( "status" , "new_status" ) )
161125 );
162126 }
@@ -169,7 +133,7 @@ public void testRelatedUpdateRelatedDifferentTransaction(VertxTestContext contex
169133 .find ( ParentEntity .class , 2L )
170134 .invoke ( entity -> entity .getChild ().setStatus ( "new_status" ) )
171135 )
172- .invoke ( RowIdUpdateAndDeleteTest :: shouldUseRowIdForUpdate )
136+ .invoke ( RowIdUpdateTest :: shouldUseRowId )
173137 .chain ( () -> getMutinySessionFactory ()
174138 .withSession ( session -> session .find ( SimpleEntity .class , 2L ) ) )
175139 .invoke ( entity -> assertThat ( entity )
@@ -178,19 +142,13 @@ public void testRelatedUpdateRelatedDifferentTransaction(VertxTestContext contex
178142 );
179143 }
180144
181- private static void shouldUsePrimaryKeyForUpdate () {
145+ private static void shouldUsePrimaryKey () {
182146 assertThat ( sqlTracker .getLoggedQueries () ).hasSize ( 1 );
183147 assertThat ( sqlTracker .getLoggedQueries ().get ( 0 ) )
184148 .matches ( "update SimpleEntity set status=.+ where primary_key=.+" );
185149 }
186150
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 () {
194152 // Not all databases have a rowId column
195153 String rowId = getDialect ().rowId ( "" );
196154 String column = rowId == null ? "primary_key" : rowId ;
@@ -199,15 +157,6 @@ private static void shouldUseRowIdForUpdate() {
199157 .matches ( "update SimpleEntity set status=.+ where " + column + "=.+" );
200158 }
201159
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-
211160 @ Entity (name = "SimpleEntity" )
212161 @ Table (name = "SimpleEntity" )
213162 @ RowId
0 commit comments