com.samskivert.jdbc.jora
Class Table<T>

java.lang.Object
  extended by com.samskivert.jdbc.jora.Table<T>

public class Table<T>
extends Object

Used to establish mapping between corteges of database tables and Java classes. This class is responsible for constructing SQL statements for extracting, updating and deleting records of the database table.


Field Summary
protected  Class<T> _rowClass
           
protected static Object[] bypassFlag
           
protected static byte[] BYTE_PROTO
           
protected  Constructor<T> constructor
           
protected static Object[] constructorArgs
           
protected  com.samskivert.jdbc.jora.FieldDescriptor[] fields
           
static String fieldSeparator
          Spearator of name components of compound field.
protected  FieldMask fMask
           
protected  String listOfAssignments
           
protected  String listOfFields
           
protected  boolean mixedCaseConvert
           
protected  String name
           
protected  int nColumns
           
protected  int nFields
           
protected  int[] primaryKeyIndices
           
protected  String[] primaryKeys
           
protected  String qualifiedListOfFields
           
protected static Class<Serializable> serializableClass
           
protected static Method setBypass
           
 
Constructor Summary
Table(Class<T> clazz, String tableName, String key)
          Constructor for table object.
Table(Class<T> clazz, String tableName, String[] keys)
          Constructor for table object.
Table(Class<T> clazz, String tableName, String[] keys, boolean mixedCaseConvert)
          Constructor for table object.
Table(Class<T> clazz, String tableName, String key, boolean mixedCaseConvert)
          Constructor for table object.
 
Method Summary
protected  int bindQueryVariables(PreparedStatement pstmt, Object obj, int i, int end, int column, FieldMask mask)
           
protected  void bindQueryVariables(PreparedStatement pstmt, T obj, FieldMask mask)
           
protected  int bindUpdateVariables(PreparedStatement pstmt, Object obj, int i, int end, int column, FieldMask mask)
           
protected  int bindUpdateVariables(PreparedStatement pstmt, T obj, FieldMask mask)
           
protected  int buildFieldsList(ArrayList<com.samskivert.jdbc.jora.FieldDescriptor> buf, Class<?> _rowClass, String prefix)
           
protected  String buildListOfAssignments(FieldMask mask)
           
protected  void buildQueryList(StringBuilder buf, Object qbe, int i, int end, FieldMask mask, boolean like)
           
protected  String buildQueryList(T qbe, FieldMask mask, boolean like)
           
protected  String buildUpdateWhere()
           
protected  String convertName(String name)
           
 int delete(Connection conn, T obj)
          Delete record with specified value of primary key from the table.
 int delete(Connection conn, T[] objects)
          Delete records with specified primary keys from the table.
 FieldMask getFieldMask()
          Returns a field mask that can be configured and used to update subsets of entire objects via calls to update(Connection,Object,FieldMask).
 String getName()
          Returns the SQL name of the table on which we operate.
protected  void init(Class<T> clazz, String tableName, String[] keys, boolean mixedCaseConvert)
           
 void insert(Connection conn, T obj)
          Insert new record in the table.
 void insert(Connection conn, T[] objects)
          Insert several new records in the table.
 Cursor<T> join(Connection conn, String tables, String condition)
          Select records from database table according to search condition including the specified (comma separated) extra tables into the SELECT clause to facilitate a join in determining the key.
protected  int load(Object obj, int i, int end, int column, ResultSet result)
           
protected  T load(ResultSet result)
           
 Cursor<T> queryByExample(Connection conn, T obj)
          Select records from database table using obj object as template.
 Cursor<T> queryByExample(Connection conn, T obj, FieldMask mask)
          Select records from database table using obj object as template for selection.
 Cursor<T> queryByLikeExample(Connection conn, T obj)
          The same as the queryByExample, but string fields for the obj are matched using 'like' instead of equals, which allows you to send % in to do matching.
 Cursor<T> queryByLikeExample(Connection conn, T obj, FieldMask mask)
          The same as the queryByExample, but string fields for the obj are matched using 'like' instead of equals, which allows you to send % in to do matching.
 Cursor<T> select(Connection conn, String condition)
          Select records from database table according to search condition
 Cursor<T> select(Connection conn, String tables, String condition)
          Select records from database table according to search condition including the specified (comma separated) extra tables into the SELECT clause to facilitate a join in determining the key.
 Cursor<T> straightJoin(Connection conn, String table, String condition)
          Like join(java.sql.Connection, java.lang.String, java.lang.String) but does a straight join with the specified table.
 String toString()
           
 int update(Connection conn, T obj)
          Update record in the table using table's primary key to locate record in the table and values of fields of specified object obj to alter record fields.
 int update(Connection conn, T[] objects)
          Update set of records in the table using table's primary key to locate record in the table and values of fields of objects from sepecifed array objects to alter record fields.
 int update(Connection conn, T obj, FieldMask mask)
          Update record in the table using table's primary key to locate record in the table and values of fields of specified object obj to alter record fields.
