Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
aureamunoz committed Nov 19, 2024
1 parent a1e6d7a commit 983f731
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,20 @@ public Result parse(MethodInfo methodInfo) {
String topLevelFieldName = getTopLevelFieldName(fieldName);
String childEntityAlias = topLevelFieldName;
if (fieldInfo != null) {
//Find the field of the child entity mapping with entityClass
//logic to find the field mapping with the parent (with entityClass)
FieldInfo relatedParentFieldInfo = indexView
.getClassByName(fieldInfo.declaringClass().name().toString()).fields()
.stream().filter(fi -> fi.type().name().equals(DotName.createSimple(entityClass.name().toString())))
.stream()
.filter(fi -> fi.type().name().equals(DotName.createSimple(entityClass.name().toString())))
.findFirst().orElse(null);
if (relatedParentFieldInfo != null) {
joinClause = " LEFT JOIN " + topLevelFieldName + " " + childEntityAlias + " ON "
+ entityAlias + "." + getIdFieldInfo(entityClass).name() + " = "
+ topLevelFieldName + "." + relatedParentFieldInfo.name() + "."
+ getIdFieldInfo(entityClass).name();
} else {
// Fallback for cases where the relationship is not explicit
joinClause = " LEFT JOIN " + entityAlias + "." + topLevelFieldName + " " + childEntityAlias;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class LoginEvent {
private Long id;

@ManyToOne
// @JoinColumn(name = "user_id", referencedColumnName = "userId")
private User user;

private ZonedDateTime zonedDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public void testFindAllByAddressZipCode() throws Exception {
assertThat(result).isNotNull();
assertSameClass(result.getEntityClass(), entityClass);
assertThat(result.getParamCount()).isEqualTo(1);
assertThat(result.getQuery()).isEqualTo("FROM Person AS person WHERE address.zipCode = ?1");
assertThat(result.getQuery())
.isEqualTo("FROM Person AS person LEFT JOIN person.address address WHERE address.zipCode = ?1");
}

@Test
Expand Down Expand Up @@ -83,7 +84,8 @@ public void testFindAllByAddress_Country() throws Exception {
additionalClasses);
assertThat(result).isNotNull();
assertSameClass(result.getEntityClass(), entityClass);
assertThat(result.getQuery()).isEqualTo("FROM Person AS person WHERE address.country = ?1");
assertThat(result.getQuery())
.isEqualTo("FROM Person AS person LEFT JOIN person.address address WHERE address.country = ?1");
assertThat(result.getParamCount()).isEqualTo(1);
}

Expand All @@ -100,7 +102,8 @@ public void testFindAllByAddress_CountryIsoCode() throws Exception {
additionalClasses);
assertThat(result).isNotNull();
assertSameClass(result.getEntityClass(), entityClass);
assertThat(result.getQuery()).isEqualTo("FROM Person AS person WHERE address.country.isoCode = ?1");
assertThat(result.getQuery())
.isEqualTo("FROM Person AS person LEFT JOIN person.address address WHERE address.country.isoCode = ?1");
assertThat(result.getParamCount()).isEqualTo(1);
}

Expand All @@ -110,7 +113,8 @@ public void testFindAllByAddress_Country_IsoCode() throws Exception {
additionalClasses);
assertThat(result).isNotNull();
assertSameClass(result.getEntityClass(), entityClass);
assertThat(result.getQuery()).isEqualTo("FROM Person AS person WHERE address.country.isoCode = ?1");
assertThat(result.getQuery())
.isEqualTo("FROM Person AS person LEFT JOIN person.address address WHERE address.country.isoCode = ?1");
assertThat(result.getParamCount()).isEqualTo(1);
}

Expand Down Expand Up @@ -138,7 +142,8 @@ public void testGenericsWithWildcard() throws Exception {
additionalClasses);
assertThat(result).isNotNull();
assertSameClass(result.getEntityClass(), ParentBase.class);
assertThat(result.getQuery()).isEqualTo("FROM ParentBase AS parentbase WHERE children.nombre = ?1");
assertThat(result.getQuery())
.isEqualTo("FROM ParentBase AS parentbase LEFT JOIN parentbase.children children WHERE children.nombre = ?1");
assertThat(result.getParamCount()).isEqualTo(1);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.quarkus.spring.data.deployment;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand Down Expand Up @@ -29,5 +31,8 @@ public interface UserRepository extends JpaRepository<User, String> {
// purposely with compiled parameter name not matching the query to also test that @Param takes precedence
User getUserByFullNameUsingNamedQueries(@Param("name") String arg);

long countUsersByLoginEvents_Id(Long id);
// issue 34395: This method is used to test the MethodNameParser class. See MethodNameParserTest class
long countUsersByLoginEvents_Id(long id);

List<User> findAllByLoginEvents_Id(long id);
}

0 comments on commit 983f731

Please sign in to comment.