Interface | Description |
---|---|
Binder<AnnotationType extends Annotation,ArgType> | |
BinderFactory<T extends Annotation> |
Factor for building
Binder instances. |
CloseInternalDoNotUseThisClass |
This is public as we need it to be for some stuff to work.
|
SqlStatementCustomizer |
Used with
SqlStatementCustomizerFactory to
customize sql statements via annotations |
SqlStatementCustomizerFactory |
Interface used in conjunction with
SqlStatementCustomizingAnnotation to generate
SqlStatementCustomizer instances. |
Class | Description |
---|---|
BindBean.Default | |
CloseInternalDoNotUseThisClass.CloseHandler | |
CloseInternalDoNotUseThisClass.Helper | |
PositionalBinder |
A binder that bind an argument by its position in the arguments list
|
SqlObjectBuilder |
Annotation Type | Description |
---|---|
Bind |
A binding annotation
|
BindBean | |
BindingAnnotation |
Annotation used to mark binding annotations.
|
BindMap |
Bind a
Map<String, Object> |
CreateSqlObject |
Use this annotation on a sql object method to create a new sql object
with the same underlying handle source (onDemand, attached, etc) as the
sql object the method is invoked on.
|
GetGeneratedKeys | |
SqlBatch |
Annotate a method to indicate that it will create and execute a SQL batch.
|
SqlCall |
Support for stored proc invocation.
|
SqlQuery |
Used to indicate that a method should execute a query.
|
SqlStatementCustomizingAnnotation |
Annotation used to build customizing annotations.
|
SqlUpdate |
Used to indicate that a method should execute a non-query sql statement
|
Transaction |
The sql objects API allows for declarative definition of interfaces which will handle the generation of sql statements and queries on your behalf when needed. Take the following 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);
}
You obtain an instance of TheBasics
via one of three means, the first opens a new
handle against a DBI instance, the second attaches the object to an already open handle, and the third
will obtain and release connections on demand against a DBI instance.
DBI dbi = new DBI(dataSource);
Handle handle = dbi.open();
TheBasics via_open = dbi.open(TheBasics.class);
TheBasics attached = handle.attach(TheBasics.class);
TheBasics on_demand = dbi.onDemand(TheBasics.class);
It is important to ensure you close the underlying handle on a sql object if it was opened via the DBI#open in particular.
If the sql object defines a close() method, or includes it via another interface (such as the included CloseMe, or java.lang.AutoCloseable) calling that method will close the handle.
On-demand sql objects should not be explicitly closed.
A number of mixin interfaces are included in the org.skife.jdbi.v2.sqlobject package. These provide additional functionality on your sql object, such as transactions or access to the underlying Handle instance. To make use of them just have your sql object interface extend the mixin interface.
Copyright © 2018. All rights reserved.