/** * Return the Id value for the bean. */ public Object getBeanId() { return beanDescriptor.getId(entityBean); }
/** * Fetch the outline bean with associated one and associated many beans loaded with Id values only. * <p> * We use the Id values to determine what are inserts, updates and deletes as part of the merge. */ private EntityBean fetchOutline(Set<String> paths) { Query<?> query = server.find(desc.getBeanType()); query.setBeanCacheMode(CacheMode.OFF); query.setPersistenceContextScope(PersistenceContextScope.QUERY); query.setId(desc.getId(bean)); query.select(desc.getIdProperty().getName()); for (String path : paths) { MergeNode node = buildNode(path); node.addSelectId(query); } return (EntityBean) server.findOne(query, transaction); }
/** * Return true if the otherBean has an Id value. */ public boolean hasImportedId(EntityBean otherBean) { return null != targetDescriptor.getId(otherBean); }
@Override public Object beanId(Object bean) { return getId((EntityBean) bean); }
@Override public Object getBeanId(T bean) { return getId((EntityBean) bean); }
public Object getParentId(EntityBean parentBean) { return descriptor.getId(parentBean); }
/** * Return the outline beans as a map keyed by Id values. */ Map<Object, EntityBean> toMap(Collection outlines) { Map<Object, EntityBean> outlineMap = new HashMap<>(); if (outlines != null) { for (Object out : outlines) { EntityBean outlineBean = (EntityBean) out; Object outlineId = targetDescriptor.getId(outlineBean); outlineMap.put(outlineId, outlineBean); } } return outlineMap; }
/** * The hash used to register the bean with the transaction. * <p> * Takes into account the class type and id value. * </p> */ private Integer getBeanHash() { if (beanHash == null) { Object id = beanDescriptor.getId(entityBean); int hc = 92821 * bean.getClass().getName().hashCode(); if (id != null) { hc += id.hashCode(); } beanHash = hc; } return beanHash; }
/** * Add the bean to the persistence context. */ public void persistenceContextAdd(EntityBean bean) { Object id = beanDescriptor.getId(bean); beanDescriptor.contextPut(persistenceContext, id, bean); }
@SuppressWarnings("unchecked") private Map<Object, T> liveBeansAsMap(BeanCollection<?> liveVal) { liveVal.size(); Collection<?> liveBeans = liveVal.getActualDetails(); Map<Object, T> liveMap = new LinkedHashMap<>(); for (Object liveBean : liveBeans) { Object id = targetDescriptor.getId((EntityBean) liveBean); liveMap.put(id, (T) liveBean); } return liveMap; }
/** * Collect the Id values of the details to remove 'missing children' for stateless updates. */ private List<Object> collectIds(Collection<?> collection, BeanDescriptor<?> targetDescriptor, boolean isMap) { List<Object> detailIds = new ArrayList<>(); // stateless update with deleteMissingChildren so first // collect the Id values to remove the 'missing children' for (Object detailBean : collection) { if (isMap) { detailBean = ((Map.Entry<?, ?>) detailBean).getValue(); } if (detailBean instanceof EntityBean) { Object id = targetDescriptor.getId((EntityBean) detailBean); if (!DmlUtil.isNullOrZero(id)) { // remember the Id (other details not in the collection) will be removed detailIds.add(id); } } } return detailIds; }
@Override public Object getBeanId(Object bean) { EntityBean eb = checkEntityBean(bean); BeanDescriptor<?> desc = getBeanDescriptor(bean.getClass()); if (desc == null) { throw new PersistenceException(bean.getClass().getName() + " is NOT an Entity Bean registered with this server?"); } return desc.getId(eb); }
private CachedManyIds createManyIds(BeanPropertyAssocMany<?> many, Object details) { Collection<?> actualDetails = BeanCollectionUtil.getActualDetails(details); if (actualDetails == null) { return null; } BeanDescriptor<?> targetDescriptor = many.getTargetDescriptor(); List<Object> idList = new ArrayList<>(actualDetails.size()); for (Object bean : actualDetails) { idList.add(targetDescriptor.getId((EntityBean) bean)); } return new CachedManyIds(idList); }
/** * Return the list of Id values for the beans in the lazy load buffer. */ public List<Object> getIdList(int batchSize) { List<Object> idList = new ArrayList<>(batchSize); BeanDescriptor<?> desc = loadBuffer.getBeanDescriptor(); for (EntityBeanIntercept ebi : batch) { EntityBean bean = ebi.getOwner(); idList.add(desc.getId(bean)); } if (!desc.isMultiValueIdSupported() && !idList.isEmpty()) { int extraIds = batchSize - batch.size(); if (extraIds > 0) { // for performance make up the Id's to the batch size // so we get the same query (for Ebean and the db) Object firstId = idList.get(0); for (int i = 0; i < extraIds; i++) { // just add the first Id again idList.add(firstId); } } } return idList; }
/** * For a bean built from the cache this sets up its persistence context for future lazy loading etc. */ private void setupContext(Object bean, PersistenceContext context) { if (context == null) { context = new DefaultPersistenceContext(); } // Not using a loadContext for beans coming out of L2 cache // so that means no batch lazy loading for these beans EntityBean entityBean = (EntityBean) bean; EntityBeanIntercept ebi = entityBean._ebean_getIntercept(); ebi.setPersistenceContext(context); Object id = desc.getId(entityBean); desc.contextPut(context, id, bean); }
/** * Set the parent bean to the child bean if it has not already been set. */ public void setParentBeanToChild(EntityBean parent, EntityBean child) { if (primaryKeyExport) { Object parentId = descriptor.getId(parent); targetDescriptor.convertSetId(parentId, child); } if (mappedBy != null) { BeanProperty beanProperty = targetDescriptor.getBeanProperty(mappedBy); if (beanProperty != null && beanProperty.getValue(child) == null) { // set the 'parent' bean to the 'child' bean beanProperty.setValue(child, parent); } } } }
@Override public void markAsDeleted(EntityBean bean) { if (softDeleteProperty == null) { Object id = getId(bean); logger.info("(Lazy) loading unsuccessful for type:{} id:{} - expecting when bean has been deleted", getName(), id); bean._ebean_getIntercept().setLazyLoadFailure(id); } else { setSoftDeleteValue(bean); bean._ebean_getIntercept().setLoaded(); setAllLoaded(bean); } }
/** * Completed update request handling cases for element collection and where ONLY * many properties were updated. */ public void completeUpdate() { if (!dirty && updatedManys != null) { // set the flag and register for post commit processing if there // is caching or registered listeners if (idValue == null) { this.idValue = beanDescriptor.getId(entityBean); } // not dirty so postExecute() will never be called // set true to trigger cache notify if needed postExecute = true; updatedManysOnly = true; setNotifyCache(); addPostCommitListeners(); } notifyCacheOnComplete(); postUpdateNotify(); }
/** * Clear part of the L2 relationship cache for this property. */ void cacheDelete(boolean clear, EntityBean bean, CacheChangeSet changeSet) { if (cacheNotifyRelationship) { if (clear) { changeSet.addManyClear(targetDescriptor, relationshipProperty.getName()); } else { Object assocBean = getValue(bean); if (assocBean != null) { Object parentId = targetDescriptor.getId((EntityBean) assocBean); if (parentId != null) { changeSet.addManyRemove(targetDescriptor, relationshipProperty.getName(), parentId); } } } } }
@Override public void merge(MergeRequest request) { EntityBean entityBean = getEntityBean(request.getBean()); if (entityBean == null) { checkOrphanRemoval(request); } else { Object beanId = targetDescriptor.getId(entityBean); if (beanId == null) { checkOrphanRemoval(request); } else { EntityBean outlineBean = getEntityBean(request.getOutline()); Object outlineId = (outlineBean == null) ? null : targetDescriptor.getId(outlineBean); if (isUpdate(beanId, outlineId, request)) { entityBean._ebean_getIntercept().setForceUpdate(true); cascade(entityBean, outlineBean, request); } } } }