|
Spring Data JDBC Extensions | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.springframework.data.jdbc.core.OneToManyResultSetExtractor<R,C,K>
public abstract class OneToManyResultSetExtractor<R,C,K>
An abstract results extractor for row mapping operations that map multiple rows to a single root object. This is useful when joining a one-to-many relationship where there can be multiple child rows returned per parent root.
It's assumed that the root type R table has a primary key (id) of type K and that the child type C table has a foreign key of type K referencing the root table's primary key.
For example, consider the relationship: "a Customer has one-to-many Addresses". When joining the Customer table with the Address table to build a Customer object, multiple rows would be returned for a Customer if it has more than one Address. This extractor is useful in that case.
| Nested Class Summary | |
|---|---|
static class |
OneToManyResultSetExtractor.ExpectedResults
|
| Field Summary | |
|---|---|
protected RowMapper<C> |
childMapper
|
protected OneToManyResultSetExtractor.ExpectedResults |
expectedResults
|
protected List<R> |
results
|
protected RowMapper<R> |
rootMapper
|
| Constructor Summary | |
|---|---|
OneToManyResultSetExtractor(RowMapper<R> rootMapper,
RowMapper<C> childMapper)
Creates a new OneToManyResultSetExtractor from the given RowMappers. |
|
OneToManyResultSetExtractor(RowMapper<R> rootMapper,
RowMapper<C> childMapper,
OneToManyResultSetExtractor.ExpectedResults expectedResults)
Creates a new OneToManyResultSetExtractor from the given RowMappers and OneToManyResultSetExtractor.ExpectedResults. |
|
| Method Summary | |
|---|---|
protected abstract void |
addChild(R root,
C child)
Add the child object to the root object This method must be implemented by subclasses. |
List<R> |
extractData(ResultSet rs)
|
protected abstract K |
mapForeignKey(ResultSet rs)
Map the foreign key value to the required type. |
protected abstract K |
mapPrimaryKey(ResultSet rs)
Map the primary key value to the required type. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final OneToManyResultSetExtractor.ExpectedResults expectedResults
protected final RowMapper<R> rootMapper
protected final RowMapper<C> childMapper
protected List<R> results
| Constructor Detail |
|---|
public OneToManyResultSetExtractor(RowMapper<R> rootMapper,
RowMapper<C> childMapper)
OneToManyResultSetExtractor from the given RowMappers.
rootMapper - RowMapper to map the root entity, must not be null.childMapper - RowMapper to map the root entities, must not be null.
public OneToManyResultSetExtractor(RowMapper<R> rootMapper,
RowMapper<C> childMapper,
OneToManyResultSetExtractor.ExpectedResults expectedResults)
OneToManyResultSetExtractor from the given RowMappers and OneToManyResultSetExtractor.ExpectedResults.
rootMapper - RowMapper to map the root entity, must not be null.childMapper - RowMapper to map the root entities, must not be null.expectedResults - | Method Detail |
|---|
public List<R> extractData(ResultSet rs)
throws SQLException,
DataAccessException
extractData in interface ResultSetExtractor<List<R>>SQLException
DataAccessException
protected abstract K mapPrimaryKey(ResultSet rs)
throws SQLException
next() on
the ResultSet; it is only supposed to map values of the current row.
rs - the ResultSet
SQLException
protected abstract K mapForeignKey(ResultSet rs)
throws SQLException
next() on
the ResultSet; it is only supposed to map values of the current row.
rs - the ResultSet
SQLException
protected abstract void addChild(R root,
C child)
root - the Root objectchild - the Child object
|
Spring Data JDBC Extensions | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||