Skip to content

Commit

Permalink
fix(db): use Java field names for HQLs
Browse files Browse the repository at this point in the history
Column names / aliases no longer work after upgrade to Hibernate 6.

RHINENG-1631
  • Loading branch information
vkrizan committed Jan 2, 2024
1 parent 57c84fa commit e5e3c71
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/redhat/cloud/policies/app/model/Policy.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static Page<Policy> pagePoliciesForCustomer(EntityManager em, String orgi
.keySet()
.forEach(FilterableColumn::fromName);

Filter filter = pager.getFilter().and("org_id", Filter.Operator.EQUAL, orgid);
Filter filter = pager.getFilter().and("orgId", Filter.Operator.EQUAL, orgid);

PanacheQuery<Policy> panacheQuery = find(
filter.getQuery(),
Expand All @@ -171,7 +171,7 @@ public static List<UUID> getPolicyIdsForCustomer(EntityManager em, String orgId,
.keySet()
.forEach(FilterableColumn::fromName);

Filter filter = pager.getFilter().and("org_id", Filter.Operator.EQUAL, orgId);
Filter filter = pager.getFilter().and("orgId", Filter.Operator.EQUAL, orgId);


PanacheQuery<Policy> panacheQuery = find(
Expand All @@ -183,11 +183,11 @@ public static List<UUID> getPolicyIdsForCustomer(EntityManager em, String orgId,
}

public static Policy findById(String orgId, UUID theId) {
return find("org_id = ?1 and id = ?2", orgId, theId).firstResult();
return find("orgId = ?1 and id = ?2", orgId, theId).firstResult();
}

public static Policy findByName(String orgId, String name) {
return find("org_id = ?1 and name = ?2", orgId, name).firstResult();
return find("orgId = ?1 and name = ?2", orgId, name).firstResult();
}

public void delete(Policy policy) {
Expand Down Expand Up @@ -249,7 +249,7 @@ public static SortableColumn fromName(String columnName) {
enum FilterableColumn {
NAME("name"),
DESCRIPTION("description"),
IS_ENABLED("is_enabled");
IS_ENABLED("isEnabled");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public PagerBuilder filter(String column, Filter.Operator operator, String value
Object transformedValue = value;
if (operator.equals(Filter.Operator.BOOLEAN_IS)) {
transformedValue = Boolean.valueOf(value);
operator = Filter.Operator.EQUAL; // force to equal for HQL
}

this.filter.and(column, operator, transformedValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public static Pager extractPager(UriInfo uriInfo) {
String value = queryParams.getFirst(key);
Filter.Operator operator;
if (column.equals("is_enabled")) {
column = "isEnabled";
operator = Filter.Operator.BOOLEAN_IS;
if (value == null || value.isEmpty()) {
value = "true";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ public void extractBadFilterBooleanOperator() throws URISyntaxException {
@Test
public void extractFilterBooleanOperator() throws URISyntaxException {
Pager pager = getPagerFromUriString("https://foo?filter[is_enabled]=true&filter:op[is_enabled]=boolean_is");
assertEquals(true, pager.getFilter().getParameters().map().get("is_enabled"));
assertEquals(true, pager.getFilter().getParameters().map().get("isEnabled"));
}

@Test
public void extractFilterBooleanOperator2() throws URISyntaxException {
Pager pager = getPagerFromUriString("https://foo?filter[is_enabled]=true");
assertEquals(true, pager.getFilter().getParameters().map().get("is_enabled"));
assertEquals(true, pager.getFilter().getParameters().map().get("isEnabled"));
}

@Test
Expand Down

0 comments on commit e5e3c71

Please sign in to comment.