Skip to content

Commit 46b213f

Browse files
committed
Rename TableCrud -> Dao, fix generic issues by calling mapper.map instead of record.map
1 parent 4bac3e1 commit 46b213f

File tree

1 file changed

+8
-9
lines changed
  • stubbornjava-common/src/main/java/com/stubbornjava/common/db

1 file changed

+8
-9
lines changed

stubbornjava-common/src/main/java/com/stubbornjava/common/db/Dao.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
import org.jooq.UpdatableRecord;
1919
import org.jooq.impl.TableImpl;
2020

21-
public class TableCrud<Rec extends UpdatableRecord<Rec>, T> {
21+
public class Dao<Rec extends UpdatableRecord<Rec>, T> {
2222
private final TableImpl<Rec> table;
23-
private final RecordMapper<Record, T> mapper;
23+
private final RecordMapper<Rec, T> mapper;
2424
private final RecordUnmapper<T, Rec> unmapper;
2525
private final Supplier<DSLContext> configSupplier;
26-
public TableCrud(TableImpl<Rec> table,
27-
// Ideally this would be RecordMapper<Rec, T> mapper but hitting generic issues
28-
RecordMapper<Record, T> mapper,
26+
public Dao(TableImpl<Rec> table,
27+
RecordMapper<Rec, T> mapper,
2928
RecordUnmapper<T, Rec> unmapper,
3029
Supplier<DSLContext> configSupplier) {
3130
super();
@@ -38,7 +37,7 @@ public TableCrud(TableImpl<Rec> table,
3837
public T insertReturning(T obj) {
3938
Rec rec = records(Collections.singletonList(obj), false).get(0);
4039
rec.insert();
41-
return rec.map(mapper);
40+
return mapper.map(rec);
4241
}
4342

4443
public void insert(T obj) {
@@ -104,11 +103,11 @@ else if (objects.size() == 1) {
104103
}
105104
}
106105

107-
public T findOne(Function<TableImpl<Rec>, Condition> func) {
108-
return configSupplier.get().fetchOne(table, func.apply(table)).map(mapper);
106+
public T fetchOne(Function<TableImpl<Rec>, Condition> func) {
107+
return mapper.map(configSupplier.get().fetchOne(table, func.apply(table)));
109108
}
110109

111-
public List<T> find(Function<TableImpl<Rec>, Condition> func) {
110+
public List<T> fetch(Function<TableImpl<Rec>, Condition> func) {
112111
return configSupplier.get().fetch(table, func.apply(table)).map(mapper);
113112
}
114113

0 commit comments

Comments
 (0)