/** * Returns the id of the entity. A generated id is not guaranteed to be * available until after the database insert has occurred. Returns null if * the entity does not yet have an id * * @param entity * @return id of the entity * @throws IllegalArgumentException * if the entity is found not to be an entity. */ public static Object getIdentifier(Object entity, AbstractSession session) { ClassDescriptor descriptor = session.getDescriptor(entity); if (descriptor == null) { throw new IllegalArgumentException(ExceptionLocalization.buildMessage("jpa_persistence_util_non_persistent_class", new Object[] { entity })); } if (descriptor.getCMPPolicy() != null) { return descriptor.getCMPPolicy().createPrimaryKeyInstance(entity, session); } else { // 308950: Alternatively, CacheImpl.getId(entity) handles a null CMPPolicy case for weaved and unweaved domain object throw new IllegalArgumentException(ExceptionLocalization.buildMessage("jpa_persistence_util_non_persistent_class", new Object[] { entity })); } }
/** * INTERNAL: * This method will access the target relationship and create a list of PKs of the target entities. * This method is used in combination with the CachedValueHolder to store references to PK's to be loaded * from a cache instead of a query. */ public Object[] buildReferencesPKList(Object entity, Object attribute, AbstractSession session){ ClassDescriptor referenceDescriptor = getReferenceDescriptor(); Object collection = this.indirectionPolicy.getRealAttributeValueFromObject(entity, attribute); Object[] result = new Object[this.containerPolicy.sizeFor(collection)]; Iterator iterator = (Iterator)this.containerPolicy.iteratorFor(collection); int index = 0; while(iterator.hasNext()){ Object target = iterator.next(); if (target != null){ CMPPolicy policy = referenceDescriptor.getCMPPolicy(); if (policy != null && policy.isCMP3Policy()){ result[index] = policy.createPrimaryKeyInstance(target, session); }else{ result[index] = referenceDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(target, session); } ++index; } } return result; }
/** * INTERNAL: This method will access the target relationship and create a * list of PKs of the target entities. This method is used in combination * with the CachedValueHolder to store references to PK's to be loaded from * a cache instead of a query. */ public Object[] buildReferencesPKList(Object entity, Object attribute, AbstractSession session) { ClassDescriptor referenceDescriptor = getReferenceDescriptor(); Object target = this.indirectionPolicy.getRealAttributeValueFromObject(entity, attribute); Object[] result = new Object[1]; if (target != null){ CMPPolicy policy = referenceDescriptor.getCMPPolicy(); if (policy != null && policy.isCMP3Policy()) { result[0] = policy.createPrimaryKeyInstance(target, session); } else { result[0] = referenceDescriptor.getObjectBuilder().extractPrimaryKeyFromObject(target, session); } } return result; }
} else if (mapping.isObjectReferenceMapping()) { // what if mapping comes from derived ID. need to get the derived mapping. keyInstance = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(key, session); } else if (mapping.isObjectReferenceMapping()) { // what if mapping comes from derived ID. need to get the derived mapping. fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(key, session);
Object fieldValue = mapping.getRealAttributeValueFromObject(object, session); if (mapping.isObjectReferenceMapping()){ fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session); fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session); usedObjectReferenceMappings.add((ObjectReferenceMapping)mapping);
Object fieldValue = mapping.getRealAttributeValueFromObject(key, session); if (mapping.isObjectReferenceMapping()){ fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session); fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session); usedObjectReferenceMappings.add((ObjectReferenceMapping)mapping);
return getElementDescriptor().getCMPPolicy().createPrimaryKeyInstance(keyElement, session);
return getElementDescriptor().getCMPPolicy().createPrimaryKeyInstance(keyElement, session);
return getElementDescriptor().getCMPPolicy().createPrimaryKeyInstance(keyElement, session);
Object fieldValue = mapping.getRealAttributeValueFromObject(object, session); if (mapping.isObjectReferenceMapping()){ fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session); fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session); usedObjectReferenceMappings.add((ObjectReferenceMapping)mapping);
key = updateDerivedIds(parentClone, parentDescriptor); } else { key = parentDescriptor.getCMPPolicy().createPrimaryKeyInstance(parentClone, this);
key = updateDerivedIds(parentClone, parentDescriptor); } else { key = parentDescriptor.getCMPPolicy().createPrimaryKeyInstance(parentClone, this);
key = updateDerivedIds(parentClone, parentDescriptor); } else { key = parentDescriptor.getCMPPolicy().createPrimaryKeyInstance(parentClone, this);