|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjodd.db.orm.mapper.DefaultResultSetMapper
public class DefaultResultSetMapper
Maps all columns of database result set (RS) row to objects. It does it in two steps: preparation (reading table and column names) and parsing (parsing one result set row to resulting objects).
Preparation
Default mapper reads RS column and table names from RS meta-data and external maps, if provided.
Since column name is always available in RS meta-data, it may be used to hold table name information.
Column names may contain table code separator (DbOrm.getColumnAliasSeparator()
that
divides column name to table reference and column name. Here, table reference may be either table name or
table alias. When it is table alias, external alias-to-name map must be provided.
Hence, this defines the table name, and there is no need to read it from RS meta-data.
When column name doesn't contain a separator, it may be either an actual column name, or a column code. For column codes, both table and column name is lookup-ed from external map. If column name is an actual column name, table information is read from the RS meta data. Unfortunately, some DBs (such Oracle) doesn't implements this simple JDBC feature. Therefore, it must be expected that column table name is not available.
Table name is also not available for columns which are not directly table columns: e.g. some calculations, counts etc.
Parsing
Parser takes types array and tries to populate their instances in best possible way. It assumes that provided
types list matches selected columns. That is very important, and yet very easy and natural to follow.
So, parser will try to inject columns value into the one result instance. Now, there are two types of instances:
simple types (numbers and strings) and entities (pojo objects). Simple types are always mapped to
one and only one column. Entities will be mapped to all possible columns that can be matched starting from
current column. So, simple types are not column-hungry, entity types are column-hungry:)
A column can be injected in one entities property only once. If one column is already mapped to current result, RS mapper will assume that current result is finished with mapping and will proceed to the next one. Similarly, if property name is not found for a column, RS mapper will proceed to the next result. Therefore, entity types are column precise and hungry;) - all listed columns must be mapped somewhere.
Results that are not used during parsing will be set to null
.
Field Summary | |
---|---|
protected int |
cachedColumnNdx
|
protected java.lang.Object |
cachedColumnValue
|
protected java.lang.String[] |
cachedTypesTableNames
|
protected java.lang.Class[] |
cachedUsedTypes
|
protected java.lang.String[] |
columnNames
|
protected DbOrm |
dbOrm
|
protected java.sql.ResultSet |
rs
|
protected java.lang.String[] |
tableNames
|
protected int |
totalColumns
|
Constructor Summary | |
---|---|
DefaultResultSetMapper(java.sql.ResultSet rs)
|
|
DefaultResultSetMapper(java.sql.ResultSet rs,
DbOrm orm)
|
|
DefaultResultSetMapper(java.sql.ResultSet rs,
java.util.Map<java.lang.String,ColumnData> columnAliases)
|
|
DefaultResultSetMapper(java.sql.ResultSet rs,
java.util.Map<java.lang.String,ColumnData> columnAliases,
DbOrm orm)
Reads RS meta-data for column and table names. |
Method Summary | |
---|---|
void |
close()
Releases this ResultSet object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. |
protected java.lang.String[] |
createTypesTableNames(java.lang.Class[] types)
Creates table names for all specified types. |
java.sql.ResultSet |
getResultSet()
Return JDBC result set. |
protected java.lang.Object |
newInstance(java.lang.Class types)
Creates new instances of a types. |
boolean |
next()
Moves the cursor down one row from its current position. |
java.lang.Object[] |
parseObjects(java.lang.Class... types)
Parse objects from result set row to specified types. |
java.lang.Object |
parseOneObject(java.lang.Class... types)
Parse single object from result set row to specified type. |
protected java.lang.Object |
readColumnValue(int colNdx)
Reads column value from result set. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected DbOrm dbOrm
protected java.sql.ResultSet rs
protected int totalColumns
protected java.lang.String[] columnNames
protected java.lang.String[] tableNames
protected java.lang.Class[] cachedUsedTypes
protected java.lang.String[] cachedTypesTableNames
protected int cachedColumnNdx
protected java.lang.Object cachedColumnValue
Constructor Detail |
---|
public DefaultResultSetMapper(java.sql.ResultSet rs)
public DefaultResultSetMapper(java.sql.ResultSet rs, DbOrm orm)
public DefaultResultSetMapper(java.sql.ResultSet rs, java.util.Map<java.lang.String,ColumnData> columnAliases)
public DefaultResultSetMapper(java.sql.ResultSet rs, java.util.Map<java.lang.String,ColumnData> columnAliases, DbOrm orm)
Method Detail |
---|
public boolean next()
next
in interface ResultSetMapper
public void close()
close
in interface ResultSetMapper
public java.sql.ResultSet getResultSet()
getResultSet
in interface ResultSetMapper
protected java.lang.Object newInstance(java.lang.Class types)
protected java.lang.String[] createTypesTableNames(java.lang.Class[] types)
null
for simple names, i.e. for all those
types that returns null
when used by DbOrm.lookupType(Class)
.
protected java.lang.Object readColumnValue(int colNdx)
public java.lang.Object[] parseObjects(java.lang.Class... types)
ResultSetMapper
parseObjects
in interface ResultSetMapper
public java.lang.Object parseOneObject(java.lang.Class... types)
ResultSetMapper
parseOneObject
in interface ResultSetMapper
ResultSetMapper.parseObjects(Class[])
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |