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

org.itsallcode.jdbc.DbDialectFactory Maven / Gradle / Ivy

There is a newer version: 0.7.1
Show newest version
package org.itsallcode.jdbc;

import java.util.ServiceLoader;
import java.util.ServiceLoader.Provider;

import org.itsallcode.jdbc.dialect.DbDialect;

class DbDialectFactory {
    public DbDialect createDialect(final String url) {
        final ServiceLoader serviceLoader = ServiceLoader.load(DbDialect.class,
                DbDialect.class.getClassLoader());
        return serviceLoader.stream()
                .map(Provider::get)
                .filter(dialect -> dialect.supportsUrl(url))
                .findAny()
                .orElseThrow(() -> new IllegalStateException("No DB dialect registered for JDBC URL '" + url + "'"));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy