public class DefaultResultSetMapper extends BaseResultSetMapper
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 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
.
Modifier and Type | Field and Description |
---|---|
protected int |
cachedColumnNdx |
protected java.lang.Object |
cachedColumnValue |
protected DbEntityDescriptor[] |
cachedDbEntityDescriptors |
protected java.lang.String[][] |
cachedMappedNames |
protected java.lang.String[] |
cachedTypesTableNames |
protected java.lang.Class[] |
cachedUsedTypes |
protected boolean |
cacheEntities |
protected int[] |
columnDbSqlTypes |
protected java.lang.String[] |
columnNames |
protected DbOomQuery |
dbOomQuery |
protected java.util.HashMap<java.lang.Object,java.lang.Object> |
entitiesCache |
protected java.lang.String[] |
tableNames |
protected int |
totalColumns |
resultSet
Constructor and Description |
---|
DefaultResultSetMapper(DbOom dbOom,
java.sql.ResultSet resultSet,
java.util.Map<java.lang.String,ColumnData> columnAliases,
boolean cacheEntities,
DbOomQuery dbOomQuery)
Reads
ResultSet meta-data for column and table names. |
Modifier and Type | Method and Description |
---|---|
protected void |
cacheResultSetEntities(java.lang.Object[] result)
Caches returned entities.
|
protected java.lang.String[] |
createTypesTableNames(java.lang.Class[] types)
Creates table names for given types.
|
java.lang.Object[] |
parseObjects(java.lang.Class... types)
Parse objects from one result set row to specified types.
|
protected java.lang.Object |
readColumnValue(int colNdx,
java.lang.Class destinationType,
java.lang.Class<? extends SqlType> sqlTypeClass,
int columnDbSqlType)
Reads column value from result set.
|
protected DbEntityDescriptor[] |
resolveDbEntityDescriptors(java.lang.Class[] types)
Resolves
DbEntityDescriptor for all given types,
so not to repeat every time. |
protected java.lang.String[][] |
resolveMappedTypesTableNames(java.lang.Class[] types)
Resolved mapped type names for each type.
|
java.lang.Class[] |
resolveTables()
Resolves table names into the list of entity types.
|
protected java.lang.String[] |
resolveTypesTableNames(java.lang.Class[] types)
Creates table names for all specified types.
|
close, getResultSet, next, parseOneObject
protected final DbOomQuery dbOomQuery
protected final boolean cacheEntities
protected final int totalColumns
protected final java.lang.String[] columnNames
protected final int[] columnDbSqlTypes
protected final java.lang.String[] tableNames
protected DbEntityDescriptor[] cachedDbEntityDescriptors
protected java.lang.Class[] cachedUsedTypes
protected java.lang.String[] cachedTypesTableNames
protected java.lang.String[][] cachedMappedNames
protected int cachedColumnNdx
protected java.lang.Object cachedColumnValue
protected java.util.HashMap<java.lang.Object,java.lang.Object> entitiesCache
public DefaultResultSetMapper(DbOom dbOom, java.sql.ResultSet resultSet, java.util.Map<java.lang.String,ColumnData> columnAliases, boolean cacheEntities, DbOomQuery dbOomQuery)
ResultSet
meta-data for column and table names.resultSet
- JDBC result setcolumnAliases
- alias names for columns, if existcacheEntities
- flag if entities should be cacheddbOomQuery
- query that created this mapper.public java.lang.Class[] resolveTables()
protected DbEntityDescriptor[] resolveDbEntityDescriptors(java.lang.Class[] types)
DbEntityDescriptor
for all given types,
so not to repeat every time.protected java.lang.String[] resolveTypesTableNames(java.lang.Class[] types)
null
for simple names, i.e. for all those
types that returns null
when used by DbEntityManager.lookupType(Class)
.protected java.lang.String[][] resolveMappedTypesTableNames(java.lang.Class[] types)
protected java.lang.String[] createTypesTableNames(java.lang.Class[] types)
protected java.lang.Object readColumnValue(int colNdx, java.lang.Class destinationType, java.lang.Class<? extends SqlType> sqlTypeClass, int columnDbSqlType)
public java.lang.Object[] parseObjects(java.lang.Class... types)
protected void cacheResultSetEntities(java.lang.Object[] result)
Copyright © 2003-present Jodd Team