Skip to content

Commit

Permalink
Fix Spring Data Repository with nested camel-case properties does not…
Browse files Browse the repository at this point in the history
… work with Quarkus #13067
  • Loading branch information
renegrob committed Nov 17, 2020
1 parent 15162d6 commit e9b9d1d
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public final class DotNames {
public static final DotName PRIMITIVE_LONG = DotName.createSimple(long.class.getName());
public static final DotName INTEGER = DotName.createSimple(Integer.class.getName());
public static final DotName PRIMITIVE_INTEGER = DotName.createSimple(int.class.getName());
public static final DotName SHORT = DotName.createSimple(Short.class.getName());
public static final DotName PRIMITIVE_SHORT = DotName.createSimple(short.class.getName());
public static final DotName CHARACTER = DotName.createSimple(Character.class.getName());
public static final DotName PRIMITIVE_CHAR = DotName.createSimple(char.class.getName());
public static final DotName BYTE = DotName.createSimple(Byte.class.getName());
public static final DotName PRIMITIVE_BYTE = DotName.createSimple(byte.class.getName());
public static final DotName DOUBLE = DotName.createSimple(Double.class.getName());
public static final DotName PRIMITIVE_DOUBLE = DotName.createSimple(double.class.getName());
public static final DotName FLOAT = DotName.createSimple(Float.class.getName());
public static final DotName PRIMITIVE_FLOAT = DotName.createSimple(float.class.getName());
public static final DotName BOOLEAN = DotName.createSimple(Boolean.class.getName());
public static final DotName PRIMITIVE_BOOLEAN = DotName.createSimple(boolean.class.getName());
public static final DotName STRING = DotName.createSimple(String.class.getName());
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.quarkus.it.spring.data.jpa;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

// TODO: @Entity(name = "EmployeeEntity")
@Entity
@Table(name = "org_employee_table")
public class Employee extends AbstractEntity {

@Column(name = "user_id")
private String userId;

@Column(name = "first_name")
private String firstName;

@Column(name = "last_name")
private String lastName;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "team_id", nullable = false)
private Team belongsToTeam;

public String getUserId() {
return userId;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

public Team getBelongsToTeam() {
return belongsToTeam;
}

@Entity // TODO: (name = "UserRoleEntity")
@Table(name = "org_team_table")
public static class Team extends AbstractEntity {

private String name;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "unit_id", nullable = false)
private OrgUnit organizationalUnit;

public String getName() {
return name;
}

public OrgUnit getOrganizationalUnit() {
return organizationalUnit;
}
}

@Entity // TODO: (name = "OrgUnitEntity")
@Table(name = "org_unit_table")
public static class OrgUnit extends AbstractEntity {

private String name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.quarkus.it.spring.data.jpa;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

public interface EmployeeRepository extends JpaRepository<Employee, Long> {

List<Employee> findByBelongsToTeamOrganizationalUnitsName(String orgUnitName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.quarkus.it.spring.data.jpa;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

@Path("/employee")
@Produces("application/json")
public class EmployeeResource {

private final EmployeeRepository employeeRepository;

public EmployeeResource(EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository;
}

@GET
public List<Employee> findAll() {
return this.employeeRepository.findAll();
}

@GET
@Path("/{id}")
public Employee findById(@PathParam("id") Long id) {
return this.employeeRepository.findById(id).orElse(null);
}

@GET
@Path("/unit/{orgUnitName}")
public List<Employee> findByManagerOfManager(@PathParam("orgUnitName") String orgUnitName) {
return this.employeeRepository.findByBelongsToTeamOrganizationalUnitsName(orgUnitName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ INSERT INTO cart(id, customer_id, status) VALUES (3, 3, 'CANCELED');

INSERT INTO orders(id, cart_id) VALUES (1, 1);
INSERT INTO orders(id, cart_id) VALUES (2, 2);

INSERT INTO org_unit_table(id, name) VALUES (1, 'Delivery Unit');
INSERT INTO org_unit_table(id, name) VALUES (2, 'Sales and Marketing Unit');
INSERT INTO org_team_table(id, name, unit_id) VALUES (10, 'Development Team', 1);
INSERT INTO org_team_table(id, name, unit_id) VALUES (11, 'Sales Team', 2);
INSERT INTO org_employee_table(id, user_id, first_name, last_name, team_id) VALUES (100, 'johdoe', 'John', 'Doe', 10);
INSERT INTO org_employee_table(id, user_id, first_name, last_name, team_id) VALUES (101, 'petdig', 'Peter', 'Digger', 10);
INSERT INTO org_employee_table(id, user_id, first_name, last_name, team_id) VALUES (102, 'stesmi', 'Stella', 'Smith', 11);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.it.spring.data.jpa;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class EmployeeResourceIT extends EmployeeResourceTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.it.spring.data.jpa;

import static io.restassured.RestAssured.when;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class EmployeeResourceTest {

@Test
public void testFindEmployeesByOrganizationalUnit() {
List<Employee> employees = when().get("/employee/unit/Delivery Unit").then()
.statusCode(200)
.extract().body().jsonPath().getList(".", Employee.class);

assertThat(employees).extracting("userId").containsExactlyInAnyOrder("johdoe", "petdig");
}

}

0 comments on commit e9b9d1d

Please sign in to comment.