Skip to content

Commit

Permalink
#569 fetch domain object for hibernate proxy multi reference instance
Browse files Browse the repository at this point in the history
  • Loading branch information
junchensz committed Dec 25, 2019
1 parent e0bf135 commit 98ad760
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.hibernate.proxy.HibernateProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -588,8 +590,12 @@ private Map<String, Object> enrichCiObject(DynamicEntityMeta entityMeta, Map<Str
}
ciMap.put(fieldName, enrichMulSels);
} else if (fieldNode.isJoinNode() && DynamicEntityType.MultiReference.equals(fieldNode.getEntityType()) && Strings.isNullOrEmpty(fieldNode.getMappedBy())) {
Set<Map> referCis = (Set<Map>) value;
Set<Object> referCis = (Set<Object>) value;
attr = attrMap.get(attrId);
if(InputType.MultRef.getCode().equals(attr.getInputType())) {
referCis = fetchCiDomainObjForMultRef(attr, referCis);
}

DynamicEntityMeta multRefMeta = multRefMetaMap.get(attrId);
Map<String, Integer> sortMap = JpaQueryUtils.getSortedMapForMultiRef(entityManager, attr, multRefMeta);

Expand All @@ -604,7 +610,26 @@ private Map<String, Object> enrichCiObject(DynamicEntityMeta entityMeta, Map<Str
return ciMap;
}

private List getSortedMultRefList(Set<Map> referCis, Map<String, Integer> sortMap) {
private Set<Object> fetchCiDomainObjForMultRef(AdmCiTypeAttr attr, Set<Object> referCis) {
Integer refCiTypeId = attr.getReferenceId();
DynamicEntityMeta refEntityMeta = dynamicEntityMetaMap.get(refCiTypeId);
Class refEntityClzz = refEntityMeta.getEntityClazz();
if(refEntityClzz != null) {
Set<Object> realReferCis = new HashSet<Object>();
referCis.forEach(elem -> {
if(elem instanceof HibernateProxy) {
Object domainObj = ((HibernateProxy) elem).getHibernateLazyInitializer().getImplementation();
realReferCis.add(domainObj);
}else {
realReferCis.add(elem);
}
});
referCis = realReferCis;
}
return referCis;
}

private List getSortedMultRefList(Set<Object> referCis, Map<String, Integer> sortMap) {
List ciList = Lists.newLinkedList();
for (Object ci : referCis) {
ciList.add(ci);
Expand Down

0 comments on commit 98ad760

Please sign in to comment.