All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openl.rules.ext.cassandra.ConfigLoader Maven / Gradle / Ivy

There is a newer version: 5.27.9
Show newest version
package org.openl.rules.ext.cassandra;

/*-
 * #%L
 * OpenL - EXT - Cassandra
 * %%
 * Copyright (C) 2019 OpenL Tablets
 * %%
 * See the file LICENSE.txt for copying permission.
 * #L%
 */

import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;

public final class ConfigLoader {

    private ConfigLoader() {
    }

    public static DriverConfigLoader fromProjectResource(String resource) {
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(ConfigLoader.class.getClassLoader());
            return new DefaultDriverConfigLoader(() -> {
                ConfigFactory.invalidateCaches();
                Config config = ConfigFactory.defaultOverrides()
                    .withFallback(ConfigFactory.parseResourcesAnySyntax(ConfigLoader.class.getClassLoader(), resource))
                    .withFallback(ConfigFactory.defaultReference())
                    .resolve();
                return config.getConfig(DefaultDriverConfigLoader.DEFAULT_ROOT_PATH);
            });
        } finally {
            Thread.currentThread().setContextClassLoader(oldClassLoader);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy