Skip to content

Instantly share code, notes, and snippets.

@Eng-Fouad
Last active December 29, 2023 20:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eng-Fouad/7b5925481dd391fcc74487a68484b987 to your computer and use it in GitHub Desktop.
Save Eng-Fouad/7b5925481dd391fcc74487a68484b987 to your computer and use it in GitHub Desktop.
Using JDBI in Quarkus (native mode) [JDBI 3.38.2]
quarkus.native.additional-build-args=-H:ReflectionConfigurationFiles=reflection-config.json,-H:DynamicProxyConfigurationFiles=proxy-config.json
[
{ "interfaces": [ "io.fouad.demo.db.UserDao" ] },
{ "interfaces": [ "io.fouad.demo.db.FooDao" ] }
]
[
{"name":"org.jdbi.v3.core.statement.SqlStatements","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.statement.StatementExceptions","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.argument.Arguments","methods":[{"name":"<init>","parameterTypes":["org.jdbi.v3.core.config.ConfigRegistry"]}]},
{"name":"org.jdbi.v3.core.mapper.RowMappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.mapper.ColumnMappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.mapper.Mappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.mapper.MapMappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.mapper.MapEntryMappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.mapper.reflect.ReflectionMappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.mapper.reflect.internal.PojoTypes","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.collector.JdbiCollectors","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.qualifier.Qualifiers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.result.ResultProducers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.array.SqlArrayTypes","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.transaction.SerializableTransactionRunner$Configuration","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.extension.Extensions","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.internal.OnDemandExtensions","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.internal.EnumStrategies","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.config.internal.ConfigCaches","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.enums.Enums","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.Handles","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.Handlers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.HandlerDecorators","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.SqlObjects","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.SqlObject","methods":[{"name":"getHandle"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterRowMapperImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.transaction.internal.TransactionDecorator","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.TimestampedConfig","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.BindFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.BindListFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.statement.internal.SqlObjectStatementConfiguration","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.statement.internal.SqlQueryHandler","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.statement.internal.SqlUpdateHandler","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.postgres.PostgresTypes","methods":[{"name":"<init>"}]}
]
package io.fouad.demo.db;
public interface UserDao {
@SqlUpdate("CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR)")
void createTable();
@SqlUpdate("INSERT INTO user(id, name) VALUES (?, ?)")
void insertPositional(int id, String name);
@SqlUpdate("INSERT INTO user(id, name) VALUES (:id, :name)")
void insertNamed(@Bind("id") int id, @Bind("name") String name);
@SqlUpdate("INSERT INTO user(id, name) VALUES (:id, :name)")
void insertBean(@BindBean User user);
@SqlQuery("SELECT * FROM user ORDER BY name")
@RegisterBeanMapper(User.class)
List<User> listUsers();
}
@Eng-Fouad
Copy link
Author

Eng-Fouad commented Jul 26, 2022

Sample project that runs JDBI on Quarkus native image: https://github.com/Eng-Fouad/jdbi-quarkus-native

@Eng-Fouad
Copy link
Author

Eng-Fouad commented Jul 26, 2022

Include these classes only if the corresponding annotation is used:

{"name":"org.jdbi.v3.sqlobject.config.internal.KeyColumnImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterArgumentFactoriesImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterArgumentFactoryImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterBeanMapperImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterBeanMappersImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterCollectorFactoryImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterColumnMapperImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterColumnMapperFactoriesImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterColumnMapperFactoryImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterColumnMappersImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterConstructorMapperImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterConstructorMappersImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterFieldMapperImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterFieldMappersImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterJoinRowMapperImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterObjectArgumentFactoriesImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterObjectArgumentFactoryImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterRowMapperImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterRowMapperFactoriesImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterRowMapperFactoryImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.RegisterRowMappersImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.UseEnumStrategyImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.UseSqlParserImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.UseTemplateEngineImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.config.internal.ValueColumnImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.locator.internal.UseAnnotationSqlLocatorImpl","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.locator.internal.UseClasspathSqlLocatorImpl","methods":[{"name":"<init>"}]},
@org.jdbi.v3.sqlobject.config.KeyColumn
@org.jdbi.v3.sqlobject.config.RegisterArgumentFactories
@org.jdbi.v3.sqlobject.config.RegisterArgumentFactory
@org.jdbi.v3.sqlobject.config.RegisterBeanMapper
@org.jdbi.v3.sqlobject.config.RegisterBeanMappers
@org.jdbi.v3.sqlobject.config.RegisterCollectorFactory
@org.jdbi.v3.sqlobject.config.RegisterColumnMapper
@org.jdbi.v3.sqlobject.config.RegisterColumnMapperFactories
@org.jdbi.v3.sqlobject.config.RegisterColumnMapperFactory
@org.jdbi.v3.sqlobject.config.RegisterColumnMappers
@org.jdbi.v3.sqlobject.config.RegisterConstructorMapper
@org.jdbi.v3.sqlobject.config.RegisterConstructorMappers
@org.jdbi.v3.sqlobject.config.RegisterFieldMapper
@org.jdbi.v3.sqlobject.config.RegisterFieldMappers
@org.jdbi.v3.sqlobject.config.RegisterJoinRowMapper
@org.jdbi.v3.sqlobject.config.RegisterObjectArgumentFactories
@org.jdbi.v3.sqlobject.config.RegisterObjectArgumentFactory
@org.jdbi.v3.sqlobject.config.RegisterRowMapper
@org.jdbi.v3.sqlobject.config.RegisterRowMapperFactories
@org.jdbi.v3.sqlobject.config.RegisterRowMapperFactory
@org.jdbi.v3.sqlobject.config.RegisterRowMappers
@org.jdbi.v3.sqlobject.config.UseEnumStrategy
@org.jdbi.v3.sqlobject.config.UseSqlParser
@org.jdbi.v3.sqlobject.config.UseTemplateEngine
@org.jdbi.v3.sqlobject.config.ValueColumn
@org.jdbi.v3.sqlobject.locator.UseAnnotationSqlLocator
@org.jdbi.v3.sqlobject.locator.UseClasspathSqlLocator

@Eng-Fouad
Copy link
Author

Include these classes only if the corresponding annotation is used:

{"name":"org.jdbi.v3.sqlobject.statement.internal.MapToFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.statement.internal.SqlBatchHandler","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.statement.internal.SqlCallHandler","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.statement.internal.SqlQueryHandler","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.statement.internal.SqlScriptsHandler","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.statement.internal.SqlUpdateHandler","methods":[{"name":"<init>"}]},
@org.jdbi.v3.sqlobject.statement.MapTo
@org.jdbi.v3.sqlobject.statement.SqlBatch
@org.jdbi.v3.sqlobject.statement.SqlCall
@org.jdbi.v3.sqlobject.statement.SqlQuery
@org.jdbi.v3.sqlobject.statement.SqlScripts
@org.jdbi.v3.sqlobject.statement.SqlUpdate

@Eng-Fouad
Copy link
Author

Include these classes only if the corresponding annotation is used:

{"name":"org.jdbi.v3.sqlobject.customizer.internal.AllowUnusedBindingsFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.BindFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.BindBeanFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.BindBeanListFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.BindFieldsFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.BindListFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.BindMapFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.BindMethodsFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.BindMethodsListFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.BindPojoFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.DefineFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.DefineListFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.DefineNamedBindingsFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.FetchSizeFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.MaxRowsFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.OutParameterFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.OutParameterListFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.QueryTimeOutFactory","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.customizer.internal.TimestampedFactory","methods":[{"name":"<init>"}]},
@org.jdbi.v3.sqlobject.customizer.AllowUnusedBindings
@org.jdbi.v3.sqlobject.customizer.Bind
@org.jdbi.v3.sqlobject.customizer.BindBean
@org.jdbi.v3.sqlobject.customizer.BindBeanList
@org.jdbi.v3.sqlobject.customizer.BindFields
@org.jdbi.v3.sqlobject.customizer.BindList
@org.jdbi.v3.sqlobject.customizer.BindMap
@org.jdbi.v3.sqlobject.customizer.BindMethods
@org.jdbi.v3.sqlobject.customizer.BindMethodsList
@org.jdbi.v3.sqlobject.customizer.BindPojo
@org.jdbi.v3.sqlobject.customizer.Define
@org.jdbi.v3.sqlobject.customizer.DefineList
@org.jdbi.v3.sqlobject.customizer.DefineNamedBindings
@org.jdbi.v3.sqlobject.customizer.FetchSize
@org.jdbi.v3.sqlobject.customizer.MaxRows
@org.jdbi.v3.sqlobject.customizer.OutParameter
@org.jdbi.v3.sqlobject.customizer.OutParameterList
@org.jdbi.v3.sqlobject.customizer.QueryTimeOut
@org.jdbi.v3.sqlobject.customizer.Timestamped

@Eng-Fouad
Copy link
Author

Eng-Fouad commented Jul 26, 2022

Include the following classes always, if org.jdbi:jdbi3-core artifact is used (all the time):

{"name":"org.jdbi.v3.core.config.JdbiCaches","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.statement.SqlStatements","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.argument.Arguments","methods":[{"name":"<init>","parameterTypes":["org.jdbi.v3.core.config.ConfigRegistry"]}]},
{"name":"org.jdbi.v3.core.mapper.RowMappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.mapper.ColumnMappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.mapper.Mappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.collector.JdbiCollectors","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.statement.StatementExceptions","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.Handles","methods":[{"name":"<init>"}]},
{"name":"com.github.benmanes.caffeine.cache.CacheLoader","methods":[{"name":"loadAll","parameterTypes":["java.lang.Iterable"]}]},
{"name":"com.github.benmanes.caffeine.cache.PSMS","methods":[{"name":"<init>"}]},
{"name":"com.github.benmanes.caffeine.cache.SSMS","methods":[{"name":"<init>","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"]}]}

Note: Include other Caffeine classes, only if the constructors ColonPrefixSqlParser(Caffeine<Object, Object> cache) or HashPrefixSqlParser(final Caffeine<Object, Object> cache) with customized Caffeine object is invoked. The cache classes are in com.github.benmanes.caffeine.cache.* package with class name all capitalized.

Include the following class, when result set is returned (almost all time):

{"name":"org.jdbi.v3.core.result.ResultProducers","methods":[{"name":"<init>"}]},

Include the following class, if Jdbi.onDemand(java.lang.Class) is invoked:

{"name":"org.jdbi.v3.core.internal.OnDemandExtensions","methods":[{"name":"<init>"}]},

Include the following class, when arrays are used:

{"name":"org.jdbi.v3.core.array.SqlArrayTypes","methods":[{"name":"<init>"}]},

Include the following classes, when enums are used:

{"name":"org.jdbi.v3.core.internal.EnumStrategies","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.enums.Enums","methods":[{"name":"<init>"}]},

Include the following class, when transactions are used:

{"name":"org.jdbi.v3.core.transaction.SerializableTransactionRunner$Configuration","methods":[{"name":"<init>"}]},

Include the following class, when extensions (e.g. UserDao class) are used:

{"name":"org.jdbi.v3.core.extension.Extensions","methods":[{"name":"<init>"}]},

@Eng-Fouad
Copy link
Author

Eng-Fouad commented Jul 26, 2022

Include the following classes always, if org.jdbi:jdbi3-sqlobject artifact is used and jdbi.installPlugin(new SqlObjectPlugin()) is invoked:

{"name":"org.jdbi.v3.core.internal.OnDemandExtensions","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.statement.internal.SqlObjectStatementConfiguration","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.Handlers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.HandlerDecorators","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.sqlobject.SqlObject","methods":[{"name":"getHandle"}]},

Include the following class, only if annotation @org.jdbi.v3.sqlobject.customizer.Timestamped is used:

{"name":"org.jdbi.v3.sqlobject.customizer.TimestampedConfig","methods":[{"name":"<init>"}]},

Include the following class, only if one of the annotations that follows is used:

{"name":"org.jdbi.v3.sqlobject.SqlObjects","methods":[{"name":"<init>"}]},
@org.jdbi.v3.sqlobject.locator.UseAnnotationSqlLocator
@org.jdbi.v3.sqlobject.locator.UseClasspathSqlLocator
@org.jdbi.v3.sqlobject.statement.SqlBatch
@org.jdbi.v3.sqlobject.statement.SqlCall
@org.jdbi.v3.sqlobject.statement.SqlQuery
@org.jdbi.v3.sqlobject.statement.SqlScripts
@org.jdbi.v3.sqlobject.statement.SqlUpdate

@Eng-Fouad
Copy link
Author

Eng-Fouad commented Jul 26, 2022

Include the following class always, if org.jdbi:jdbi3-postgres artifact is used and jdbi.installPlugin(new PostgresPlugin()) is invoked:

{"name":"org.jdbi.v3.postgres.PostgresTypes","methods":[{"name":"<init>"}]},

@Eng-Fouad
Copy link
Author

Eng-Fouad commented Jul 26, 2022

The following classes I am not sure when to include them:

{"name":"org.jdbi.v3.core.mapper.MapMappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.mapper.MapEntryMappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.mapper.reflect.ReflectionMappers","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.mapper.reflect.internal.PojoTypes","methods":[{"name":"<init>"}]},
{"name":"org.jdbi.v3.core.qualifier.Qualifiers","methods":[{"name":"<init>"}]},

To be in safe side, just include them all.

@Eng-Fouad
Copy link
Author

Include the following class, if Immutables is used:

{"name":"org.jdbi.v3.core.mapper.immutables.JdbiImmutables","methods":[{"name":"<init>"}]},

Include the following class, if FreeBuilders is used:

{"name":"org.jdbi.v3.core.mapper.freebuilder.JdbiFreeBuilders","methods":[{"name":"<init>"}]},

@Eng-Fouad
Copy link
Author

I didn't test the other modules that Jdbi already supports:

jdbi3-guava
Support for Guava’s collection and Optional types.

jdbi3-jodatime2
Support for JodaTime v2’s DateTime type.

jdbi3-jpa
Minimal support for JPA annotations.

jdbi3-kotlin
Automatically map kotlin data classes.

jdbi3-kotlin-sqlobject
Enhance the SQL Object extension to support Kotlin default methods and method default parameters.

jdbi3-oracle12
Support Oracle returning DML statements.

jdbi3-spring5
Provides a factory bean to set up Jdbi singleton.

jdbi3-stringtemplate4
Use the StringTemplate4 template engine, instead of JDBI’s built in engine.

jdbi3-vavr
Support for Vavr Tuples, Collections and Value arguments

@smil2k
Copy link

smil2k commented Jul 26, 2022

great write up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment