Version 4.10.0

hirondelle.web4j.database
Class DbTx

Object
  extended by hirondelle.web4j.database.DbTx

public final class DbTx
extends Object

Version of Db for use in a transaction.

The Db class uses an internal connection to execute single operations. If more than one operation needs to be performed as an atomic transaction, then this class is used instead.

This class is identical to Db, except that it uses a Connection passed by the caller.

SQL Parameters

The parameters for SQL statements used by this class have the same behavior as defined by the Db class.


Method Summary
static Id add(Connection aConnection, SqlId aSqlId, Object... aParams)
          INSERT operation which returns the database identifier of the added record.
static int delete(Connection aConnection, SqlId aSqlId, Object... aParams)
          DELETE operation which takes parameters.
static int edit(Connection aConnection, SqlId aSqlId, Object... aParams)
          INSERT, UPDATE, or DELETE operations which take parameters.
static
<T> T
fetch(Connection aConnection, Class<T> aClass, SqlId aSqlId, Object... aParams)
          SELECT operation which returns a single Model Object.
static
<T> T
fetchCompound(Connection aConnection, Class<T> aClassParent, Class<?> aClassChild, int aNumTrailingColsForChildList, SqlId aSqlId, Object... aParams)
          SELECT operation which typically returns a single item with a 0..N relation.
static
<T> T
fetchValue(Connection aConnection, Class<T> aSupportedTargetClass, SqlId aSqlId, Object... aParams)
          SELECT operation which returns a single 'building block' value such as Integer, BigDecimal, and so on.
static
<T> List<T>
list(Connection aConnection, Class<T> aClass, SqlId aSqlId, Object... aParams)
          SELECT operation which returns 0..N Model Objects, one per row.
static
<T> List<T>
listCompound(Connection aConnection, Class<T> aClassParent, Class<?> aClassChild, int aNumTrailingColsForChildList, SqlId aSqlId, Object... aParams)
          SELECT operation which typically returns mutliple items item with a 0..N relation.
static
<T> List<T>
listRange(Connection aConnection, Class<T> aClass, SqlId aSqlId, Integer aStartIndex, Integer aPageSize, Object... aParams)
          SELECT operation that returns a List of Model Objects "subsetted" to a particular range of rows.
static
<T> List<T>
listValues(Connection aConnection, Class<T> aSupportedTargetClass, SqlId aSqlId, Object... aParams)
          SELECT operation which returns a List of 'building block' values such as Integer, BigDecimal, and so on.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fetch

public static <T> T fetch(Connection aConnection,
                          Class<T> aClass,
                          SqlId aSqlId,
                          Object... aParams)
               throws DAOException
SELECT operation which returns a single Model Object.

Parameters:
aConnection - single connection shared by all operations in the transaction.
aClass - class of the returned Model Object.
aSqlId - identifies the underlying SQL statement.
aParams - parameters for the SQL statement.
Throws:
DAOException

fetchValue

public static <T> T fetchValue(Connection aConnection,
                               Class<T> aSupportedTargetClass,
                               SqlId aSqlId,
                               Object... aParams)
                    throws DAOException
SELECT operation which returns a single 'building block' value such as Integer, BigDecimal, and so on.

Parameters:
aConnection - single connection shared by all operations in the transaction.
aSupportedTargetClass - class supported by the configured implementation of ConvertColumn.
aSqlId - identifies the underlying SQL statement.
aParams - parameters for the SQL statement.
Throws:
DAOException

list

public static <T> List<T> list(Connection aConnection,
                               Class<T> aClass,
                               SqlId aSqlId,
                               Object... aParams)
                    throws DAOException
SELECT operation which returns 0..N Model Objects, one per row.

Parameters:
aConnection - single connection shared by all operations in the transaction.
aClass - class of the returned Model Objects.
aSqlId - identifies the underlying SQL statement.
aParams - parameters for the SQL statement.
Returns:
an unmodifiable List of Model Objects. The list may be empty.
Throws:
DAOException

listValues

public static <T> List<T> listValues(Connection aConnection,
                                     Class<T> aSupportedTargetClass,
                                     SqlId aSqlId,
                                     Object... aParams)
                          throws DAOException
SELECT operation which returns a List of 'building block' values such as Integer, BigDecimal, and so on.

Parameters:
aConnection - single connection shared by all operations in the transaction.
aSupportedTargetClass - class supported by the configured implementation of ConvertColumn.
aSqlId - identifies the underlying SQL statement.
aParams - parameters for the SQL statement.
Returns:
an unmodifiable List of building block objects. The list may be empty.
Throws:
DAOException

listRange

public static <T> List<T> listRange(Connection aConnection,
                                    Class<T> aClass,
                                    SqlId aSqlId,
                                    Integer aStartIndex,
                                    Integer aPageSize,
                                    Object... aParams)
                         throws DAOException
SELECT operation that returns a List of Model Objects "subsetted" to a particular range of rows.

This method is intended for paging through long listings. When the underlying SELECT returns many pages of items, the records can be "subsetted" by calling this method.

See Pager.

Parameters:
aConnection - single connection shared by all operations in the transaction.
aClass - class of the returned Model Objects.
aSqlId - identifies the underlying SQL statement.
aStartIndex - 1-based index indentifying the first row to be returned.
aPageSize - number of records to be returned.
aParams - parameters for the SQL statement.
Returns:
an unmodifiable List of Model Objects. The list may be empty.
Throws:
DAOException

edit

public static int edit(Connection aConnection,
                       SqlId aSqlId,
                       Object... aParams)
                throws DAOException,
                       DuplicateException
INSERT, UPDATE, or DELETE operations which take parameters.

Parameters:
aConnection - single connection shared by all operations in the transaction.
aSqlId - identifies the underlying SQL statement.
aParams - parameters for the SQL statement.
Returns:
the number of records affected by this edit operation.
Throws:
DAOException
DuplicateException

add

public static Id add(Connection aConnection,
                     SqlId aSqlId,
                     Object... aParams)
              throws DAOException,
                     DuplicateException
INSERT operation which returns the database identifier of the added record.

This operation is not supported by all databases. See Statement for more information.

Parameters:
aConnection - single connection shared by all operations in the transaction.
aSqlId - identifies the underlying SQL statement.
aParams - parameters for the SQL statement.
Throws:
DAOException
DuplicateException

delete

public static int delete(Connection aConnection,
                         SqlId aSqlId,
                         Object... aParams)
                  throws DAOException
DELETE operation which takes parameters.

Parameters:
aConnection - single connection shared by all operations in the transaction.
aSqlId - identifies the underlying SQL statement.
aParams - identifies the item to be deleted. Often 1 or more Id objects.
Returns:
the number of deleted records.
Throws:
DAOException

fetchCompound

public static <T> T fetchCompound(Connection aConnection,
                                  Class<T> aClassParent,
                                  Class<?> aClassChild,
                                  int aNumTrailingColsForChildList,
                                  SqlId aSqlId,
                                  Object... aParams)
                       throws DAOException
SELECT operation which typically returns a single item with a 0..N relation.

The ResultSet is parsed into a single parent Model Object having a List of 0..N child Model Objects. See note on compound objects for more information.

Parameters:
aConnection - single connection shared by all operations in the transaction.
aClassParent - class of the parent Model Object.
aClassChild - class of the child Model Object.
aNumTrailingColsForChildList - number of columns appearing at the end of the ResultSet which are passed to the child constructor.
aSqlId - identifies the underlying SQL statement.
aParams - parameters to the underlying SQL statement.
Throws:
DAOException

listCompound

public static <T> List<T> listCompound(Connection aConnection,
                                       Class<T> aClassParent,
                                       Class<?> aClassChild,
                                       int aNumTrailingColsForChildList,
                                       SqlId aSqlId,
                                       Object... aParams)
                            throws DAOException
SELECT operation which typically returns mutliple items item with a 0..N relation.

The ResultSet is parsed into a List of parent Model Objects, each having 0..N child Model Objects. See note on compound objects for more information.

Parameters:
aConnection - single connection shared by all operations in the transaction.
aClassParent - class of the parent Model Object.
aClassChild - class of the child Model Object.
aNumTrailingColsForChildList - number of columns appearing at the end of the ResultSet which are passed to the child constructor.
aSqlId - identifies the underlying SQL statement.
aParams - parameters to the underlying SQL statement.
Throws:
DAOException

Version 4.10.0

Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.