[#2689] Expose a DAO's internal RecordMapper through DAO.mapper()

This commit is contained in:
Lukas Eder 2013-08-14 09:13:43 +02:00
parent 268ca49173
commit a207faef0a
2 changed files with 23 additions and 4 deletions

View File

@ -61,6 +61,15 @@ public interface DAO<R extends TableRecord<R>, P, T> {
*/
Configuration configuration();
/**
* Expose the {@link RecordMapper} that is used internally by this
* <code>DAO</code> to map from records of type <code>R</code> to POJOs of
* type <code>P</code>.
*
* @return the <code>DAO</code>'s underlying <code>RecordMapper</code>
*/
RecordMapper<R, P> mapper();
/**
* Performs an <code>INSERT</code> statement for a given POJO
*

View File

@ -95,6 +95,16 @@ public abstract class DAOImpl<R extends UpdatableRecord<R>, P, T> implements DAO
return configuration;
}
/**
* {@inheritDoc}
* <p>
* Subclasses may override this method to provide custom implementations.
*/
@Override
public /* non-final */ RecordMapper<R, P> mapper() {
return mapper;
}
// -------------------------------------------------------------------------
// XXX: DAO API
// -------------------------------------------------------------------------
@ -211,7 +221,7 @@ public abstract class DAOImpl<R extends UpdatableRecord<R>, P, T> implements DAO
return using(configuration)
.selectFrom(table)
.fetch()
.map(mapper);
.map(mapper());
}
@Override
@ -226,7 +236,7 @@ public abstract class DAOImpl<R extends UpdatableRecord<R>, P, T> implements DAO
.fetchOne();
}
return mapper.map(record);
return mapper().map(record);
}
@Override
@ -235,7 +245,7 @@ public abstract class DAOImpl<R extends UpdatableRecord<R>, P, T> implements DAO
.selectFrom(table)
.where(field.in(values))
.fetch()
.map(mapper);
.map(mapper());
}
@Override
@ -245,7 +255,7 @@ public abstract class DAOImpl<R extends UpdatableRecord<R>, P, T> implements DAO
.where(field.equal(value))
.fetchOne();
return mapper.map(record);
return mapper().map(record);
}
@Override