org.hotrod.utils.SQLUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hotrod-generator Show documentation
Show all versions of hotrod-generator Show documentation
HotRod is an ORM for Java, Spring and SpringBoot.
The newest version!
package org.hotrod.utils;
import org.nocrala.tools.lang.collector.listcollector.ListWriter;
public class SQLUtil {
public static String cleanUpSQL(final String select) {
ListWriter lw = new ListWriter("\n");
String[] lines = select.split("\n");
// Trim lines and remove empty ones
for (String line : lines) {
String trimmed = line.trim();
if (!trimmed.isEmpty()) {
lw.add(line);
}
}
// Remove trailing semicolons
String reassembled = lw.toString();
while (reassembled.endsWith(";")) {
reassembled = reassembled.substring(0, reassembled.length() - 1);
}
return reassembled.trim();
}
}