org.pojava.persistence.sql
Class TableMap<POJO>

java.lang.Object
  extended by org.pojava.persistence.sql.TableMap<POJO>

public class TableMap<POJO>
extends Object

TableMap manages a collection of mappings between a Java bean and a database table. It allows for either a manual or automated mapping of each property. Each property is defined by its get/set accessors.

Author:
John Pile

Constructor Summary
TableMap(Class<POJO> javaClass, String tableName, String dataSourceName)
          Construct a table map defining the Java class, Table name and DataSource name.
 
Method Summary
 void addFieldMap(FieldMap<POJO,?,?> field)
          Add a field map to this table map.
 void addFieldMap(String property, String fieldName, boolean isKeyField, org.pojava.transformation.BindingAdaptor<Object,Object> adaptor)
          Add a FieldMap to this TableMap.
 void addFieldMap(String property, String fieldName, boolean isKeyField, Class<Object> columnClass)
          Add a FieldMap to this TableMap.
 void autoBind()
          Populate the field mappings by asking the database for MetaData.
 POJO extractObject(ResultSet rs)
          Extract an Object specific to this TableMap
 Map<String,FieldMap<POJO,?,?>> getAllFields()
           
 String getDataSourceName()
           
 Class<POJO> getJavaClass()
           
 List<FieldMap<POJO,?,?>> getKeyFields()
           
 List<FieldMap<POJO,?,?>> getNonKeyFields()
           
 String getTableName()
           
 org.pojava.lang.BoundString sqlDelete(POJO bean)
          Form a DELETE statement for this map.
 org.pojava.lang.BoundString sqlInsert(POJO bean)
          Form an INSERT statement for this map.
 org.pojava.lang.BoundString sqlSelect()
          Form a SELECT statement for this map.
 org.pojava.lang.BoundString sqlSelect(POJO bean)
          Form a SELECT statement for this map filtered by key fields to a single object.
 org.pojava.lang.BoundString sqlUpdate(POJO bean)
          Form an UPDATE statement for this map.
 org.pojava.lang.BoundString whereKeyFieldsMatch(POJO bean)
          Form a WHERE clause for the key fields of this map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableMap

public TableMap(Class<POJO> javaClass,
                String tableName,
                String dataSourceName)
Construct a table map defining the Java class, Table name and DataSource name.

Parameters:
javaClass -
tableName -
dataSourceName -
Method Detail

autoBind

public void autoBind()
              throws SQLException
Populate the field mappings by asking the database for MetaData.

Throws:
SQLException

getTableName

public String getTableName()

getJavaClass

public Class<POJO> getJavaClass()

getDataSourceName

public String getDataSourceName()

getKeyFields

public List<FieldMap<POJO,?,?>> getKeyFields()

getNonKeyFields

public List<FieldMap<POJO,?,?>> getNonKeyFields()

getAllFields

public Map<String,FieldMap<POJO,?,?>> getAllFields()

addFieldMap

public void addFieldMap(FieldMap<POJO,?,?> field)
                 throws NoSuchMethodException
Add a field map to this table map.

Parameters:
field -
Throws:
NoSuchMethodException

addFieldMap

public void addFieldMap(String property,
                        String fieldName,
                        boolean isKeyField,
                        Class<Object> columnClass)
                 throws NoSuchMethodException
Add a FieldMap to this TableMap.

Parameters:
property -
fieldName -
isKeyField -
columnClass -
Throws:
NoSuchMethodException

addFieldMap

public void addFieldMap(String property,
                        String fieldName,
                        boolean isKeyField,
                        org.pojava.transformation.BindingAdaptor<Object,Object> adaptor)
                 throws NoSuchMethodException
Add a FieldMap to this TableMap.

Parameters:
property -
fieldName -
isKeyField -
adaptor -
Throws:
NoSuchMethodException

sqlSelect

public org.pojava.lang.BoundString sqlSelect()
Form a SELECT statement for this map.

Returns:
SQL select statement

sqlSelect

public org.pojava.lang.BoundString sqlSelect(POJO bean)
Form a SELECT statement for this map filtered by key fields to a single object.

Returns:
SQL select statement

sqlInsert

public org.pojava.lang.BoundString sqlInsert(POJO bean)
Form an INSERT statement for this map.

Parameters:
bean -
Returns:
SQL insert statement

sqlUpdate

public org.pojava.lang.BoundString sqlUpdate(POJO bean)
Form an UPDATE statement for this map.

Parameters:
bean -
Returns:
SQL update statement

sqlDelete

public org.pojava.lang.BoundString sqlDelete(POJO bean)
Form a DELETE statement for this map.

Parameters:
bean -
Returns:
SQL delete statement

whereKeyFieldsMatch

public org.pojava.lang.BoundString whereKeyFieldsMatch(POJO bean)
Form a WHERE clause for the key fields of this map.

Parameters:
bean -
Returns:
SQL where clause

extractObject

public POJO extractObject(ResultSet rs)
Extract an Object specific to this TableMap

Parameters:
rs - ResultSet already advanced to next row.
Returns:
bean extracted from a ResultSet row.


Copyright © 2011. All Rights Reserved.