org.jdbi.v3.sqlobject.SqlObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdbi3-sqlobject Show documentation
Show all versions of jdbi3-sqlobject Show documentation
SqlObject is a declarative, annotation-driven API
for database access. It complements the core API.
Jdbi 3 is designed to provide convenient tabular data access in
Java(tm) and other JVM based languages.
It uses the Java collections framework for query results,
provides a convenient means of externalizing SQL statements, and
named parameter support for any database that supports JDBC.
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jdbi.v3.sqlobject;
import org.jdbi.v3.core.Handle;
import org.jdbi.v3.core.HandleCallback;
import org.jdbi.v3.core.HandleConsumer;
/**
* SqlObject base interface. All synthesized implementations implement
* this interface, even if the declaration doesn't extend {@code SqlObject}.
*
* Custom mixins may be written as subinterfaces of this class with default methods.
*/
public interface SqlObject {
/**
* Returns the handle used in the current sql object context.
*
* @return the handle used in the current sql object context.
*/
Handle getHandle();
/**
* A convenience function which manages the lifecycle of the handle associated to this sql object,
* and yields it to a callback for use by clients.
*
* @param callback A callback which will receive the handle associated to this sql object
* @param type returned by the callback
* @param exception type thrown by the callback, if any.
*
* @return the value returned by callback
*
* @throws X any exception thrown by the callback
*/
R withHandle(HandleCallback callback) throws X;
/**
* A convenience function which manages the lifecycle of the handle associated to this sql object,
* and yields it to a consumer for use by clients.
*
* @param consumer A consumer which will receive the handle associated to this sql object
* @param exception type thrown by the callback, if any.
*
* @throws X any exception thrown by the callback
*/
default void useHandle(HandleConsumer consumer) throws X {
withHandle(consumer.asCallback());
}
}