From c91fcadea88d1d7ba9adc01eea42ace8b01cd18e Mon Sep 17 00:00:00 2001 From: Alex Shpak Date: Wed, 7 Nov 2018 18:10:08 +0100 Subject: [PATCH] Add support for JDBI 3, drop JDBI 2 --- build.gradle | 4 ++-- .../dropwizard/hk2bundle/jdbi/HandleFactory.java | 12 ++++++------ .../dropwizard/hk2bundle/jdbi/JDBIBinder.java | 6 +++--- .../dropwizard/hk2bundle/jdbi/JDBIFactory.java | 12 ++++++------ .../dropwizard/hk2bundle/jdbi/SqlObjectFactory.java | 12 ++++++------ .../dropwizard/hk2bundle/ExampleAppBinder.java | 4 +--- .../dropwizard/hk2bundle/jdbi/ExampleDAO.java | 6 ++---- 7 files changed, 26 insertions(+), 30 deletions(-) diff --git a/build.gradle b/build.gradle index 3736d62..e5c8b92 100644 --- a/build.gradle +++ b/build.gradle @@ -11,11 +11,11 @@ repositories { dependencies { compile "io.dropwizard:dropwizard-core:$dropwizardVersion" compile "org.glassfish.hk2:hk2-extras:2.5.0-b32" - compileOnly "io.dropwizard:dropwizard-jdbi:$dropwizardVersion" + compileOnly "io.dropwizard:dropwizard-jdbi3:$dropwizardVersion" testCompile "junit:junit:$junitVersion" testCompile "com.h2database:h2:1.4.197" - testCompile "io.dropwizard:dropwizard-jdbi:$dropwizardVersion" + testCompile "io.dropwizard:dropwizard-jdbi3:$dropwizardVersion" } compileJava { diff --git a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/HandleFactory.java b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/HandleFactory.java index 5d26f0f..9a8d3b3 100644 --- a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/HandleFactory.java +++ b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/HandleFactory.java @@ -2,8 +2,8 @@ import org.glassfish.hk2.api.Factory; import org.glassfish.jersey.process.internal.RequestScoped; -import org.skife.jdbi.v2.DBI; -import org.skife.jdbi.v2.Handle; +import org.jdbi.v3.core.Handle; +import org.jdbi.v3.core.Jdbi; import javax.inject.Inject; import javax.inject.Provider; @@ -15,17 +15,17 @@ @Singleton public class HandleFactory implements Factory { - private final Provider dbi; + private final Provider jdbi; @Inject - public HandleFactory(Provider dbi) { - this.dbi = dbi; + public HandleFactory(Provider jdbi) { + this.jdbi = jdbi; } @Override @RequestScoped public Handle provide() { - return dbi.get().open(); + return jdbi.get().open(); } @Override diff --git a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIBinder.java b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIBinder.java index a0c7c48..41323a4 100644 --- a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIBinder.java +++ b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIBinder.java @@ -4,7 +4,7 @@ import io.dropwizard.db.DatabaseConfiguration; import org.glassfish.hk2.api.Factory; import org.glassfish.hk2.utilities.binding.AbstractBinder; -import org.skife.jdbi.v2.DBI; +import org.jdbi.v3.core.Jdbi; import javax.inject.Singleton; import java.util.Collections; @@ -19,7 +19,7 @@ */ public class JDBIBinder extends AbstractBinder { - private Class> dbiFactory = JDBIFactory.class; + private Class> dbiFactory = JDBIFactory.class; private Class> sqlObjectFactory = SqlObjectFactory.class; private DatabaseConfiguration databaseConfiguration; @@ -39,7 +39,7 @@ public JDBIBinder(DatabaseConfiguration databaseConfiguration) { * @return self * @see JDBIFactory */ - public JDBIBinder setDBIFactory(Class> dbiFactory) { + public JDBIBinder setDBIFactory(Class> dbiFactory) { this.dbiFactory = requireNonNull(dbiFactory); return this; } diff --git a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIFactory.java b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIFactory.java index 15bcf75..6dbe2cf 100644 --- a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIFactory.java +++ b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/JDBIFactory.java @@ -3,18 +3,18 @@ import io.dropwizard.Configuration; import io.dropwizard.db.DatabaseConfiguration; import io.dropwizard.db.PooledDataSourceFactory; -import io.dropwizard.jdbi.DBIFactory; +import io.dropwizard.jdbi3.JdbiFactory; import io.dropwizard.setup.Environment; import org.glassfish.hk2.api.Factory; -import org.skife.jdbi.v2.DBI; +import org.jdbi.v3.core.Jdbi; import javax.inject.Inject; import javax.inject.Singleton; @Singleton -public class JDBIFactory implements Factory { +public class JDBIFactory implements Factory { - private final DBIFactory factory = new DBIFactory(); + private final JdbiFactory factory = new JdbiFactory(); private final String name = getClass().getSimpleName(); private final Environment environment; @@ -31,13 +31,13 @@ public JDBIFactory(Environment environment, Configuration configuration, @Override @Singleton - public DBI provide() { + public Jdbi provide() { PooledDataSourceFactory dataSourceFactory = databaseConfiguration.getDataSourceFactory(configuration); return factory.build(environment, dataSourceFactory, name); } @Override - public void dispose(DBI instance) { + public void dispose(Jdbi instance) { } } diff --git a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/SqlObjectFactory.java b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/SqlObjectFactory.java index 0623e2e..4a91166 100644 --- a/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/SqlObjectFactory.java +++ b/src/main/java/net/winterly/dropwizard/hk2bundle/jdbi/SqlObjectFactory.java @@ -3,7 +3,7 @@ import org.glassfish.hk2.api.ActiveDescriptor; import org.glassfish.hk2.api.Factory; import org.glassfish.hk2.api.Self; -import org.skife.jdbi.v2.DBI; +import org.jdbi.v3.core.Jdbi; import javax.inject.Inject; import javax.inject.Provider; @@ -20,24 +20,24 @@ @Singleton public class SqlObjectFactory implements Factory { - private final Provider dbi; + private final Provider jdbi; private final ActiveDescriptor activeDescriptor; @Inject - public SqlObjectFactory(Provider dbi, @Self ActiveDescriptor activeDescriptor) { + public SqlObjectFactory(Provider dbi, @Self ActiveDescriptor activeDescriptor) { this.activeDescriptor = activeDescriptor; - this.dbi = dbi; + this.jdbi = dbi; } @Override public Object provide() { Class daoInterface = extractDaoType(activeDescriptor); - return dbi.get().onDemand(daoInterface); + return jdbi.get().onDemand(daoInterface); } @Override public void dispose(Object instance) { - dbi.get().close(instance); + } private Class extractDaoType(ActiveDescriptor activeDescriptor) { diff --git a/src/test/java/net/winterly/dropwizard/hk2bundle/ExampleAppBinder.java b/src/test/java/net/winterly/dropwizard/hk2bundle/ExampleAppBinder.java index d4ae821..f8c0168 100644 --- a/src/test/java/net/winterly/dropwizard/hk2bundle/ExampleAppBinder.java +++ b/src/test/java/net/winterly/dropwizard/hk2bundle/ExampleAppBinder.java @@ -3,13 +3,11 @@ import net.winterly.dropwizard.hk2bundle.health.ExampleHealthCheck; import net.winterly.dropwizard.hk2bundle.metric.ExampleGauge; import net.winterly.dropwizard.hk2bundle.spi.DropwizardBinder; -import net.winterly.dropwizard.hk2bundle.validation.InjectValidatorBundle; public class ExampleAppBinder extends DropwizardBinder { + @Override protected void configure() { - bundle(InjectValidatorBundle.class); - metric(ExampleGauge.class); healthCheck(ExampleHealthCheck.class); } diff --git a/src/test/java/net/winterly/dropwizard/hk2bundle/jdbi/ExampleDAO.java b/src/test/java/net/winterly/dropwizard/hk2bundle/jdbi/ExampleDAO.java index 31182af..34b961f 100644 --- a/src/test/java/net/winterly/dropwizard/hk2bundle/jdbi/ExampleDAO.java +++ b/src/test/java/net/winterly/dropwizard/hk2bundle/jdbi/ExampleDAO.java @@ -1,10 +1,8 @@ package net.winterly.dropwizard.hk2bundle.jdbi; -import org.glassfish.hk2.api.UseProxy; -import org.skife.jdbi.v2.sqlobject.Bind; -import org.skife.jdbi.v2.sqlobject.SqlQuery; +import org.jdbi.v3.sqlobject.customizer.Bind; +import org.jdbi.v3.sqlobject.statement.SqlQuery; -@UseProxy public interface ExampleDAO { @SqlQuery("SELECT :i")