org.itsallcode.jdbc.DbDialectFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simple-jdbc Show documentation
Show all versions of simple-jdbc Show documentation
Library to simplify using JDBC
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 + "'"));
}
}