dave08
02/07/2023, 11:23 AMEntityStore
subclasses for each aggregate root, and have it store the the root by itself type safely and the relations already in the form they need to be?Toshihiro Nakamura
02/07/2023, 12:27 PMdave08
02/07/2023, 12:32 PMdave08
02/07/2023, 12:34 PMdave08
02/07/2023, 12:35 PMdave08
02/07/2023, 12:37 PMdave08
02/07/2023, 12:40 PMToshihiro Nakamura
02/07/2023, 12:41 PMdave08
02/07/2023, 12:51 PMclass DepartmentEntityStore(
val departments: List<Department>,
val employees: Map<Department, List<Employee>>
)
// Maybe having some kind of wrapper for things that weren't requested in the query like employees being nullable?
///
val store: DepartmentEntityStore = db.runQuery(...includeAllTyped<Departement>())
// Still have extension functions, but with almost no cost to resuse them many times:
val employees = store.departments.first().employees
For non-aggregateroots, there could still be the include()
api with the EntityStore, and this generation of the extra store could be opt-in by indicating it in the AggregateRoot annotation...dave08
02/07/2023, 2:27 PMToshihiro Nakamura
02/08/2023, 2:12 PMdave08
02/08/2023, 2:17 PMemployees
you go through this with the current implementation:
private fun <T : Any, S : Any> createOneToMany(
first: EntityMetamodel<T, *, *>,
second: EntityMetamodel<S, *, *>,
): Map<T, Set<S>> {
if (!contains(first, second)) {
return emptyMap()
}
val oneToMany = mutableMapOf<T, MutableSet<S>>()
for (row in rows) {
val entity1 = row[first]
val entity2 = row[second]
if (entity1 != null) {
val key = first.klass().cast(entity1)
val values = oneToMany.computeIfAbsent(key) { mutableSetOf() }
if (entity2 != null) {
val value = second.klass().cast(entity2)
values.add(value)
}
}
}
return oneToMany
}
dave08
02/08/2023, 2:20 PMval
indicates that there's not some kind of expensive operation being done... so maybe the current implementation IS employees()
. But it could still be nice to avoid the intermediate structures being saved to and caching already when using runQuery
...dave08
02/08/2023, 2:24 PMToshihiro Nakamura
02/08/2023, 2:26 PMToshihiro Nakamura
02/08/2023, 2:28 PMdave08
02/08/2023, 2:28 PM