io.hypersistence.utils.logging.InlineQueryLogEntryCreator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hypersistence-utils-hibernate-62 Show documentation
Show all versions of hypersistence-utils-hibernate-62 Show documentation
Utilities for Spring and Hibernate ORM 6.2 or newer
package io.hypersistence.utils.logging;
import net.ttddyy.dsproxy.ExecutionInfo;
import net.ttddyy.dsproxy.QueryInfo;
import net.ttddyy.dsproxy.listener.logging.DefaultQueryLogEntryCreator;
import java.util.*;
/**
* @author Vlad Mihalcea
*/
public class InlineQueryLogEntryCreator extends DefaultQueryLogEntryCreator {
@Override
protected void writeParamsEntry(StringBuilder sb, ExecutionInfo execInfo, List queryInfoList) {
sb.append("Params:[");
for (QueryInfo queryInfo : queryInfoList) {
boolean firstArg = true;
for (Map paramMap : queryInfo.getQueryArgsList()) {
if (!firstArg) {
sb.append(", ");
} else {
firstArg = false;
}
SortedMap sortedParamMap = new TreeMap(new CustomStringAsIntegerComparator());
sortedParamMap.putAll(paramMap);
sb.append("(");
boolean firstParam = true;
for (Map.Entry paramEntry : sortedParamMap.entrySet()) {
if (!firstParam) {
sb.append(", ");
} else {
firstParam = false;
}
Object parameter = paramEntry.getValue();
if (parameter != null && parameter.getClass().isArray()) {
sb.append(arrayToString(parameter));
} else {
sb.append(parameter);
}
}
sb.append(")");
}
}
sb.append("]");
}
private String arrayToString(Object object) {
if (object.getClass().isArray()) {
if (object instanceof byte[]) {
return Arrays.toString((byte[]) object);
}
if (object instanceof short[]) {
return Arrays.toString((short[]) object);
}
if (object instanceof char[]) {
return Arrays.toString((char[]) object);
}
if (object instanceof int[]) {
return Arrays.toString((int[]) object);
}
if (object instanceof long[]) {
return Arrays.toString((long[]) object);
}
if (object instanceof float[]) {
return Arrays.toString((float[]) object);
}
if (object instanceof double[]) {
return Arrays.toString((double[]) object);
}
if (object instanceof boolean[]) {
return Arrays.toString((boolean[]) object);
}
if (object instanceof Object[]) {
return Arrays.toString((Object[]) object);
}
}
throw new UnsupportedOperationException("Array type not supported: " + object.getClass());
}
private static class CustomStringAsIntegerComparator extends StringAsIntegerComparator {
}
}