Skip to content

Commit fae433a

Browse files
committed
Various code cleanup
1 parent c069398 commit fae433a

File tree

1 file changed

+62
-73
lines changed

1 file changed

+62
-73
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ql/MapIssueTest.java

Lines changed: 62 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,29 @@
55
package org.hibernate.orm.test.jpa.ql;
66

77
import org.hibernate.dialect.PostgreSQLDialect;
8-
98
import org.hibernate.orm.test.jpa.model.MapContent;
109
import org.hibernate.orm.test.jpa.model.MapOwner;
1110
import org.hibernate.orm.test.jpa.model.Relationship;
12-
import org.hibernate.testing.orm.junit.JiraKey;
1311
import org.hibernate.testing.jdbc.SQLStatementInspector;
1412
import org.hibernate.testing.orm.junit.DomainModel;
13+
import org.hibernate.testing.orm.junit.JiraKey;
1514
import org.hibernate.testing.orm.junit.RequiresDialect;
1615
import org.hibernate.testing.orm.junit.SessionFactory;
1716
import org.hibernate.testing.orm.junit.SessionFactoryScope;
1817
import org.junit.jupiter.api.Test;
1918

19+
@SuppressWarnings("JUnitMalformedDeclaration")
2020
@JiraKey(value = "HHH-14279")
21-
@DomainModel(
22-
annotatedClasses = {
23-
MapOwner.class, MapContent.class, Relationship.class
24-
})
21+
@DomainModel( annotatedClasses = { MapOwner.class, MapContent.class, Relationship.class } )
2522
@SessionFactory(useCollectingStatementInspector = true)
2623
public class MapIssueTest {
2724

2825
@Test
2926
@RequiresDialect(value = PostgreSQLDialect.class, comment = "Requires support for using a correlated column in a join condition which H2 apparently does not support. For simplicity just run this on PostgreSQL")
3027
public void testWhereSubqueryMapKeyIsEntityWhereWithKey(SessionFactoryScope scope) {
31-
scope.inTransaction(
32-
s -> {
33-
s.createQuery( "select r from Relationship r where exists (select 1 from MapOwner as o left join o.contents c with key(c) = r)" ).list();
28+
scope.inTransaction( (session) -> {
29+
//noinspection deprecation
30+
session.createQuery( "select r from Relationship r where exists (select 1 from MapOwner as o left join o.contents c with key(c) = r)" ).list();
3431
}
3532
);
3633
}
@@ -39,112 +36,104 @@ public void testWhereSubqueryMapKeyIsEntityWhereWithKey(SessionFactoryScope scop
3936
public void testOnlyCollectionTableJoined(SessionFactoryScope scope) {
4037
SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
4138
statementInspector.clear();
42-
scope.inTransaction(
43-
s -> {
44-
s.createQuery( "select 1 from MapOwner as o left join o.contents c where c.id is not null" ).list();
45-
statementInspector.assertExecutedCount( 1 );
46-
// Assert only the collection table is joined
47-
statementInspector.assertNumberOfJoins( 0, 1 );
48-
}
49-
);
39+
scope.inTransaction( (session) -> {
40+
//noinspection deprecation
41+
session.createQuery( "select 1 from MapOwner as o left join o.contents c where c.id is not null" ).list();
42+
statementInspector.assertExecutedCount( 1 );
43+
// Assert only the collection table is joined
44+
statementInspector.assertNumberOfJoins( 0, 1 );
45+
} );
5046
}
5147

5248
@Test
5349
public void testMapKeyJoinIsNotOmitted(SessionFactoryScope scope) {
5450
SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
5551
statementInspector.clear();
56-
scope.inTransaction(
57-
s -> {
58-
s.createQuery( "select c from MapOwner as o join o.contents c join c.relationship r where r.id is not null" ).list();
59-
statementInspector.assertExecutedCount( 1 );
60-
// Assert 3 joins, collection table, collection element and collection key (relationship)
61-
statementInspector.assertNumberOfJoins( 0, 3 );
62-
}
63-
);
52+
scope.inTransaction( (session) -> {
53+
//noinspection deprecation
54+
session.createQuery( "select c from MapOwner as o join o.contents c join c.relationship r where r.id is not null" ).list();
55+
statementInspector.assertExecutedCount( 1 );
56+
// Assert 3 joins, collection table, collection element and collection key (relationship)
57+
statementInspector.assertNumberOfJoins( 0, 3 );
58+
} );
6459
}
6560

6661
@Test
6762
public void testMapKeyJoinIsOmitted2(SessionFactoryScope scope) {
6863
SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
6964
statementInspector.clear();
70-
scope.inTransaction(
71-
s -> {
72-
s.createQuery( "select c from MapOwner as o join o.contents c where c.relationship.id is not null" ).list();
73-
statementInspector.assertExecutedCount( 1 );
74-
// Assert 2 joins, collection table and collection element. No need to join the relationship because it is not nullable
75-
statementInspector.assertNumberOfJoins( 0, 2 );
76-
}
77-
);
65+
scope.inTransaction( (session) -> {
66+
//noinspection deprecation
67+
session.createQuery( "select c from MapOwner as o join o.contents c where c.relationship.id is not null" ).list();
68+
statementInspector.assertExecutedCount( 1 );
69+
// Assert 2 joins, collection table and collection element. No need to join the relationship because it is not nullable
70+
statementInspector.assertNumberOfJoins( 0, 2 );
71+
} );
7872
}
7973

8074
@Test
8175
public void testMapKeyDeReferenceDoesNotCauseJoin(SessionFactoryScope scope) {
8276
SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
8377
statementInspector.clear();
84-
scope.inTransaction(
85-
s -> {
86-
s.createQuery( "select c from MapOwner as o left join o.contents c where key(c).id is not null" ).list();
87-
statementInspector.assertExecutedCount( 1 );
88-
// Assert 2 joins, collection table and collection element
89-
statementInspector.assertNumberOfJoins( 0, 2 );
90-
}
91-
);
78+
scope.inTransaction( (session) -> {
79+
//noinspection deprecation
80+
session.createQuery( "select c from MapOwner as o left join o.contents c where key(c).id is not null" ).list();
81+
statementInspector.assertExecutedCount( 1 );
82+
// Assert 2 joins, collection table and collection element
83+
statementInspector.assertNumberOfJoins( 0, 2 );
84+
} );
9285
}
9386

9487
@Test
9588
public void testMapKeyJoinIsReused(SessionFactoryScope scope) {
9689
SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
9790
statementInspector.clear();
98-
scope.inTransaction(
99-
s -> {
100-
s.createQuery( "select key(c), c from MapOwner as o left join o.contents c join c.relationship r where r.name is not null" ).list();
101-
statementInspector.assertExecutedCount( 1 );
102-
// Assert 3 joins, collection table, collection element and relationship
103-
statementInspector.assertNumberOfJoins( 0, 3 );
104-
}
105-
);
91+
scope.inTransaction( (s) -> {
92+
//noinspection deprecation
93+
s.createQuery( "select key(c), c from MapOwner as o left join o.contents c join c.relationship r where r.name is not null" ).list();
94+
statementInspector.assertExecutedCount( 1 );
95+
// Assert 3 joins, collection table, collection element and relationship
96+
statementInspector.assertNumberOfJoins( 0, 3 );
97+
} );
10698
}
10799

108100
@Test
109101
public void testMapKeyJoinIsReusedForFurtherJoin(SessionFactoryScope scope) {
110102
SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
111103
statementInspector.clear();
112-
scope.inTransaction(
113-
s -> {
114-
s.createQuery( "select key(c), c from MapOwner as o left join o.contents c join c.relationship r join r.self s where s.name is not null" ).list();
115-
statementInspector.assertExecutedCount( 1 );
116-
// Assert 3 joins, collection table, collection element, relationship and self
117-
statementInspector.assertNumberOfJoins( 0, 4 );
118-
}
119-
);
104+
scope.inTransaction( (session) -> {
105+
//noinspection deprecation
106+
session.createQuery( "select key(c), c from MapOwner as o left join o.contents c join c.relationship r join r.self s where s.name is not null" ).list();
107+
statementInspector.assertExecutedCount( 1 );
108+
// Assert 3 joins, collection table, collection element, relationship and self
109+
statementInspector.assertNumberOfJoins( 0, 4 );
110+
} );
120111
}
121112

122113
@Test
123114
public void testMapKeyJoinIsReusedForFurtherJoinAndElementJoinIsProperlyOrdered(SessionFactoryScope scope) {
124115
SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
125116
statementInspector.clear();
126-
scope.inTransaction(
127-
s -> {
128-
s.createQuery( "select key(c), c from MapOwner as o left join o.contents c join c.relationship r join r.self s join c.relationship2 where s.name is not null" ).list();
129-
statementInspector.assertExecutedCount( 1 );
130-
// Assert 3 joins, collection table, collection element, relationship, relationship2 and self
131-
statementInspector.assertNumberOfJoins( 0, 5 );
132-
}
133-
);
117+
scope.inTransaction( (session) -> {
118+
//noinspection deprecation
119+
session.createQuery( "select key(c), c from MapOwner as o left join o.contents c join c.relationship r join r.self s join c.relationship2 where s.name is not null" ).list();
120+
statementInspector.assertExecutedCount( 1 );
121+
// Assert 3 joins, collection table, collection element, relationship, relationship2 and self
122+
statementInspector.assertNumberOfJoins( 0, 5 );
123+
} );
134124
}
135125

136126
@Test
137127
@JiraKey( value = "HHH-15357")
138128
public void testSelectMapKeyFk(SessionFactoryScope scope) {
139129
SQLStatementInspector statementInspector = scope.getCollectingStatementInspector();
140130
statementInspector.clear();
141-
scope.inTransaction(
142-
s -> {
143-
s.createQuery( "select key(c).id from MapOwner as o left join o.contents c" ).list();
144-
statementInspector.assertExecutedCount( 1 );
145-
// Assert that only the collection table and element table are joined
146-
statementInspector.assertNumberOfJoins( 0, 2 );
147-
}
148-
);
131+
scope.inTransaction( (session) -> {
132+
//noinspection deprecation
133+
session.createQuery( "select key(c).id from MapOwner as o left join o.contents c" ).list();
134+
statementInspector.assertExecutedCount( 1 );
135+
// Assert that only the collection table and element table are joined
136+
statementInspector.assertNumberOfJoins( 0, 2 );
137+
} );
149138
}
150139
}

0 commit comments

Comments
 (0)