Skip to content

Commit

Permalink
REPORT-900 - HQL Query Builder should support entity names that diffe…
Browse files Browse the repository at this point in the history
…r from class names
  • Loading branch information
mseaton committed Aug 29, 2023
1 parent f5f3cfc commit 2b982e1
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class HqlQueryBuilder implements QueryBuilder {

protected Log log = LogFactory.getLog(getClass());

private Map<String, Class<?>> fromTypes = new LinkedHashMap<String, Class<?>>();
private Map<String, String> fromTypes = new LinkedHashMap<String, String>();
private boolean includeVoided = false;
private List<String> columns = new ArrayList<String>();
private List<String> joinClauses = new ArrayList<String>();
Expand Down Expand Up @@ -93,13 +93,18 @@ public HqlQueryBuilder from(Class<?> fromType) {
}

public HqlQueryBuilder from(Class<?> fromType, String fromAlias) {
fromTypes.put(fromAlias, fromType);
fromTypes.put(fromAlias, fromType.getName());
if (!includeVoided && Voidable.class.isAssignableFrom(fromType)) {
whereEqual((ObjectUtil.notNull(fromAlias) ? fromAlias + "." : "")+"voided", false);
}
return this;
}

public HqlQueryBuilder from(String entityName, String fromAlias) {
fromTypes.put(fromAlias, entityName);
return this;
}

public HqlQueryBuilder innerJoin(String property, String alias) {
joinClauses.add("inner join " + property + " as " + alias);
return this;
Expand Down Expand Up @@ -534,7 +539,7 @@ else if (!ObjectUtil.containsWhitespace(column)) {
for (int i=0; i<aliases.size(); i++) {
String alias = aliases.get(i);
q.append(i == 0 ? " from " : ", ");
q.append(fromTypes.get(alias).getName());
q.append(fromTypes.get(alias));
if (ObjectUtil.notNull(alias)) {
q.append(" as ").append(alias);
}
Expand Down

0 comments on commit 2b982e1

Please sign in to comment.