protected  int updateVariables(ResultSet result, Object obj, int i, int end, int column)
           
protected  void updateVariables(ResultSet result, T obj)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fieldSeparator

public static String fieldSeparator
Spearator of name components of compound field. For example, if Java class constains component "location" of Point class, which has two components "x" and "y", then database table should have columns "location_x" and "location_y" (if '_' is used as separator).


name

protected String name

listOfFields

protected String listOfFields

qualifiedListOfFields

protected String qualifiedListOfFields

listOfAssignments

protected String listOfAssignments

_rowClass

protected Class<T> _rowClass

mixedCaseConvert

protected boolean mixedCaseConvert

fields

protected com.samskivert.jdbc.jora.FieldDescriptor[] fields

fMask

protected FieldMask fMask

nFields

protected int nFields

nColumns

protected int nColumns

primaryKeys

protected String[] primaryKeys

primaryKeyIndices

protected int[] primaryKeyIndices

constructor

protected Constructor<T> constructor

setBypass

protected static Method setBypass

serializableClass

protected static Class<Serializable> serializableClass

bypassFlag

protected static final Object[] bypassFlag

constructorArgs

protected static final Object[] constructorArgs

BYTE_PROTO

protected static final byte[] BYTE_PROTO
Constructor Detail

Table

public Table(Class<T> clazz,
             String tableName,
             String key,
             boolean mixedCaseConvert)
Constructor for table object. Make association between Java class and database table.

Parameters:
clazz - the class that represents a row entry.
tableName - name of database table mapped on this Java class
key - table's primary key. This parameter is used in UPDATE/DELETE operations to locate record in the table.
mixedCaseConvert - whether or not to convert mixed case field names into underscore separated uppercase column names.

Table

public Table(Class<T> clazz,
             String tableName,
             String key)
Constructor for table object. Make association between Java class and database table.

Parameters:
clazz - the class that represents a row entry.
tableName - name of database table mapped on this Java class
key - table's primary key. This parameter is used in UPDATE/DELETE operations to locate record in the table.

Table

public Table(Class<T> clazz,
             String tableName,
             String[] keys)
Constructor for table object. Make association between Java class and database table.

Parameters:
clazz - the class that represents a row entry.
tableName - name of database table mapped on this Java class
keys - table primary keys. This parameter is used in UPDATE/DELETE operations to locate record in the table.

Table

public Table(Class<T> clazz,
             String tableName,
             String[] keys,
             boolean mixedCaseConvert)
Constructor for table object. Make association between Java class and database table.

Parameters:
clazz - the class that represents a row entry.
tableName - name of database table mapped on this Java class
keys - table primary keys. This parameter is used in UPDATE/DELETE operations to locate record in the table.
mixedCaseConvert - whether or not to convert mixed case field names into underscore separated uppercase column names.
Method Detail

getName

public String getName()
Returns the SQL name of the table on which we operate.


select

public final Cursor<T> select(Connection conn,
                              String condition)
Select records from database table according to search condition

Parameters:
condition - valid SQL condition expression started with WHERE or empty string if all records should be fetched.

select

public final Cursor<T> select(Connection conn,
                              String tables,
                              String condition)
Select records from database table according to search condition including the specified (comma separated) extra tables into the SELECT clause to facilitate a join in determining the key.

Parameters:
tables - the (comma separated) names of extra tables to include in the SELECT clause.
condition - valid SQL condition expression started with WHERE.

join

public final Cursor<T> join(Connection conn,
                            String tables,
                            String condition)
Select records from database table according to search condition including the specified (comma separated) extra tables into the SELECT clause to facilitate a join in determining the key. To facilitate situations where data from multiple tables is being combined into a single object, the fields will not be qualified with the primary table name.

Parameters:
tables - the (comma separated) names of extra tables to include in the SELECT clause.
condition - valid SQL condition expression started with WHERE.

straightJoin

public final Cursor<T> straightJoin(Connection conn,
                                    String table,
                                    String condition)
Like join(java.sql.Connection, java.lang.String, java.lang.String) but does a straight join with the specified table.


queryByExample

public final Cursor<T> queryByExample(Connection conn,
                                      T obj)
Select records from database table using obj object as template.

Parameters:
obj - example object for search: selected objects should match all non-null fields.

queryByExample

public final Cursor<T> queryByExample(Connection conn,
                                      T obj,
                                      FieldMask mask)
Select records from database table using obj object as template for selection.

Parameters:
obj - example object for search.
mask - field mask indicating which fields in the example object should be used when building the query.

queryByLikeExample

public final Cursor<T> queryByLikeExample(Connection conn,
                                          T obj)
The same as the queryByExample, but string fields for the obj are matched using 'like' instead of equals, which allows you to send % in to do matching.


