Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2004 - 2011 Brian McCallister
   *
   * 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.skife.jdbi.v2;
 
 
 import java.util.List;
 import java.util.Map;

This represents a connection to the database system. It ususally is a wrapper around a JDBC Connection object.
 
 public interface Handle extends Closeable
 {

    
Get the JDBC Connection this Handle uses

Returns:
the JDBC Connection this Handle uses
 
     Connection getConnection();

    

Throws:
org.skife.jdbi.v2.exceptions.UnableToCloseResourceException if any resources throw exception while closing
 
     void close();

    
Define a statement attribute which will be applied to all StatementContext instances for statements created from this handle

Parameters:
key Attribute name
value Attribute value
 
     void define(String keyObject value);

    
Start a transaction
 
     Handle begin();

    
Commit a transaction
 
     Handle commit();

    
Rollback a transaction
 
     Handle rollback();

    
Rollback a transaction to a named checkpoint

Parameters:
checkpointName the name of the checkpoint, previously declared with checkpoint(java.lang.String)
 
     Handle rollback(String checkpointName);

    
Is the handle in a transaction? It defers to the underlying org.skife.jdbi.v2.tweak.TransactionHandler
 
     boolean isInTransaction();

    
Return a default Query instance which can be executed later, as long as this handle remains open.

Parameters:
sql the select sql
 
     Query<Map<StringObject>> createQuery(String sql);

    
Create an Insert or Update statement which returns the number of rows modified.

Parameters:
sql The statement sql
 
     Update createStatement(String sql);

Create a call to a stored procedure

Parameters:
callableSql
Returns:
the Call
	public Call createCall(String callableSql);


    
Execute a simple insert statement

Parameters:
sql the insert SQL
Returns:
the number of rows inserted
    int insert(String sqlObject... args);

    
Execute a simple update statement

Parameters:
sql the update SQL
args positional arguments
Returns:
the number of updated inserted
    int update(String sqlObject... args);

    
Prepare a batch to execute. This is for efficiently executing more than one of the same statements with different parameters bound

Parameters:
sql the batch SQL
Returns:
a batch which can have "statements" added
    PreparedBatch prepareBatch(String sql);

    
Create a non-prepared (no bound parameters, but different SQL, batch statement

Returns:
empty batch
See also:
prepareBatch(java.lang.String)
    Batch createBatch();

    
Executes callback in a transaction. If the transaction succeeds, the result of the callback will be returned. If it fails a org.skife.jdbi.v2.exceptions.TransactionFailedException will be thrown.

Returns:
value returned from the callback
Throws:
org.skife.jdbi.v2.exceptions.TransactionFailedException if the transaction failed in the callback
    <ReturnType> ReturnType inTransaction(TransactionCallback<ReturnType> callbackthrows TransactionFailedException;

    
Executes callback in a transaction. If the transaction succeeds, the result of the callback will be returned. If it fails a org.skife.jdbi.v2.exceptions.TransactionFailedException will be thrown.

This form accepts a transaction isolation level which will be applied to the connection for the scope of this transaction, after which the original isolation level will be restored.

Returns:
value returned from the callback
Throws:
org.skife.jdbi.v2.exceptions.TransactionFailedException if the transaction failed in the callback
    <ReturnType> ReturnType inTransaction(TransactionIsolationLevel level,
                                          TransactionCallback<ReturnType> callbackthrows TransactionFailedException;

    
Convenience method which executes a select with purely positional arguments

Parameters:
sql SQL or named statement
args arguments to bind positionally
Returns:
results of the query
    List<Map<StringObject>> select(String sqlObject... args);

    
Allows for overiding the default statement locator. The default searches the classpath for named statements
    public void setStatementLocator(StatementLocator locator);

    
Allows for overiding the default statement rewriter. The default handles named parameter interpolation.
    public void setStatementRewriter(StatementRewriter rewriter);

    
Creates an SQL script, looking for the source of the script using the current statement locator (which defaults to searching the classpath)
    public Script createScript(String name);

    
Execute some SQL with no return value

Parameters:
sql the sql to execute
args arguments to bind to the sql
    void execute(String sqlObject... args);

    
Create a transaction checkpoint (savepoint in JDBC terminology) with the name provided.

Parameters:
name The name of the checkpoint
Returns:
The same handle
    Handle checkpoint(String name);

    
Release a previously created checkpoint

Parameters:
checkpointName the name of the checkpoint to release
    Handle release(String checkpointName);

    
Specify the statement builder to use for this handle

Parameters:
builder StatementBuilder to be used
    void setStatementBuilder(StatementBuilder builder);

    
Specify the class used to log sql statements. The default is inherited from the DBI used to create this Handle.
    void setSQLLog(SQLLog log);

    
Specify the class used to collect timing information. The default is inherited from the DBI used to create this Handle.
    void setTimingCollector(TimingCollector timingCollector);

    
Register a result set mapper which will have its parameterized type inspected to determine what it maps to Will be used with Query.mapTo(java.lang.Class) for registered mappings.
    public void registerMapper(ResultSetMapper mapper);

    
Register a result set mapper factory. Will be used with Query.mapTo(java.lang.Class) for registerd mappings.
    public void registerMapper(ResultSetMapperFactory factory);

    
Create a a sql object of the specified type bound to this handle. Any state changes to the handle, or the sql object, such as transaction status, closing it, etc, will apply to both the object and the handle.

Parameters:
sqlObjectType
<SqlObjectType>
Returns:
the new sql object bound to this handle
    <SqlObjectType> SqlObjectType attach(Class<SqlObjectType> sqlObjectType);

    
Set the transaction isolation level on the underlying connection

Parameters:
level the isolation level to use
    public void setTransactionIsolation(TransactionIsolationLevel level);

    
Set the transaction isolation level on the underlying connection

Parameters:
level the isolation level to use
    public void setTransactionIsolation(int level);

    
Obtain the current transaction isolation level

Returns:
the current isolation level on the underlying connection
    public void registerArgumentFactory(ArgumentFactory argumentFactory);
    public void registerContainerFactory(ContainerFactory<?> factory);
New to GrepCode? Check out our FAQ X