/** * @see org.seasar.framework.jpa.metadata.AttributeDesc#getValue(java.lang.Object) */ public Object getValue(Object entity) { return mapping.getRealAttributeValueFromObject(entity, null); }
public Object getValue(Object object, AbstractSession session) { return mapping.getRealAttributeValueFromObject(object, session); }
@SuppressWarnings("rawtypes") protected void removeMappingValueFromObject(Object object, Object attributeValue, DatabaseMapping mapping, DatabaseMapping partner) { if (mapping.isObjectReferenceMapping()) { Object currentValue = mapping.getRealAttributeValueFromObject(object, (AbstractSession) getServerSession()); if (currentValue.equals(attributeValue)) { ((ObjectReferenceMapping) mapping).getIndirectionPolicy().setRealAttributeValueInObject(object, null, true); if (partner != null) { removeMappingValueFromObject(attributeValue, object, partner, null); } } } else if (mapping.isCollectionMapping()) { boolean removed = ((Collection) mapping.getRealAttributeValueFromObject(object, (AbstractSession) getServerSession())).remove(attributeValue); if (removed && partner != null) { removeMappingValueFromObject(attributeValue, object, partner, null); } } }
@SuppressWarnings("rawtypes") protected void removeMappingValueFromObject(Object object, Object attributeValue, DatabaseMapping mapping, DatabaseMapping partner) { if (mapping.isObjectReferenceMapping()) { Object currentValue = mapping.getRealAttributeValueFromObject(object, (AbstractSession) getServerSession()); if (currentValue.equals(attributeValue)) { ((ObjectReferenceMapping) mapping).getIndirectionPolicy().setRealAttributeValueInObject(object, null, true); if (partner != null) { removeMappingValueFromObject(attributeValue, object, partner, null); } } } else if (mapping.isCollectionMapping()) { boolean removed = ((Collection) mapping.getRealAttributeValueFromObject(object, (AbstractSession) getServerSession())).remove(attributeValue); if (removed && partner != null) { removeMappingValueFromObject(attributeValue, object, partner, null); } } }
if (pkElementArray.length == 1 && pkElementArray[0] instanceof KeyIsElementAccessor){ DatabaseMapping mapping = builder.getMappingForAttributeName(pkElementArray[0].getAttributeName()); Object fieldValue = mapping.getRealAttributeValueFromObject(object, session); if (mapping.isObjectReferenceMapping()){ fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session); keyObj = mapping.getRealAttributeValueFromObject(keyObj, session); mapping = mapping.getReferenceDescriptor().getObjectBuilder().getMappingForField(field); Object fieldValue = mapping.getRealAttributeValueFromObject(keyObj, session); if (mapping.isObjectReferenceMapping()){ fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session);
if (pkElementArray.length == 1 && pkElementArray[0] instanceof KeyIsElementAccessor){ DatabaseMapping mapping = builder.getMappingForAttributeName(pkElementArray[0].getAttributeName()); Object fieldValue = mapping.getRealAttributeValueFromObject(key, session); if (mapping.isObjectReferenceMapping()){ fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session); keyObj = mapping.getRealAttributeValueFromObject(keyObj, session); mapping = mapping.getReferenceDescriptor().getObjectBuilder().getMappingForField(field); Object fieldValue = mapping.getRealAttributeValueFromObject(keyObj, session); if (mapping.isObjectReferenceMapping()){ fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session);
if (pkElementArray.length == 1 && pkElementArray[0] instanceof KeyIsElementAccessor){ DatabaseMapping mapping = builder.getMappingForAttributeName(pkElementArray[0].getAttributeName()); Object fieldValue = mapping.getRealAttributeValueFromObject(object, session); if (mapping.isObjectReferenceMapping()){ fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session); keyObj = mapping.getRealAttributeValueFromObject(keyObj, session); mapping = mapping.getReferenceDescriptor().getObjectBuilder().getMappingForField(field); Object nestedObject = mapping.getRealAttributeValueFromObject(nestedKeyInstance, session); if (nestedObject == null) { nestedObject = getClassInstance(mapping.getReferenceDescriptor().getJavaClass()); Object fieldValue = mapping.getRealAttributeValueFromObject(keyObj, session); if (mapping.isObjectReferenceMapping()){ fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstance(fieldValue, session);
Object attributeValue = mapping.getRealAttributeValueFromObject(baseValue, session); if (attributeValue != null) { if (mapping.isForeignReferenceMapping() && (((ForeignReferenceMapping)mapping).getIndirectionPolicy().usesTransparentIndirection())) {
/** * INTERNAL: * Helper method to get the value from the clone for the expression passed in, triggering joins on * all intermediate steps. * Example expression "emp.project.pk" with a clone Employee will trigger indirection and return * the project pk value. * @param session * @param clone * @param expression * @return */ public Object getValueFromObjectForExpression(AbstractSession session, Object clone, ObjectExpression expression){ if (!expression.isExpressionBuilder()){ //can only operate over querykeys representing aggregate Objects. Indirection should not be needed Object baseValue = this.getValueFromObjectForExpression(session, clone, (ObjectExpression)expression.getBaseExpression()); if ( baseValue == null ) { return null; } DatabaseMapping mapping = expression.getMapping(); Object attributeValue = mapping.getRealAttributeValueFromObject(baseValue, session); if (attributeValue != null) { if (mapping.isForeignReferenceMapping() && (((ForeignReferenceMapping)mapping).getIndirectionPolicy().usesTransparentIndirection())) { //getRealAttributeValueFromObject does not trigger transparent indirection, but instantiateObject will (it calls size on it) ((ForeignReferenceMapping)mapping).getIndirectionPolicy().instantiateObject(baseValue, attributeValue); } } return attributeValue; } return clone; }
DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForAttributeName(joinManager.getJoinedAttributes().get(index)); if (mapping !=null){ Object attributeValue = mapping.getRealAttributeValueFromObject(clone, unitOfWork); if (attributeValue != null){ if ( mapping.isForeignReferenceMapping() && (((ForeignReferenceMapping)mapping).getIndirectionPolicy().usesTransparentIndirection()) ) {
/** * This is used for a remote unit of work. * If the value holder is sent back to the server uninstantiated and * it needs to be instantiated, then we must find the original * object and get the appropriate attribute from it. */ protected Object getValueFromServerObject() { setSession(getRemoteUnitOfWork()); Object primaryKey = getSession().getId(getSourceObject()); Object originalObject = getUnitOfWork().getParent().getIdentityMapAccessor().getFromIdentityMap(primaryKey, getSourceObject().getClass()); if (originalObject == null) { originalObject = getUnitOfWork().getParent().readObject(getSourceObject()); } ClassDescriptor descriptor = getSession().getDescriptor(originalObject); DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForAttributeName(getSourceAttributeName()); setMapping(mapping); return getMapping().getRealAttributeValueFromObject(originalObject, getSession()); }
Object parentClone = derivesIdMapping.getRealAttributeValueFromObject(clone, this); Object aggregateClone = derivedIdMapping.getRealAttributeValueFromObject(clone, this);
ClassDescriptor parentDescriptor = derivesIdMapping.getReferenceDescriptor(); ObjectBuilder parentBuilder = parentDescriptor.getObjectBuilder(); Object parentClone = derivesIdMapping.getRealAttributeValueFromObject(clone, this); Object aggregateClone = derivedIdMapping.getRealAttributeValueFromObject(clone, this);
/** * This is used for a remote unit of work. * If the value holder is sent back to the server uninstantiated and * it needs to be instantiated, then we must find the original * object and get the appropriate attribute from it. */ protected Object getValueFromServerObject() { setSession(getRemoteUnitOfWork()); Object primaryKey = getSession().getId(getSourceObject()); Object originalObject = getUnitOfWork().getParent().getIdentityMapAccessor().getFromIdentityMap(primaryKey, getSourceObject().getClass()); if (originalObject == null) { originalObject = getUnitOfWork().getParent().readObject(getSourceObject()); } ClassDescriptor descriptor = getSession().getDescriptor(originalObject); DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForAttributeName(getSourceAttributeName()); setMapping(mapping); return getMapping().getRealAttributeValueFromObject(originalObject, getSession()); }
/** * This is used for a remote unit of work. * If the value holder is sent back to the server uninstantiated and * it needs to be instantiated, then we must find the original * object and get the appropriate attribute from it. */ protected Object getValueFromServerObject() { setSession(getRemoteUnitOfWork()); Vector primaryKey = getSession().keyFromObject(getSourceObject()); Object originalObject = getUnitOfWork().getParent().getIdentityMapAccessor().getFromIdentityMap(primaryKey, getSourceObject().getClass()); if (originalObject == null) { originalObject = getUnitOfWork().getParent().readObject(getSourceObject()); } ClassDescriptor descriptor = getSession().getDescriptor(originalObject); DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForAttributeName(getSourceAttributeName()); setMapping(mapping); return getMapping().getRealAttributeValueFromObject(originalObject, getSession()); }
Object nestedObject = mapping.getRealAttributeValueFromObject(keyInstance, session);
/** * INTERNAL: * Recursive method to set a field value in the given key instance. */ protected void setFieldValue(KeyElementAccessor accessor, Object keyInstance, DatabaseMapping mapping, AbstractSession session, int[] elementIndex, Object ... keyElements) { if (mapping.isAggregateMapping()) { Object nestedObject = mapping.getRealAttributeValueFromObject(keyInstance, session); if (nestedObject == null) { nestedObject = getClassInstance(mapping.getReferenceDescriptor().getJavaClass()); mapping.setRealAttributeValueInObject(keyInstance, nestedObject); } // keep drilling down the nested mappings ... setFieldValue(accessor, nestedObject, mapping.getReferenceDescriptor().getObjectBuilder().getMappingForField(accessor.getDatabaseField()), session, elementIndex, keyElements); } else { Object fieldValue = null; if (mapping.isAbstractColumnMapping()) { fieldValue = keyElements[elementIndex[0]]; Converter converter = ((AbstractColumnMapping) mapping).getConverter(); if (converter != null){ fieldValue = converter.convertDataValueToObjectValue(fieldValue, session); } ++elementIndex[0]; } else if (mapping.isObjectReferenceMapping()) { // what if mapping comes from derived ID. need to get the derived mapping. // get reference descriptor and extract pk from target cmp policy fieldValue = mapping.getReferenceDescriptor().getCMPPolicy().createPrimaryKeyInstanceFromPrimaryKeyValues(session, elementIndex, keyElements); } accessor.setValue(keyInstance, fieldValue); } }
Object aggregate = mapping.getRealAttributeValueFromObject(toWriteInto, session); if (aggregate == null) { aggregate = mapping.getReferenceDescriptor().getJavaClass().newInstance();
parentObj = parentMapping.getRealAttributeValueFromObject(obj, uow);
getMapping().getContainerPolicy().removeFrom(unwrappedValue, getMapping().getRealAttributeValueFromObject(oldParent, getSession()), getSession());