Skip to content

Commit

Permalink
[#26284] Minor refactoring
Browse files Browse the repository at this point in the history
Reduce number of `trim()` and `toLowerCase()` calls.
  • Loading branch information
DavideD committed Jul 18, 2022
1 parent e81b6bd commit 966f6af
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ public <T> CommonPanacheQueryImpl<T> project(Class<T> type) {
throw new PanacheQueryException("Unable to perform a projection on a named query");
}

if (query.trim().toLowerCase().startsWith("select new ")) {
String lowerCasedTrimmedQuery = query.trim().toLowerCase();
if (lowerCasedTrimmedQuery.startsWith("select new ")) {
throw new PanacheQueryException("Unable to perform a projection on a 'select new' query: " + query);
}

// If the query starts with a select clause, we generate an HQL query
// using the fields in the select clause:
// Initial query: select e.field1, e.field2 from EntityClass e
// New query: SELECT new org.acme.ProjectionClass(e.field1, e.field2) from EntityClass e
if (query.trim().toLowerCase().startsWith("select ")) {
if (lowerCasedTrimmedQuery.startsWith("select ")) {
int endSelect = lowerCasedTrimmedQuery.indexOf(" from ");
String trimmedQuery = query.trim();
int endSelect = trimmedQuery.toLowerCase().indexOf(" from ");
String selectClause = trimmedQuery.substring("SELECT ".length(), endSelect);
String from = trimmedQuery.substring(endSelect);
StringBuilder newQuery = new StringBuilder("select ");
Expand Down

0 comments on commit 966f6af

Please sign in to comment.