Use cast built into BeanDescriptor.beanId() rather than cast + getId()

This commit is contained in:
Rob Bygrave
2021-09-02 19:25:02 +12:00
parent 2419c6ab34
commit 455914fb52
7 changed files with 7 additions and 14 deletions
@@ -120,8 +120,7 @@ public final class LoadBeanRequest extends LoadRequest {
BeanDescriptor<?> desc = loadBuffer.getBeanDescriptor();
// collect Ids and maybe load bean cache
for (Object bean : list) {
EntityBean loadedBean = (EntityBean) bean;
loadedIds.add(desc.getId(loadedBean));
loadedIds.add(desc.beanId(bean));
}
if (loadCache) {
desc.cacheBeanPutAll(list);
@@ -141,8 +141,7 @@ public final class LoadManyRequest extends LoadRequest {
logger.debug("BeanCollection after lazy load was empty. type:" + ownerBean.getClass().getName() + " id:" + parentId + " owner:" + ownerBean);
}
} else if (isLoadCache() && many.isUseCache()) {
Object parentId = desc.getId(bc.getOwnerBean());
desc.cacheManyPropPut(many, bc, parentId);
desc.cacheManyPropPut(many, bc, desc.getId(bc.getOwnerBean()));
}
}
}
@@ -69,12 +69,10 @@ final class DefaultBeanLoader {
}
Object parentId = parentDesc.getId(parentBean);
if (pc == null) {
pc = new DefaultPersistenceContext();
parentDesc.contextPut(pc, parentId, parentBean);
}
boolean useManyIdCache = beanCollection != null && parentDesc.isManyPropCaching() && many.isUseCache();
if (useManyIdCache) {
Boolean readOnly = null;
@@ -87,7 +85,6 @@ final class DefaultBeanLoader {
}
SpiQuery<?> query = server.createQuery(parentDesc.getBeanType());
if (refresh) {
// populate a new collection
BeanCollection<?> emptyCollection = many.createEmpty(parentBean);
@@ -98,7 +95,6 @@ final class DefaultBeanLoader {
}
query.select(parentDesc.getIdBinder().getIdProperty());
if (onlyIds) {
query.fetch(many.getName(), many.getTargetIdProperty());
} else {
@@ -113,7 +109,6 @@ final class DefaultBeanLoader {
query.setMode(Mode.LAZYLOAD_MANY);
query.setLazyLoadManyPath(many.getName());
query.setPersistenceContext(pc);
if (ebi.isReadOnly()) {
query.setReadOnly(true);
}
@@ -352,7 +352,7 @@ final class BeanDescriptorCacheHelp<T> {
BeanDescriptor<?> targetDescriptor = many.getTargetDescriptor();
List<Object> idList = new ArrayList<>(actualDetails.size());
for (Object bean : actualDetails) {
idList.add(targetDescriptor.getId((EntityBean) bean));
idList.add(targetDescriptor.beanId(bean));
}
return new CachedManyIds(idList);
}
@@ -869,7 +869,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
draftVal.size();
Collection<T> actualDetails = draftVal.getActualDetails();
for (T bean : actualDetails) {
Object id = targetDescriptor.getId((EntityBean) bean);
Object id = targetDescriptor.beanId(bean);
T liveBean = liveBeansAsMap.remove(id);
if (isManyToMany()) {
@@ -899,7 +899,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
Collection<?> liveBeans = liveVal.getActualDetails();
Map<Object, T> liveMap = new LinkedHashMap<>();
for (Object liveBean : liveBeans) {
Object id = targetDescriptor.getId((EntityBean) liveBean);
Object id = targetDescriptor.beanId(liveBean);
liveMap.put(id, (T) liveBean);
}
return liveMap;
@@ -195,7 +195,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
} else {
Object assocBean = getValue(bean);
if (assocBean != null) {
Object parentId = targetDescriptor.getId((EntityBean) assocBean);
Object parentId = targetDescriptor.beanId(assocBean);
if (parentId != null) {
changeSet.addManyRemove(targetDescriptor, relationshipProperty.getName(), parentId);
}
@@ -225,7 +225,7 @@ public final class SaveManyBeans extends SaveManyBase {
detailBean = ((Map.Entry<?, ?>) detailBean).getValue();
}
if (detailBean instanceof EntityBean) {
Object id = targetDescriptor.getId((EntityBean) detailBean);
Object id = targetDescriptor.beanId(detailBean);
if (!isNullOrZero(id)) {
// remember the Id (other details not in the collection) will be removed
detailIds.add(id);