Skip to content
Snippets Groups Projects

feat(HQLGenerator): adding decorator with node name

Merged Jordi Gómez requested to merge gnugomez/eclipsefdn-api-common:gnugomez/main/90 into main
Files
2
@@ -11,6 +11,8 @@
**********************************************************************/
package org.eclipsefoundation.persistence.model;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
@@ -49,7 +51,7 @@ public class HQLGenerator implements SQLGenerator {
} else if (SortOrder.RANDOM.equals(src.getOrder())) {
sb.append(" order by RAND()");
}
return sb.toString();
return decorateWithNodeName(sb).toString();
}
@Override
@@ -68,7 +70,7 @@ public class HQLGenerator implements SQLGenerator {
// retrieve the where clauses
sb.append(getWhereClause(src));
return sb.toString();
return decorateWithNodeName(sb).toString();
}
private String getFromClause(ParameterizedSQLStatement src) {
@@ -136,4 +138,18 @@ public class HQLGenerator implements SQLGenerator {
return sb.toString();
}
/**
* Appends a comment containing the local host's name to the provided StringBuilder.
* If the local host's name cannot be determined, the original StringBuilder is returned unchanged.
*
* @param sb the StringBuilder to which the comment will be appended
* @return the StringBuilder with the appended comment, or the original StringBuilder if the host name cannot be determined
*/
private StringBuilder decorateWithNodeName(StringBuilder sb) {
try {
return sb.append(String.format(" /* node name: %s */", InetAddress.getLocalHost().getHostName()));
} catch (UnknownHostException e) {
return sb;
}
}
}
Loading