use of org.summerb.approaches.jdbccrud.api.dto.datapackage.DataTable.RefToReferencedObjectsIdsMap in project summerb by skarpushin.
the class DataSetLoaderImpl method populateBackReferencesOne2Many.
private void populateBackReferencesOne2Many(EntityTypeToObjectsMap rowsMap, Map<Ref, Set<Object>> refs, DataSet dataSet) {
for (Entry<String, List<HasId>> entry : rowsMap.entrySet()) {
for (HasId row : entry.getValue()) {
PropertyAccessor propertyAccessor = PropertyAccessorFactory.forBeanPropertyAccess(row);
for (Ref ref : refs.keySet()) {
if (!ref.getToEntity().equals(entry.getKey())) {
continue;
}
Object referencedId = null;
try {
referencedId = propertyAccessor.getPropertyValue(ref.getToField());
} catch (Throwable t) {
throw new RuntimeException("Failed to read property " + ref.getFromField() + " from " + row, t);
}
if (referencedId == null) {
continue;
}
RowIdToBackReferencesMap backRefs = dataSet.get(ref.getFromEntity()).getBackRefs();
if (backRefs.get(referencedId) == null) {
backRefs.put(referencedId, new RefToReferencedObjectsIdsMap());
}
RefToReferencedObjectsIdsMap refToObjsMap = backRefs.get(referencedId);
if (refToObjsMap.get(ref.getName()) == null) {
refToObjsMap.put(ref.getName(), new HashSet<>());
}
refToObjsMap.get(ref.getName()).add(row.getId());
}
}
}
}
use of org.summerb.approaches.jdbccrud.api.dto.datapackage.DataTable.RefToReferencedObjectsIdsMap in project summerb by skarpushin.
the class DataSetLoaderImpl method populateBackReferencesMany2Many.
private void populateBackReferencesMany2Many(ManyToManyRefToReferenceesMap manyToManyRefs, DataSet dataSet) {
for (Entry<Ref, Map<Object, List<HasId>>> refToReferenceeListPair : manyToManyRefs.entrySet()) {
DataTable sourceTable = dataSet.get(refToReferenceeListPair.getKey().getFromEntity());
RowIdToBackReferencesMap backRefs = sourceTable.getBackRefs();
for (Entry<Object, List<HasId>> referencerToReferencesListPair : refToReferenceeListPair.getValue().entrySet()) {
Object referencerId = referencerToReferencesListPair.getKey();
RefToReferencedObjectsIdsMap refToObjsMap = backRefs.get(referencerId);
if (refToObjsMap == null) {
backRefs.put(referencerId, refToObjsMap = new RefToReferencedObjectsIdsMap());
}
String refName = refToReferenceeListPair.getKey().getName();
Set<Object> referenceeIdsList = refToObjsMap.get(refName);
if (referenceeIdsList == null) {
refToObjsMap.put(refName, referenceeIdsList = new HashSet<>());
}
Set referenceeIds = EasyCrudDtoUtils.enumerateIds(referencerToReferencesListPair.getValue());
referenceeIdsList.addAll(referenceeIds);
}
}
}
Aggregations