### SQL Object Usage Examples Source: https://jdbi.org/releases/3.40.0/apidocs/org/jdbi/v3/sqlobject/package-summary.html Demonstrates how to install the SqlObjectPlugin and obtain/use SQL object instances via lambda, handle attachment, and on-demand. ```APIDOC ## SQL Objects API ### Description The SQL Objects API allows for declarative definition of interfaces which will handle the generation of statements and queries on your behalf when needed. ### Installation ```java Jdbi jdbi = Jdbi.create(dataSource); jdbi.installPlugin(new SqlObjectPlugin()); ``` ### Usage Patterns #### 1. Lambda-based Usage (`useExtension` and `withExtension`) Obtain a short-lived instance of a SQL object interface within a lambda. `withExtension` returns the lambda's result, while `useExtension` is for void methods. ```java // Example interface public interface TheBasics { @SqlUpdate("insert into something (id, name) values (:id, :name)") int insert(@BindBean Something something); @SqlQuery("select id, name from something where id = :id") Something findById(@Bind("id") long id); } // Usage jdbi.useExtension(TheBasics.class, theBasics -> theBasics.insert(new Something(1, "Alice"))); Something result = jdbi.withExtension(TheBasics.class, theBasics -> theBasics.findById(1)); ``` #### 2. Handle-attached Instance Get a SQL object instance attached to a specific `Handle`. The instance's lifecycle is tied to the handle's. ```java // Usage try (Handle handle = jdbi.open()) { TheBasics attached = handle.attach(TheBasics.class); attached.insert(new Something(2, "Bob")); Something result = attached.findById(2); } ``` #### 3. On-Demand Instance Request an instance that obtains and releases connections for each method call. These are thread-safe and suitable for single calls. ```java // Usage TheBasics onDemand = jdbi.onDemand(TheBasics.class); onDemand.insert(new Something(3, "Chris")); Something result = onDemand.findById(3); ``` ### Default Methods Interfaces can include default methods that can invoke other methods within the same interface. ```java public interface DefaultMethods { @SqlQuery("select * from folders where id = :id") Folder getFolderById(int id); @SqlQuery("select * from documents where folder_id = :folderId") List getDocuments(int folderId); default Node getFolderByIdWithDocuments(int id) { Node result = getById(id); result.setChildren(listByParendId(id)); return result; } } ``` ### Mixin Interfaces SQL objects implicitly implement `SqlObject`, providing a `getHandle()` method to access the core Jdbi API. ```java public interface UsingMixins extends SqlObject { @RegisterBeanMapper(value={Folder.class, Document.class}, prefix={\"f\", \"d\"}) default Folder getFolder(int id) { return getHandle().createQuery( "select f.id f_id, f.name f_name, " + "d.id d_id, d.name d_name, d.contents d_contents " + "from folders f left join documents d " + "on f.id = d.folder_id " + "where f.id = :folderId") .bind("folderId", id) .reduceRows(Optional.empty(), (folder, row) -> { Folder f = folder.orElseGet(() -> row.getRow(Folder.class)); if (row.getColumn("d_id", Integer.class) != null) { f.getDocuments().add(row.getRow(Document.class)); } return Optional.of(f); }); } } ``` ``` -------------------------------- ### Install JdbiPlugin Source: https://jdbi.org/apidocs/org/jdbi/v3/core/spi/class-use/JdbiPlugin.html Demonstrates how to install a JdbiPlugin instance to configure Handle instances. ```APIDOC ## Jdbi.installPlugin(JdbiPlugin plugin) ### Description Installs a given `JdbiPlugin` instance. This plugin will then configure any provided `Handle` instances, allowing for custom functionality to be integrated with Jdbi. ### Method `Jdbi.installPlugin` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java Jdbi jdbi = Jdbi.create("jdbc:h2:mem:testdb"); CaffeineCachePlugin plugin = new CaffeineCachePlugin(); jdbi.installPlugin(plugin); ``` ### Response #### Success Response This method does not return a value, but the plugin is installed and configured. #### Response Example None ``` -------------------------------- ### SQL Object Plugin Installation Source: https://jdbi.org/releases/3.32.0/apidocs/org/jdbi/v3/sqlobject/package-summary.html Demonstrates how to install the SQL Object plugin for Jdbi. ```APIDOC ## SQL Object Plugin Installation ### Description To use the SQL Objects API, you need to install the `SqlObjectPlugin` with your Jdbi instance. ### Example Usage ```java Jdbi jdbi = Jdbi.create(dataSource); jdbi.installPlugin(new SqlObjectPlugin()); ``` ``` -------------------------------- ### Install and Configure Moshi Plugin Source: https://jdbi.org/ Installs the Moshi plugin and optionally configures the Moshi instance for JDBI. ```java jdbi.installPlugin(new MoshiPlugin()); // optional jdbi.getConfig(MoshiConfig.class).setMoshi(myMoshi); ``` -------------------------------- ### Install MySQL Plugin Source: https://jdbi.org/ Install the MysqlPlugin into the Jdbi instance to enable MySQL-specific features. ```java Jdbi jdbi = Jdbi.create("jdbc:mysql://host:port/database") .installPlugin(new MysqlPlugin()); ``` -------------------------------- ### withPlugins() Source: https://jdbi.org/releases/3.47.0/apidocs/org/jdbi/v3/testing/JdbiRule.html Discovers and installs Jdbi plugins available on the classpath. It is recommended to install plugins explicitly instead. ```APIDOC ## withPlugins() ### Description Discover and install plugins from the classpath. See also: we recommend installing plugins explicitly instead. ### Method `public JdbiRule withPlugins()` ``` -------------------------------- ### Install and Configure Gson 2 Plugin Source: https://jdbi.org/ Installs the Gson 2 plugin and optionally configures the Gson instance for JDBI. ```java jdbi.installPlugin(new Gson2Plugin()); // optional jdbi.getConfig(Gson2Config.class).setGson(myGson); ``` -------------------------------- ### Programmatic Registration Example Source: https://jdbi.org/releases/3.41.3/apidocs/org/jdbi/v3/testing/junit5/JdbiExtension.html Programmatic registration is preferred as it allows further customization of each extension. This example shows how to use JdbiExtension with H2. ```java import org.jdbi.v3.testing.junit5.JdbiExtension; import org.junit.jupiter.api.extension.RegisterExtension; public class MyTest { @RegisterExtension public static JdbiExtension h2Extension = JdbiExtension.h2().withPlugin(new MyPlugin()); @Test void myTest(Jdbi jdbi, Handle handle) { // use jdbi or handle } } ``` -------------------------------- ### Basic JdbiOtjPostgresExtension Setup Source: https://jdbi.org/apidocs/org/jdbi/v3/testing/junit5/JdbiOtjPostgresExtension.html Demonstrates how to register JdbiOtjPostgresExtension with JUnit 5. This setup allows tests to automatically receive Jdbi and Handle instances. ```java @RegisterExtension public JdbiExtension extension = new JdbiOtjPostgresExtension() { @Override protected DataSource createDataSource() { // Custom DataSource creation logic here } }; ``` -------------------------------- ### Install and Configure Jackson 3 Plugin Source: https://jdbi.org/ Installs the Jackson 3 plugin and optionally configures the ObjectMapper and Json Views for JDBI. ```java jdbi.installPlugin(new Jackson3Plugin()); // optionally configure your ObjectMapper (recommended) jdbi.getConfig(Jackson3Config.class).setMapper(myObjectMapper); // now with simple support for Json Views if you want to filter properties: jdbi.getConfig(Jackson3Config.class).setView(ApiProperty.class); ``` -------------------------------- ### Install Vavr Plugin Source: https://jdbi.org/ Installs the Vavr plugin into the Jdbi instance. This is a required setup step before using Vavr-specific features. ```java jdbi.installPlugin(new VavrPlugin()); ``` -------------------------------- ### Execution Moment Source: https://jdbi.org/releases/3.28.0/apidocs/org/jdbi/v3/core/statement/StatementContext.html Methods to get and set the query execution start time. ```APIDOC ## getExecutionMoment ### Description Returns the query execution start as an `Instant`. ### Method `@Nullable public Instant getExecutionMoment()` ### Returns * `Instant` - the `Instant` at which query execution began. ``` ```APIDOC ## setExecutionMoment ### Description Sets the query execution start. This is not part of the Jdbi API and should not be called by code outside JDBI. ### Method `public void setExecutionMoment(Instant executionMoment)` ### Parameters * `executionMoment` (Instant) - Sets the query execution start. ``` -------------------------------- ### JdbiRule.before Source: https://jdbi.org/apidocs/index-all.html Setup method for JdbiRule. ```APIDOC ## JdbiRule.before ### Description Setup method for JdbiRule. ### Method before() ### Class JdbiRule in org.jdbi.v3.testing ``` -------------------------------- ### Execution Moment Access Source: https://jdbi.org/releases/3.38.3/apidocs/org/jdbi/v3/core/statement/StatementContext.html Methods to get and set the query execution start time. ```APIDOC ## getExecutionMoment ### Description Returns the query execution start as an `Instant`. ### Method `getExecutionMoment` ### Returns * `@Nullable Instant` - the `Instant` at which query execution began. ``` ```APIDOC ## setExecutionMoment ### Description Sets the query execution start. This is not part of the Jdbi API and should not be called by code outside JDBI. ### Method `setExecutionMoment` ### Parameters * `executionMoment` (Instant) - Sets the query execution start. ``` -------------------------------- ### org.jdbi.v3.testing.JdbiRule.before Source: https://jdbi.org/releases/3.49.4/apidocs/index-all.html Setup method for JdbiRule. ```APIDOC ## Method before ### Description Setup method for JdbiRule. ``` -------------------------------- ### beforeEach Method Source: https://jdbi.org/releases/3.27.0/apidocs/org/jdbi/v3/testing/junit5/JdbiOtjPostgresExtension.html Callback invoked before each test method. It handles setup operations for the extension, such as starting the embedded PostgreSQL instance. ```APIDOC ## beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) ### Description Callback invoked before each test method. It handles setup operations for the extension. ### Method `void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)` ### Throws `Exception` ``` -------------------------------- ### Get Erased Type Source: https://jdbi.org/releases/3.27.0/apidocs/org/jdbi/v3/core/generic/GenericTypes.html Obtain the erased class for a given type. For example, if the type is List, this method returns List.class. ```java Class erasedType = GenericTypes.getErasedType(type); ``` -------------------------------- ### org.jdbi.v3.core.Handle.begin Source: https://jdbi.org/releases/3.49.4/apidocs/index-all.html Start a transaction. ```APIDOC ## Method begin ### Description Start a transaction. ``` -------------------------------- ### JdbiFlywayMigration Initialization Source: https://jdbi.org/releases/3.49.3/apidocs/org/jdbi/v3/testing/junit5/JdbiFlywayMigration.html Demonstrates how to initialize JdbiFlywayMigration with default Flyway migration paths and register it as a JdbiExtension. ```APIDOC ## JdbiFlywayMigration Initialization Example ### Description This example shows how to create and configure a `JdbiFlywayMigration` instance using its static factory method `flywayMigration()` and the `withDefaultPath()` method to specify the migration script location. It is then registered as a `JdbiExtensionInitializer` for a `JdbiExtension`. ### Method Static factory method and instance configuration. ### Endpoint N/A (Java API) ### Parameters N/A ### Request Example ```java @RegisterExtension public JdbiExtension extension = JdbiExtension.h2() .withInitializer(JdbiFlywayMigration.flywayMigration().withDefaultPath()); ``` ### Response N/A (Java API configuration) ``` -------------------------------- ### Use Guava Types in SQL Objects Source: https://jdbi.org/ Example of using Guava's ImmutableList and Optional in SQL object interfaces after installing the GuavaPlugin. ```java public interface UserDao { @SqlQuery("select * from users order by name") ImmutableList list(); @SqlQuery("select * from users where id = :id") com.google.common.base.Optional getById(long id); } ``` -------------------------------- ### withPlugins() Source: https://jdbi.org/releases/3.27.0/apidocs/index-all.html Discover and install plugins from the classpath. ```APIDOC ## withPlugins() ### Description Discover and install plugins from the classpath. ### Method (Not specified) ### Endpoint (Not applicable) ``` -------------------------------- ### Get Multiple Generated Keys for Insert Source: https://jdbi.org/ Multiple columns may be generated and returned using @GetGeneratedKeys. This example returns both 'id' and 'created_on' from the INSERT statement. ```java public interface UserDao { @SqlUpdate("INSERT INTO users (id, name, created_on) VALUES (nextval('user_seq'), ?, now())") @GetGeneratedKeys({"id", "created_on"}) @RegisterBeanMapper(IdCreateTime.class) IdCreateTime insert(String name); } ``` -------------------------------- ### begin Source: https://jdbi.org/releases/3.33.0/apidocs/org/jdbi/v3/core/Handle.html Start a transaction. ```APIDOC ## begin ### Description Start a transaction. ### Method `public Handle begin()` ### Returns The same handle. ``` -------------------------------- ### Counter Codec Implementation Source: https://jdbi.org/ An example implementation of a Jdbi Codec for a custom Counter class. It defines how to get a ColumnMapper for reading from the database and a Function for writing to prepared statements. ```java public class Counter { private int count = 0; public Counter() {} public int nextValue() { return count++; } private Counter setValue(int value) { this.count = value; return this; } private int getValue() { return count; } /** * Codec to persist a counter to the database and restore it back. */ public static class CounterCodec implements Codec { @Override public ColumnMapper getColumnMapper() { return (r, idx, ctx) -> new Counter().setValue(r.getInt(idx)); } @Override public Function getArgumentFunction() { return counter -> (idx, stmt, ctx) -> stmt.setInt(idx, counter.getValue()); } } } ``` -------------------------------- ### JUnit 5 JdbiExtension with H2 and SqlObjectPlugin Source: https://jdbi.org/ Example of using JdbiExtension for JUnit 5, configured for H2 and including the SqlObjectPlugin. This setup allows access to Jdbi and Handle objects within tests. ```java public class Test { @RegisterExtension public JdbiExtension h2Extension = JdbiExtension.h2() withPlugin(new SqlObjectPlugin()); @Test public void testWithJunit5() { Jdbi jdbi = h2Extension.getJdbi(); Handle handle = h2Extension.openHandle(); // ... } } ``` -------------------------------- ### installPlugin and installPlugins Methods Source: https://jdbi.org/releases/3.27.2/apidocs/index-all.html Methods for installing Jdbi plugins to configure Handle instances. ```APIDOC ## installPlugin(JdbiPlugin) ### Description Install a given `JdbiPlugin` instance that will configure any provided `Handle` instances. ### Method N/A (Method Signature) ### Endpoint N/A ## installPlugins() ### Description Use the `ServiceLoader` API to detect and install plugins automagically. ### Method N/A (Method Signature) ### Endpoint N/A ## installPlugins() ### Description When creating the `Jdbi` instance, call the `Jdbi.installPlugins()` method, which loads all plugins discovered by the `ServiceLoader` API. ### Method N/A (Method Signature) ### Endpoint N/A ``` -------------------------------- ### Get Multiple Generated Keys with SQL Batch Source: https://jdbi.org/ Multiple columns can be generated and returned with @SqlBatch and @GetGeneratedKeys. This example returns a list of IdCreateTime objects, each containing the generated 'id' and 'created_on' for each inserted name. ```java public interface UserDao { @SqlBatch("INSERT INTO users (id, name, created_on) VALUES (nextval('user_seq'), ?, now())") @GetGeneratedKeys({"id", "created_on"}) @RegisterBeanMapper(IdCreateTime.class) List bulkInsert(String... names); } ``` -------------------------------- ### Get Generated Keys for Single Insert Source: https://jdbi.org/ The @GetGeneratedKeys annotation may be used to return the keys generated from an SQL statement, such as an auto-generated primary key. This example returns the 'id' generated by the INSERT statement. ```java public interface UserDao { @SqlUpdate("INSERT INTO users (id, name) VALUES (nextval('user_seq'), ?)") @GetGeneratedKeys("id") long insert(String name); } ``` -------------------------------- ### withPlugins(JdbiPlugin...) Source: https://jdbi.org/releases/3.27.0/apidocs/index-all.html Install multiple `JdbiPlugin`s when creating the `Jdbi` instance. ```APIDOC ## withPlugins(JdbiPlugin...) ### Description Install multiple `JdbiPlugin`s when creating the `Jdbi` instance. ### Method (Not specified) ### Endpoint (Not applicable) ### Parameters * **plugins** (JdbiPlugin...) - Required - The plugins to install. ``` -------------------------------- ### Get Generated Keys with SQL Batch Source: https://jdbi.org/ When using @SqlBatch, @GetGeneratedKeys tells SQL Object that the return value should be the generated keys from each SQL statement, instead of the update count. This example returns the generated 'id' for each inserted user. ```java public interface UserDao { @SqlBatch("INSERT INTO users (id, name) VALUES (nextval('user_seq'), ?)") @GetGeneratedKeys("id") long[] bulkInsert(List names); } ``` -------------------------------- ### JdbiExtension.beforeAll() and JdbiPostgresExtension.beforeAll() Source: https://jdbi.org/releases/3.52.1/apidocs/index-all.html Methods for JUnit 5 extension setup before all tests. ```APIDOC ## beforeAll(ExtensionContext) ### Description Setup method for JUnit 5 extension, invoked before all tests. ### Method beforeAll(ExtensionContext) ### Endpoint class org.jdbi.v3.testing.junit5.JdbiExtension --- ## beforeAll(ExtensionContext) ### Description Setup method for JUnit 5 Postgres extension, invoked before all tests. ### Method beforeAll(ExtensionContext) ### Endpoint class org.jdbi.v3.testing.junit5.JdbiPostgresExtension ``` -------------------------------- ### JdbiFactoryBean.setPlugins Source: https://jdbi.org/releases/3.35.0/apidocs/org/jdbi/v3/core/spi/class-use/JdbiPlugin.html Installs the given plugins which will be installed into the Jdbi. ```APIDOC ## JdbiFactoryBean.setPlugins(Collection plugins) ### Description Installs the given plugins which will be installed into the `Jdbi`. ### Method `JdbiFactoryBean` ### Parameters - **plugins** (`Collection`) - A collection of `JdbiPlugin` instances to install. ``` -------------------------------- ### installPlugins Source: https://jdbi.org/releases/3.27.0/apidocs/org/jdbi/v3/testing/junit5/JdbiExtension.html When creating the `Jdbi` instance, call the `Jdbi.installPlugins()` method, which loads all plugins discovered by the `ServiceLoader` API. ```APIDOC ## installPlugins ### Description When creating the `Jdbi` instance, call the `Jdbi.installPlugins()` method, which loads all plugins discovered by the `ServiceLoader` API. ### Method `public final JdbiExtension installPlugins()` ### Returns The extension itself for chaining method calls. ``` -------------------------------- ### subSequence(int start, int end) Source: https://jdbi.org/releases/3.52.0/apidocs/org/jdbi/v3/core/Sql.html Returns a CharSequence that is a subsequence of this SQL statement string. The subsequence starts at the specified start index and ends at the specified end index. ```APIDOC ## subSequence(int start, int end) ### Description Returns a CharSequence that is a subsequence of this SQL statement string. The subsequence starts at the specified start index and ends at the specified end index. ### Method `public CharSequence subSequence(int start, int end)` ### Parameters * **start** (int) - The starting index of the subsequence, inclusive. * **end** (int) - The ending index of the subsequence, exclusive. ### Returns * `CharSequence` - The specified subsequence. ``` -------------------------------- ### Handle.begin Source: https://jdbi.org/apidocs/index-all.html Starts a transaction on the given Handle. ```APIDOC ## Handle.begin ### Description Start a transaction. ### Method begin() ### Class Handle in org.jdbi.v3.core ``` -------------------------------- ### Install KotlinMapperFactory Property Source: https://jdbi.org/releases/3.38.3/apidocs-kotlin/jdbi3-kotlin/jdbi3-kotlin/org.jdbi.v3.core.kotlin/-kotlin-plugin/index.html A boolean property to control whether the KotlinMapperFactory is installed. ```kotlin @property installKotlinMapperFactory If true, install the {@link KotlinMapperFactory}. ``` -------------------------------- ### JdbiExtension withConfig Example Source: https://jdbi.org/releases/3.44.1/apidocs/org/jdbi/v3/testing/junit5/JdbiExtension.html Demonstrates how to configure JdbiExtension with custom configurations like RowMappers. This is useful for registering custom mappers or other Jdbi configurations. ```java @RegisterExtension public JdbiExtension h2Extension = JdbiExtension.h2().withPlugin(new SqlObjectPlugin()) .withConfig(RowMappers.class, r -> r.register(Foo.class, new FooMapper()); ``` -------------------------------- ### Install Plugins Source: https://jdbi.org/releases/3.45.0/apidocs/org/jdbi/v3/testing/junit5/JdbiExtension.html Configures the Jdbi instance to call `Jdbi.installPlugins()`, which loads all plugins discovered via the `ServiceLoader` API. Returns the extension instance for chaining. ```java JdbiExtension extensionWithPlugins = extension.installPlugins(); ``` -------------------------------- ### JdbiExtension.withPlugin() Source: https://jdbi.org/releases/3.36.0/apidocs/index-all.html Installs a JdbiPlugin when creating the Jdbi instance within JdbiExtension. ```APIDOC ## JdbiExtension.withPlugin(JdbiPlugin) ### Description Install a `JdbiPlugin` when creating the `Jdbi` instance. ### Method N/A (Method Signature) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Default Methods Example Source: https://jdbi.org/releases/3.37.1/apidocs/org/jdbi/v3/sqlobject/package-summary.html An example interface demonstrating the use of default methods. ```APIDOC ## Interface DefaultMethods ### Description This interface shows how default methods can be declared and used to call other methods within the same interface. ### Methods #### `getFolderById(int id)` - **Description**: Retrieves a `Folder` by its ID. - **Annotation**: `@SqlQuery("select * from folders where id = :id")` #### `getDocuments(int folderId)` - **Description**: Retrieves a list of `Document` objects for a given folder ID. - **Annotation**: `@SqlQuery("select * from documents where folder_id = :folderId")` #### `getFolderByIdWithDocuments(int id)` - **Description**: A default method that retrieves a `Folder` by ID and then retrieves its associated documents. - **Implementation**: Calls `getById(id)` and `listByParendId(id)`. - **Returns**: `Node` - A `Node` object containing the folder and its documents. ``` -------------------------------- ### JdbiExtension.withPlugin Source: https://jdbi.org/releases/3.29.0/apidocs/index-all.html Install a JdbiPlugin when creating the Jdbi instance. ```APIDOC ## withPlugin(JdbiPlugin) ### Description Install a `JdbiPlugin` when creating the `Jdbi` instance. ### Method N/A (Class method) ### Endpoint N/A ``` -------------------------------- ### Handle Usage Examples Source: https://jdbi.org/releases/3.34.0/apidocs/org/jdbi/v3/core/class-use/Handle.html Examples of how the Handle interface is used in different contexts. ```APIDOC ## PostgresPlugin.customizeHandle(Handle handle) ### Description Methods in org.jdbi.v3.postgres that return Handle. ### Method Handle ### Endpoint N/A (Method Signature) ### Parameters * **handle** (Handle) - Description not available ### Response #### Success Response (Handle) Description not available ### Response Example N/A ``` ```APIDOC ## SqlObject.getHandle() ### Description Returns the handle used in the current sql object context. ### Method Handle ### Endpoint N/A (Method Signature) ### Parameters None ### Response #### Success Response (Handle) Description not available ### Response Example N/A ``` ```APIDOC ## JdbiRule.getHandle() ### Description Get the single Handle instance opened for the duration of this test case. ### Method Handle ### Endpoint N/A (Method Signature) ### Parameters None ### Response #### Success Response (Handle) Description not available ### Response Example N/A ``` -------------------------------- ### subSequence(int start, int end) Source: https://jdbi.org/releases/3.49.5/apidocs/org/jdbi/v3/core/Sql.html Returns a new CharSequence that is a subsequence of this SQL statement string. The subsequence starts at the specified start index and ends at the specified end index (exclusive). ```APIDOC ## subSequence(int start, int end) ### Description Returns a new CharSequence that is a subsequence of this SQL statement string. The subsequence starts at the specified start index and ends at the specified end index (exclusive). ### Method `CharSequence subSequence(int start, int end)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java Sql sql = Sql.of("SELECT 1 FROM users"); CharSequence sub = sql.subSequence(0, 6); // sub will be "SELECT" ``` ### Response #### Success Response - **CharSequence** (CharSequence) - A new CharSequence representing the subsequence. #### Response Example None provided. ``` -------------------------------- ### installPlugin(JdbiPlugin plugin) Source: https://jdbi.org/apidocs/org/jdbi/v3/core/Jdbi.html Installs a given JdbiPlugin instance that will configure any provided Handle instances. ```APIDOC ## installPlugin(JdbiPlugin plugin) ### Description Install a given `JdbiPlugin` instance that will configure any provided `Handle` instances. ### Method ```java public Jdbi installPlugin(JdbiPlugin plugin) ``` ### Parameters #### Path Parameters - **plugin** (JdbiPlugin) - the plugin to install. ### Returns this ``` -------------------------------- ### JdbiExtension.withPlugins() Source: https://jdbi.org/releases/3.36.0/apidocs/index-all.html Installs multiple JdbiPlugins when creating the Jdbi instance within JdbiExtension. ```APIDOC ## JdbiExtension.withPlugins(JdbiPlugin...) ### Description Install multiple `JdbiPlugin`s when creating the `Jdbi` instance. ### Method N/A (Method Signature) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### SQL Object Instance Creation Source: https://jdbi.org/releases/3.31.0/apidocs/org/jdbi/v3/sqlobject/package-summary.html Demonstrates the three primary ways to obtain and use SQL Object instances. ```APIDOC ## Obtaining SQL Object Instances ### Description This section details how to get instances of your SQL Object interfaces. ### Methods 1. **`useExtension` / `withExtension`**: Obtain a short-lived instance passed to a lambda. - `useExtension`: For void methods. - `withExtension`: Returns the value from the lambda. ```java jdbi.useExtension(TheBasics.class, theBasics -> theBasics.insert(new Something(1, "Alice"))); Something result = jdbi.withExtension(TheBasics.class, theBasics -> theBasics.findById(1)); ``` 2. **`handle.attach`**: Obtain an instance attached to a specific Handle. Lifecycle tied to the Handle. ```java try (Handle handle = jdbi.open()) { TheBasics attached = handle.attach(TheBasics.class); attached.insert(new Something(2, "Bob")); Something result = attached.findById(2); } ``` 3. **`onDemand`**: Obtain an on-demand instance with an open-ended lifecycle. Allocates connections per call. ```java TheBasics onDemand = jdbi.onDemand(TheBasics.class); onDemand.insert(new Something(3, "Chris")); Something result = onDemand.findById(3); ``` ``` -------------------------------- ### Jdbi Plugin Installation Source: https://jdbi.org/releases/3.32.0/apidocs/org/jdbi/v3/core/class-use/Jdbi.html Methods for installing plugins to extend Jdbi's functionality. ```APIDOC ## Jdbi Plugin Management ### Description Methods for managing and installing plugins to customize Jdbi behavior. ### Methods - `Jdbi installPlugin(JdbiPlugin plugin)` Installs a given `JdbiPlugin` instance. The plugin will configure any provided `Handle` instances. - `Jdbi installPlugins()` Automatically detects and installs plugins using the `ServiceLoader` API. ``` -------------------------------- ### installPlugin Source: https://jdbi.org/releases/3.46.0/apidocs/index-all.html Installs a JdbiPlugin instance to configure any provided Handle instances. ```APIDOC ## installPlugin(JdbiPlugin) ### Description Install a given `JdbiPlugin` instance that will configure any provided `Handle` instances. ### Method N/A (Method Signature) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Installing Plugins Source: https://jdbi.org/releases/3.41.3/apidocs/org/jdbi/v3/testing/junit5/JdbiExtension.html When creating the Jdbi instance, call the Jdbi.installPlugins() method, which loads all plugins discovered by the ServiceLoader API. ```java jdbiExtension.installPlugins() ``` -------------------------------- ### Install KotlinSqlObjectPlugin Source: https://jdbi.org/ Installs the KotlinSqlObjectPlugin into the Jdbi instance to enable Kotlin-specific features for SqlObjects. ```kotlin jdbi.installPlugin(KotlinSqlObjectPlugin()); ``` -------------------------------- ### Install a Single JdbiPlugin Source: https://jdbi.org/apidocs/org/jdbi/v3/testing/junit5/JdbiExtension.html Installs a specific JdbiPlugin when creating the Jdbi instance for testing. ```java public JdbiExtension h2Extension = JdbiExtension.h2().withPlugin(new SqlObjectPlugin()); ``` -------------------------------- ### Jdbi.installPlugin Source: https://jdbi.org/releases/3.27.0/apidocs/org/jdbi/v3/core/spi/class-use/JdbiPlugin.html Installs a JdbiPlugin instance to configure Handle instances. ```APIDOC ## Jdbi.installPlugin ### Description Installs a given `JdbiPlugin` instance that will configure any provided `Handle` instances. ### Method `Jdbi` ### Endpoint `installPlugin(JdbiPlugin plugin)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### KotlinPlugin Constructor Source: https://jdbi.org/releases/3.49.6/apidocs-kotlin/jdbi3-kotlin/jdbi3-kotlin/org.jdbi.v3.core.kotlin/-kotlin-plugin/index.html Installs Kotlin-specific functionality. You can optionally control the installation of the KotlinMapperFactory and coroutine support. ```APIDOC ## KotlinPlugin Constructor ### Description Installs Kotlin-specific functionality. You can optionally control the installation of the KotlinMapperFactory and coroutine support. ### Parameters * **installKotlinMapperFactory** (Boolean) - Optional - Defaults to true. Controls whether the KotlinMapperFactory is installed. * **enableCoroutineSupport** (Boolean) - Optional - Defaults to false. Controls whether coroutine support is enabled. ``` -------------------------------- ### installPlugins() Source: https://jdbi.org/releases/3.30.0/apidocs/org/jdbi/v3/testing/junit5/JdbiExtension.html Configures the Jdbi instance to automatically load all discovered plugins using the `ServiceLoader` API. This method is chainable. ```APIDOC ## installPlugins() ### Description When creating the `Jdbi` instance, call the `Jdbi.installPlugins()` method, which loads all plugins discovered by the `ServiceLoader` API. ### Method Signature `public final JdbiExtension installPlugins()` ### Returns The extension itself for chaining method calls. ``` -------------------------------- ### setPlugins Source: https://jdbi.org/apidocs/index-all.html Installs the given plugins, which will then be installed into the JDBI instance. Available for JDBI and Spring 5. ```APIDOC ## setPlugins(Collection) ### Description Installs the given plugins which will be installed into the `Jdbi`. ### Method N/A (Method signature provided) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### begin Source: https://jdbi.org/apidocs/org/jdbi/v3/core/transaction/LocalTransactionHandler.html Begins a transaction on the given handle. ```APIDOC ## begin(Handle handle) ### Description Begin a transaction. ### Method `public void begin(Handle handle)` ### Parameters #### Path Parameters - **handle** (Handle) - The handle the transaction is being started on. ``` -------------------------------- ### begin Source: https://jdbi.org/apidocs/org/jdbi/v3/core/transaction/DelegatingTransactionHandler.html Begins a transaction on the given handle. ```APIDOC ## begin(Handle handle) ### Description Begin a transaction. ### Method public void begin(Handle handle) ### Parameters * **handle** (Handle) - the handle the transaction is being started on. ``` -------------------------------- ### Install Multiple JdbiPlugins Source: https://jdbi.org/apidocs/org/jdbi/v3/testing/junit5/JdbiExtension.html Installs one or more JdbiPlugin instances when creating the Jdbi instance for testing. ```java public JdbiExtension h2Extension = JdbiExtension.h2().withPlugins(new SqlObjectPlugin(), new MyCustomPlugin()); ``` -------------------------------- ### JdbiFlywayMigration.initialize Source: https://jdbi.org/releases/3.35.0/apidocs/org/jdbi/v3/core/class-use/Handle.html Initialization method for JdbiFlywayMigration, potentially involving a Handle. ```APIDOC ## JdbiFlywayMigration.initialize ### Description Initialization method for JdbiFlywayMigration. ### Method Signature `void JdbiFlywayMigration.initialize(DataSource ds, Handle handle)` ``` -------------------------------- ### Mixin Interfaces Example Source: https://jdbi.org/releases/3.37.1/apidocs/org/jdbi/v3/sqlobject/package-summary.html An example interface demonstrating the use of mixin interfaces, extending `SqlObject`. ```APIDOC ## Interface UsingMixins ### Description This interface extends `SqlObject` and demonstrates how to use mixin interfaces. It provides a `getFolder` method that utilizes `getHandle()` to execute a custom query. ### Methods #### `getFolder(int id)` - **Description**: Retrieves a `Folder` with its associated `Document`s using a custom SQL query. - **Annotation**: `@RegisterBeanMapper(value={Folder.class, Document.class}, prefix={"f", "d"})` - **Implementation**: Uses `getHandle().createQuery(...)` to execute a join query and `reduceRows` to map the results. - **Returns**: `Folder` - The `Folder` object with its documents. ``` -------------------------------- ### Using SQL Objects with Jdbi Source: https://jdbi.org/releases/3.27.1/apidocs/org/jdbi/v3/sqlobject/package-summary.html Demonstrates how to install the SqlObjectPlugin and obtain instances of SQL Object interfaces. ```APIDOC ## Using SQL Objects ### Description This section explains how to integrate and use the SQL Objects API. It covers plugin installation and different strategies for obtaining SQL Object instances. ### Plugin Installation ```java Jdbi jdbi = Jdbi.create(dataSource); jdbi.installPlugin(new SqlObjectPlugin()); ``` ### Obtaining SQL Object Instances #### 1. Using Lambda (`useExtension` and `withExtension`) - **`useExtension`**: Creates a short-lived SQL Object instance, passes it to a lambda, and the instance is discarded after the lambda returns. The lambda has a void return. ```java jdbi.useExtension(TheBasics.class, theBasics -> theBasics.insert(new Something(1, "Alice"))); ``` - **`withExtension`**: Similar to `useExtension`, but returns the value produced by the lambda. ```java Something result = jdbi.withExtension(TheBasics.class, theBasics -> theBasics.findById(1)); ``` #### 2. Attaching to a Handle (`handle.attach`) - Creates a SQL Object instance tied to the lifecycle of a `Handle`. The instance is valid as long as the handle is open. ```java try (Handle handle = jdbi.open()) { TheBasics attached = handle.attach(TheBasics.class); attached.insert(new Something(2, "Bob")); Something result = attached.findById(2); } ``` #### 3. On-Demand Instances (`jdbi.onDemand`) - Creates a thread-safe SQL Object instance with an open-ended lifecycle. It obtains and releases connections for each method call, suitable for single, infrequent calls. ```java TheBasics onDemand = jdbi.onDemand(TheBasics.class); onDemand.insert(new Something(3, "Chris")); Something result = onDemand.findById(3); ``` **Note**: On-demand instances incur a performance penalty due to connection allocation/release for each call. Prefer other methods for multiple consecutive calls. ``` -------------------------------- ### withPlugins() (Deprecated) Source: https://jdbi.org/releases/3.53.0/apidocs/org/jdbi/v3/testing/JdbiRule.html Deprecated method to discover and install plugins from the classpath. It is recommended to install plugins explicitly. ```APIDOC ## withPlugins ### Description Deprecated, for removal: This API element is subject to removal in a future version. Registering plugins implicitly is less reliable. Please register plugins explicitly. Discover and install plugins from the classpath. See Also: * we recommend installing plugins explicitly instead ### Method `@Deprecated(forRemoval=true) public JdbiRule withPlugins()` ``` -------------------------------- ### setPlugins(Collection) Source: https://jdbi.org/releases/3.50.0/apidocs/index-all.html Installs the given plugins which will be installed into the `Jdbi`. This method is available in JdbiFactoryBean (core and spring5). ```APIDOC ## setPlugins(Collection) ### Description Installs the given plugins which will be installed into the `Jdbi`. ### Method Not specified (likely a setter method). ### Endpoint Not applicable (SDK method). ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response None ``` -------------------------------- ### Obtaining SQL Object Instances Source: https://jdbi.org/releases/3.41.0/apidocs/org/jdbi/v3/sqlobject/package-summary.html Demonstrates different ways to obtain and use SQL object instances. ```APIDOC ## Obtaining SQL Object Instances ### Description SQL Object instances can be obtained via lambdas, attached to a handle, or as on-demand instances. ### Usage with Lambdas (`useExtension`, `withExtension`) ```java // Use for operations that don't return a value jdbi.useExtension(TheBasics.class, theBasics -> theBasics.insert(new Something(1, "Alice"))); // Use for operations that return a value Something result = jdbi.withExtension(TheBasics.class, theBasics -> theBasics.findById(1)); ``` ### Usage with Handle Attachment (`handle.attach`) ```java try (Handle handle = jdbi.open()) { TheBasics attached = handle.attach(TheBasics.class); attached.insert(new Something(2, "Bob")); Something result = attached.findById(2); } ``` ### Usage with On-Demand Instances (`jdbi.onDemand`) ```java TheBasics onDemand = jdbi.onDemand(TheBasics.class); onDemand.insert(new Something(3, "Chris")); Something result = onDemand.findById(3); ``` ``` -------------------------------- ### installPlugins() Source: https://jdbi.org/releases/3.30.0/apidocs/org/jdbi/v3/core/Jdbi.html Use the ServiceLoader API to detect and install plugins automatically. Use with caution. ```APIDOC ## installPlugins() ### Description Use the `ServiceLoader` API to detect and install plugins automagically. Some people consider this feature dangerous; some consider it essential -- use at your own risk. ### Method ```java public Jdbi installPlugins() ``` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Response #### Success Response * **Jdbi** - this #### Response Example * None ``` -------------------------------- ### withPlugins Source: https://jdbi.org/releases/3.36.0/apidocs/org/jdbi/v3/testing/junit5/JdbiExtension.html Install multiple JdbiPlugins when creating the Jdbi instance. ```APIDOC ## withPlugins ### Description Install multiple `JdbiPlugin`s when creating the `Jdbi` instance. ### Method Instance Method ### Signature `final JdbiExtension withPlugins(JdbiPlugin... pluginList)` ``` -------------------------------- ### KotlinPlugin Constructor Source: https://jdbi.org/releases/3.44.1/apidocs-kotlin/jdbi3-kotlin/jdbi3-kotlin/org.jdbi.v3.core.kotlin/-kotlin-plugin Installs Kotlin-specific functionality into Jdbi. It can optionally install the KotlinMapperFactory and enable coroutine support. ```APIDOC ## KotlinPlugin Constructor ### Description Installs Kotlin-specific functionality. This includes a Kotlin inference interceptor for registered types, a Kotlin mapper factory for data classes, and support for using Handles in Coroutines. ### Parameters #### Constructor Parameters - **installKotlinMapperFactory** (Boolean) - Optional - If true, installs the {@link KotlinMapperFactory}. - **enableCoroutineSupport** (Boolean) - Optional - If true, enables support for Kotlin Coroutines. ``` -------------------------------- ### Handle.begin() and Transactional.begin() Source: https://jdbi.org/releases/3.52.1/apidocs/index-all.html Methods to start a transaction. ```APIDOC ## begin() ### Description Start a transaction. ### Method begin() ### Endpoint class org.jdbi.v3.core.Handle --- ## begin() ### Description Begins a transaction. ### Method begin() ### Endpoint interface org.jdbi.v3.sqlobject.transaction.Transactional ``` -------------------------------- ### KotlinPlugin Constructor Source: https://jdbi.org/releases/3.44.1/apidocs-kotlin/jdbi3-kotlin/jdbi3-kotlin/org.jdbi.v3.core.kotlin/-kotlin-plugin/index.html Installs Kotlin-specific functionality into Jdbi. It can optionally install the KotlinMapperFactory and enable coroutine support. ```APIDOC ## KotlinPlugin Constructor ### Description Installs Kotlin-specific functionality into Jdbi. This includes a Kotlin inference interceptor for registered types, a Kotlin mapper factory for data classes, and support for using Handles in Coroutines. ### Parameters #### Constructor Parameters - **installKotlinMapperFactory** (Boolean) - Optional - If true, installs the {@link KotlinMapperFactory}. - **enableCoroutineSupport** (Boolean) - Optional - If true, enables support for Kotlin Coroutines. ``` -------------------------------- ### JdbiRule.withPlugins() Source: https://jdbi.org/releases/3.47.0/apidocs/org/jdbi/v3/testing/class-use/JdbiRule.html Discovers and installs all available Jdbi plugins from the classpath into the JdbiRule. This is a convenient way to enable multiple Jdbi extensions. ```APIDOC ## JdbiRule.withPlugins() ### Description Discovers and installs plugins from the classpath. ### Method JdbiRule ### Endpoint N/A (Java method) ### Parameters None ### Request Example N/A ### Response #### Success Response - **JdbiRule** (JdbiRule) - The JdbiRule instance with discovered plugins installed. ``` -------------------------------- ### Jdbi Plugin Installation Source: https://jdbi.org/releases/3.41.3/apidocs/index-all.html Methods for installing plugins into Jdbi, either individually or automatically using `ServiceLoader`. ```APIDOC ## installPlugin(JdbiPlugin) ### Description Install a given `JdbiPlugin` instance that will configure any provided `Handle` instances. ### Method N/A (Method within a class) ### Endpoint N/A ``` ```APIDOC ## installPlugins() ### Description Use the `ServiceLoader` API to detect and install plugins automatically. ### Method N/A (Method within a class) ### Endpoint N/A ``` ```APIDOC ## installPlugins() ### Description When creating the `Jdbi` instance, call the `Jdbi.installPlugins()` method, which loads all plugins discovered by the `ServiceLoader` API. ### Method N/A (Method within a class) ### Endpoint N/A ``` -------------------------------- ### Install JodaTime Plugin Source: https://jdbi.org/ Installs the JodaTime plugin into a JDBI instance, enabling support for JodaTime types. ```java jdbi.installPlugin(new JodaTimePlugin()); ``` -------------------------------- ### org.jdbi.v3.testing.JdbiRule.withPlugins Source: https://jdbi.org/releases/3.31.0/apidocs/index-all.html Discover and install plugins from the classpath. ```APIDOC ## org.jdbi.v3.testing.JdbiRule.withPlugins() ### Description Discover and install plugins from the classpath. ### Method N/A (Method signature) ```