com.j256.ormlite.support
Interface DatabaseConnection


public interface DatabaseConnection

A reduction of the SQL Connection so we can implement its functionality outside of JDBC.

Author:
graywatson

Field Summary
static Object MORE_THAN_ONE
          returned by queryForOne(java.lang.String, java.lang.Object[], com.j256.ormlite.field.FieldType[], com.j256.ormlite.stmt.GenericRowMapper) if more than one result was found by the query
 
Method Summary
 void close()
          Close the connection to the database.
 void commit(Savepoint savePoint)
          Commit all changes since the savepoint was created.
 CompiledStatement compileStatement(String statement, StatementBuilder.StatementType type, FieldType[] argfieldTypes, FieldType[] resultfieldTypes)
          Compile and prepare the SQL statement for execution.
 int delete(String statement, Object[] args, FieldType[] argfieldTypes)
          Perform a SQL delete with the associated SQL statement, arguments, and types.
 boolean getAutoCommit()
          Return if auto-commit is currently enabled.
 int insert(String statement, Object[] args, FieldType[] argfieldTypes)
          Perform a SQL insert with the associated SQL statement, arguments, and types.
 int insert(String statement, Object[] args, FieldType[] argfieldTypes, GeneratedKeyHolder keyHolder)
          Perform a SQL update while returning generated keys with the associated SQL statement, arguments, and types.
 boolean isAutoCommitSupported()
          Return if auto-commit is supported.
 boolean isClosed()
          Return if the connection has been closed either through a call to close() or because of a fatal error.
 boolean isTableExists(String tableName)
          Return true if the table exists in the database.
 long queryForLong(String statement)
          Perform a query whose result should be a single long-integer value.
<T> Object
queryForOne(String statement, Object[] args, FieldType[] argfieldTypes, GenericRowMapper<T> rowMapper)
          Perform a SQL query with the associated SQL statement, arguments, and types and returns a single result.
 void rollback(Savepoint savePoint)
          Roll back all changes since the savepoint was created.
 void setAutoCommit(boolean autoCommit)
          Set the auto-commit to be on (true) or off (false).
 Savepoint setSavePoint(String name)
          Start a save point with a certain name.
 int update(String statement, Object[] args, FieldType[] argfieldTypes)
          Perform a SQL update with the associated SQL statement, arguments, and types.
 

Field Detail

MORE_THAN_ONE

static final Object MORE_THAN_ONE
returned by queryForOne(java.lang.String, java.lang.Object[], com.j256.ormlite.field.FieldType[], com.j256.ormlite.stmt.GenericRowMapper) if more than one result was found by the query

Method Detail

isAutoCommitSupported

boolean isAutoCommitSupported()
                              throws SQLException
Return if auto-commit is supported.

Throws:
SQLException

getAutoCommit

boolean getAutoCommit()
                      throws SQLException
Return if auto-commit is currently enabled.

Throws:
SQLException

setAutoCommit

void setAutoCommit(boolean autoCommit)
                   throws SQLException
Set the auto-commit to be on (true) or off (false).

Throws:
SQLException

setSavePoint

Savepoint setSavePoint(String name)
                       throws SQLException
Start a save point with a certain name. It can be a noop if savepoints are not supported.

Parameters:
name - to use for the Savepoint although it can be ignored.
Returns:
A SavePoint object with which we can release or commit in the future or null if none.
Throws:
SQLException

commit

void commit(Savepoint savePoint)
            throws SQLException
Commit all changes since the savepoint was created. If savePoint is null then commit all outstanding changes.

Parameters:
savePoint - That was returned by setSavePoint or null if none.
Throws:
SQLException

rollback

void rollback(Savepoint savePoint)
              throws SQLException
Roll back all changes since the savepoint was created. If savePoint is null then roll back all outstanding changes.

Parameters:
savePoint - That was returned by setSavePoint previously or null if none.
Throws:
SQLException

compileStatement

CompiledStatement compileStatement(String statement,
                                   StatementBuilder.StatementType type,
                                   FieldType[] argfieldTypes,
                                   FieldType[] resultfieldTypes)
                                   throws SQLException
Compile and prepare the SQL statement for execution.

Throws:
SQLException

insert

int insert(String statement,
           Object[] args,
           FieldType[] argfieldTypes)
           throws SQLException
Perform a SQL insert with the associated SQL statement, arguments, and types.

Parameters:
statement - SQL statement to use for inserting.
args - Object arguments for the SQL '?'s.
argfieldTypes - Field types of the arguments.
Returns:
The number of rows affected by the update. With some database types, this value may be invalid.
Throws:
SQLException

insert

int insert(String statement,
           Object[] args,
           FieldType[] argfieldTypes,
           GeneratedKeyHolder keyHolder)
           throws SQLException
Perform a SQL update while returning generated keys with the associated SQL statement, arguments, and types.

Parameters:
statement - SQL statement to use for inserting.
args - Object arguments for the SQL '?'s.
argfieldTypes - Field types of the arguments.
keyHolder - The holder that gets set with the generated key value.
Returns:
The number of rows affected by the update. With some database types, this value may be invalid.
Throws:
SQLException

update

int update(String statement,
           Object[] args,
           FieldType[] argfieldTypes)
           throws SQLException
Perform a SQL update with the associated SQL statement, arguments, and types.

Parameters:
statement - SQL statement to use for updating.
args - Object arguments for the SQL '?'s.
argfieldTypes - Field types of the arguments.
Returns:
The number of rows affected by the update. With some database types, this value may be invalid.
Throws:
SQLException

delete

int delete(String statement,
           Object[] args,
           FieldType[] argfieldTypes)
           throws SQLException
Perform a SQL delete with the associated SQL statement, arguments, and types.

Parameters:
statement - SQL statement to use for deleting.
args - Object arguments for the SQL '?'s.
argfieldTypes - Field types of the arguments.
Returns:
The number of rows affected by the update. With some database types, this value may be invalid.
Throws:
SQLException

queryForOne

<T> Object queryForOne(String statement,
                       Object[] args,
                       FieldType[] argfieldTypes,
                       GenericRowMapper<T> rowMapper)
                   throws SQLException
Perform a SQL query with the associated SQL statement, arguments, and types and returns a single result.

Parameters:
statement - SQL statement to use for deleting.
args - Object arguments for the SQL '?'s.
argfieldTypes - Field types of the arguments.
rowMapper - The mapper to use to convert the row into the returned object.
Returns:
The first data item returned by the query which can be cast to , null if none, the object MORE_THAN_ONE if more than one result was found.
Throws:
SQLException

queryForLong

long queryForLong(String statement)
                  throws SQLException
Perform a query whose result should be a single long-integer value.

Parameters:
statement - SQL statement to use for the query.
Throws:
SQLException

close

void close()
           throws SQLException
Close the connection to the database.

Throws:
SQLException

isClosed

boolean isClosed()
                 throws SQLException
Return if the connection has been closed either through a call to close() or because of a fatal error.

Throws:
SQLException

isTableExists

boolean isTableExists(String tableName)
                      throws SQLException
Return true if the table exists in the database.

Throws:
SQLException


Copyright © 2011. All Rights Reserved.