package com.zaxxer.hikari.hibernate;
import java.util.Map;
import java.util.Properties;
import org.hibernate.cfg.AvailableSettings;
import com.zaxxer.hikari.HikariConfig;
public class HikariConfigurationUtil
{
public static final String CONFIG_PREFIX = "hibernate.hikari.";
public static final String CONFIG_PREFIX_DATASOURCE = "hibernate.hikari.dataSource.";
@SuppressWarnings("rawtypes")
public static HikariConfig loadConfiguration(Map props)
{
Properties hikariProps = new Properties();
copyProperty(AvailableSettings.ISOLATION, props, "transactionIsolation", hikariProps);
copyProperty(AvailableSettings.AUTOCOMMIT, props, "autoCommit", hikariProps);
copyProperty(AvailableSettings.DRIVER, props, "driverClassName", hikariProps);
copyProperty(AvailableSettings.URL, props, "jdbcUrl", hikariProps);
copyProperty(AvailableSettings.USER, props, "username", hikariProps);
copyProperty(AvailableSettings.PASS, props, "password", hikariProps);
for (Object keyo : props.keySet()) {
String key = (String) keyo;
if (key.startsWith(CONFIG_PREFIX)) {
hikariProps.setProperty(key.substring(CONFIG_PREFIX.length()), (String) props.get(key));
}
}
return new HikariConfig(hikariProps);
}
@SuppressWarnings("rawtypes")
private static void copyProperty(String srcKey, Map src, String dstKey, Properties dst)
{
if (src.containsKey(srcKey)) {
dst.setProperty(dstKey, (String) src.get(srcKey));
}
}
}