Skip to content

Commit 29b8252

Browse files
author
P63098
committed
Fix 176 Add the ability to choose the join type with ElementCollection
1 parent 2546ce3 commit 29b8252

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

rsql-jpa/src/main/java/io/github/perplexhub/rsql/RSQLJPAPredicateConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ RSQLJPAContext findPropertyPath(String propertyPath, Path startRoot) {
133133
classMetadata = getManagedElementCollectionType(mappedProperty, classMetadata);
134134
String keyJoin = getKeyJoin(root, mappedProperty);
135135
log.debug("Create a element collection join between [{}] and [{}] using key [{}]", previousClass, classMetadata.getJavaType().getName(), keyJoin);
136-
root = join(keyJoin, root, mappedProperty);
136+
root = join(keyJoin, root, mappedProperty, joinHints.get(keyJoin));
137137
} else {
138138
log.debug("Create property path for type [{}] property [{}]", classMetadata.getJavaType().getName(), mappedProperty);
139139
root = root.get(mappedProperty);

rsql-jpa/src/test/java/io/github/perplexhub/rsql/RSQLJPASupportTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,26 @@ public final void testElementCollection2() {
183183
assertThat(rsql, count, is(4l));
184184
}
185185

186+
@Test
187+
public final void testElementCollection1WithJoinHints() {
188+
final Map<String, JoinType> joinHints = new HashMap<String, JoinType>(){{put("Company.tags", JoinType.LEFT);}};
189+
final String rsql = "tags!=tech,tags=na=''";
190+
final List<Company> companies = companyRepository.findAll(toSpecification(rsql, null, joinHints));
191+
final long count = companies.size();
192+
log.info("rsql: {} -> count: {}", rsql, count);
193+
assertThat(rsql, count, is(4L));
194+
}
195+
196+
@Test
197+
public final void testElementCollection2WithJoinHints() {
198+
final Map<String, JoinType> joinHints = new HashMap<String, JoinType>(){{put("Company.bigTags", JoinType.LEFT);}};
199+
final String rsql = "bigTags.tag!=tech,bigTags.tag=na=''";
200+
final List<Company> companies = companyRepository.findAll(toSpecification(rsql, null, joinHints));
201+
final long count = companies.size();
202+
log.info("rsql: {} -> count: {}", rsql, count);
203+
assertThat(rsql, count, is(4L));
204+
}
205+
186206
@Test
187207
public final void testToComplexMultiValueMap() {
188208
String rsql = "sites.trunks.id==2,id=na=2,company.id=='2',id=na=3,name==''";

0 commit comments

Comments
 (0)