Skip to content

Commit

Permalink
Switch from system property to hadcoded line separator for Panache query
Browse files Browse the repository at this point in the history
(cherry picked from commit 1ce865e)
  • Loading branch information
loicmathieu authored and gsmet committed Dec 21, 2022
1 parent ff1c280 commit ffb3f26
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public void close() {

private Map<String, Map<String, Object>> filters;

private final String lineSeparator = System.getProperty("line.separator");

public CommonPanacheQueryImpl(EntityManager em, String query, String orderBy, Object paramsArrayOrMap) {
this.em = em;
this.query = query;
Expand Down Expand Up @@ -84,7 +82,7 @@ public <T> CommonPanacheQueryImpl<T> project(Class<T> type) {
throw new PanacheQueryException("Unable to perform a projection on a named query");
}

String lowerCasedTrimmedQuery = query.trim().replace(lineSeparator, " ").toLowerCase();
String lowerCasedTrimmedQuery = query.trim().replace('\n', ' ').replace('\r', ' ').toLowerCase();
if (lowerCasedTrimmedQuery.startsWith("select new ")) {
throw new PanacheQueryException("Unable to perform a projection on a 'select new' query: " + query);
}
Expand All @@ -95,7 +93,7 @@ public <T> CommonPanacheQueryImpl<T> project(Class<T> type) {
// New query: SELECT new org.acme.ProjectionClass(e.field1, e.field2) from EntityClass e
if (lowerCasedTrimmedQuery.startsWith("select ")) {
int endSelect = lowerCasedTrimmedQuery.indexOf(" from ");
String trimmedQuery = query.trim().replace(lineSeparator, " ");
String trimmedQuery = query.trim().replace('\n', ' ').replace('\r', ' ');
// 7 is the length of "select "
String selectClause = trimmedQuery.substring(7, endSelect).trim();
String from = trimmedQuery.substring(endSelect);
Expand Down

0 comments on commit ffb3f26

Please sign in to comment.