org.zodiac.fastorm.rdb.utils.FeatureUtils Maven / Gradle / Ivy
The newest version!
package org.zodiac.fastorm.rdb.utils;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
import org.zodiac.fastorm.core.FeatureType;
import org.zodiac.fastorm.core.meta.Feature;
import org.zodiac.fastorm.core.meta.FeatureSupportedMetadata;
import org.zodiac.fastorm.core.meta.ObjectMetadata;
public abstract class FeatureUtils {
private FeatureUtils() {
super();
}
private static boolean R2DBC_IS_ALIVE;
static {
try {
Class.forName("io.r2dbc.spi.Connection");
R2DBC_IS_ALIVE = true;
} catch (ClassNotFoundException e) {
R2DBC_IS_ALIVE = false;
}
}
public static boolean r2dbcIsAlive() {
return R2DBC_IS_ALIVE;
}
public static String featureToString(List features) {
StringBuilder builder = new StringBuilder();
Map> featureMap = features
.stream()
.collect(Collectors.groupingBy(Feature::getType
, () -> new TreeMap<>(Comparator.comparing(FeatureType::getId))
, Collectors.toList()));
for (Map.Entry> entry : featureMap.entrySet()) {
builder.append("--").append(entry.getKey().getId())
.append(" (").append(entry.getKey().getName())
.append(")")
.append("\n");
for (Feature feature : entry.getValue()) {
builder.append("-----|---- ")
.append(feature.getId())
.append(" (")
.append(feature.getName())
.append(")")
.append("\t").append(feature.getClass().getSimpleName())
.append("\n");
}
}
return builder.toString();
}
public static String metadataToString(ObjectMetadata metadata) {
StringBuilder builder = new StringBuilder();
builder.append(metadata.getObjectType().getId())
.append("(")
.append(metadata.getObjectType().getName())
.append(")");
if (metadata instanceof FeatureSupportedMetadata) {
builder.append("\n")
.append(featureToString(((FeatureSupportedMetadata) metadata).getFeatureList()));
}
return builder.toString();
}
}