queryByLikeExample

public final Cursor<T> queryByLikeExample(Connection conn,
                                          T obj,
                                          FieldMask mask)
The same as the queryByExample, but string fields for the obj are matched using 'like' instead of equals, which allows you to send % in to do matching.


insert

public void insert(Connection conn,
                   T obj)
            throws SQLException
Insert new record in the table. Values of inserted record fields are taken from specifed object.

Parameters:
obj - object specifing values of inserted record fields
Throws:
SQLException

insert

public void insert(Connection conn,
                   T[] objects)
            throws SQLException
Insert several new records in the table. Values of inserted records fields are taken from objects of specified array.

Parameters:
objects - array with objects specifing values of inserted record fields
Throws:
SQLException

getFieldMask

public FieldMask getFieldMask()
Returns a field mask that can be configured and used to update subsets of entire objects via calls to update(Connection,Object,FieldMask).


update

public int update(Connection conn,
                  T obj)
           throws SQLException
Update record in the table using table's primary key to locate record in the table and values of fields of specified object obj to alter record fields.

Parameters:
obj - object specifing value of primary key and new values of updated record fields
Returns:
number of objects actually updated
Throws:
SQLException

update

public int update(Connection conn,
                  T obj,
                  FieldMask mask)
           throws SQLException
Update record in the table using table's primary key to locate record in the table and values of fields of specified object obj to alter record fields. Only the fields marked as modified in the supplied field mask will be updated in the database.

Parameters:
obj - object specifing value of primary key and new values of updated record fields
mask - a FieldMask instance configured to indicate which of the object's fields are modified and should be written to the database.
Returns:
number of objects actually updated
Throws:
SQLException

update

public int update(Connection conn,
                  T[] objects)
           throws SQLException
Update set of records in the table using table's primary key to locate record in the table and values of fields of objects from sepecifed array objects to alter record fields.

Parameters:
objects - array of objects specifing primiray keys and and new values of updated record fields
Returns:
number of objects actually updated
Throws:
SQLException

delete

public int delete(Connection conn,
                  T obj)
           throws SQLException
Delete record with specified value of primary key from the table.

Parameters:
obj - object containing value of primary key.
Throws:
SQLException

delete

public int delete(Connection conn,
                  T[] objects)
           throws SQLException
Delete records with specified primary keys from the table.

Parameters:
objects - array of objects containing values of primary key.
Returns:
number of objects actually deleted
Throws:
SQLException

toString

public String toString()
Overrides:
toString in class Object

init

protected final void init(Class<T> clazz,
                          String tableName,
                          String[] keys,
                          boolean mixedCaseConvert)

convertName

protected final String convertName(String name)

buildFieldsList

protected final int buildFieldsList(ArrayList<com.samskivert.jdbc.jora.FieldDescriptor> buf,
                                    Class<?> _rowClass,
                                    String prefix)

buildListOfAssignments

protected final String buildListOfAssignments(FieldMask mask)

load

protected final T load(ResultSet result)
                throws SQLException
Throws:
SQLException

load

protected final int load(Object obj,
                         int i,
                         int end,
                         int column,
                         ResultSet result)
                  throws SQLException
Throws:
SQLException

bindUpdateVariables

protected final int bindUpdateVariables(PreparedStatement pstmt,
                                        T obj,
                                        FieldMask mask)
                                 throws SQLException
Throws:
SQLException

bindQueryVariables

protected final void bindQueryVariables(PreparedStatement pstmt,
                                        T obj,
                                        FieldMask mask)
                                 throws SQLException
Throws:
SQLException

updateVariables

protected final void updateVariables(ResultSet result,
                                     T obj)
                              throws SQLException
Throws:
SQLException

buildUpdateWhere

protected final String buildUpdateWhere()

buildQueryList

protected final String buildQueryList(T qbe,
                                      FieldMask mask,
                                      boolean like)

bindUpdateVariables

protected final int bindUpdateVariables(PreparedStatement pstmt,
                                        Object obj,
                                        int i,
                                        int end,
                                        int column,
                                        FieldMask mask)
                                 throws SQLException
Throws:
SQLException

bindQueryVariables

protected final int bindQueryVariables(PreparedStatement pstmt,
                                       Object obj,
                                       int i,
                                       int end,
                                       int column,
                                       FieldMask mask)
                                throws SQLException
Throws:
SQLException

buildQueryList

protected final void buildQueryList(StringBuilder buf,
                                    Object qbe,
                                    int i,
                                    int end,
                                    FieldMask mask,
                                    boolean like)

updateVariables

protected final int updateVariables(ResultSet result,
                                    Object obj,
                                    int i,
                                    int end,
                                    int column)
                             throws SQLException
Throws:
SQLException


Copyright © 2000-2008 Michael Bayne. All Rights Reserved.