Search in sources :

Example 11 with XMLInverseReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping in project eclipselink by eclipse-ee4j.

the class DynamicTestProject method addPhoneNumberDescriptor.

private void addPhoneNumberDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClassName("org.eclipse.persistence.testing.oxm.dynamic.XPhoneNumber");
    XMLDirectMapping num = new XMLDirectMapping();
    num.setAttributeName("number");
    num.setXPath("text()");
    descriptor.addMapping(num);
    XMLInverseReferenceMapping owningEmployee = new XMLInverseReferenceMapping();
    owningEmployee.setReferenceClassName("org.eclipse.persistence.testing.oxm.dynamic.XEmployee");
    owningEmployee.setMappedBy("phoneNumbers");
    owningEmployee.setAttributeName("owningEmployee");
    owningEmployee.setSetMethodName("setOwningEmployee");
    owningEmployee.setGetMethodName("getOwningEmployee");
    descriptor.addMapping(owningEmployee);
    this.addDescriptor(descriptor);
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping)

Example 12 with XMLInverseReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping in project eclipselink by eclipse-ee4j.

the class EmployeeInvalidContainerAttributeProject method addAddressDescriptor.

public void addAddressDescriptor(boolean methodAccess) {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Address.class);
    XMLDirectMapping streetMapping = new XMLDirectMapping();
    streetMapping.setAttributeName("street");
    streetMapping.setXPath("street/text()");
    descriptor.addMapping(streetMapping);
    XMLDirectMapping cityMapping = new XMLDirectMapping();
    cityMapping.setAttributeName("city");
    cityMapping.setXPath("city/text()");
    descriptor.addMapping(cityMapping);
    XMLDirectMapping stateMapping = new XMLDirectMapping();
    stateMapping.setAttributeName("state");
    stateMapping.setXPath("state/text()");
    descriptor.addMapping(stateMapping);
    XMLDirectMapping countryMapping = new XMLDirectMapping();
    countryMapping.setAttributeName("country");
    countryMapping.setXPath("country/text()");
    descriptor.addMapping(countryMapping);
    XMLInverseReferenceMapping owningEmployee = new XMLInverseReferenceMapping();
    owningEmployee.setReferenceClass(Employee.class);
    owningEmployee.setMappedBy("address");
    owningEmployee.setAttributeName("invalidAttribute");
    if (methodAccess) {
        owningEmployee.setSetMethodName("invalidAttributeGet");
        owningEmployee.setGetMethodName("invalidAttributeSet");
    }
    descriptor.addMapping(owningEmployee);
    this.addDescriptor(descriptor);
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping)

Example 13 with XMLInverseReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping in project eclipselink by eclipse-ee4j.

the class JAXBValueStore method setDeclaredProperty.

/**
 * Set the value on the underlying POJO, unwrapping values as necessary.
 */
@Override
public void setDeclaredProperty(int propertyIndex, Object value) {
    SDOProperty declaredProperty = (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
    if (declaredProperty.getType().isChangeSummaryType()) {
        return;
    }
    Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);
    Object newValue = value;
    Object oldValue = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
    if (declaredProperty.getType().isDataType()) {
        if (!declaredProperty.isMany()) {
            AbstractSession session = ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
            XMLDirectMapping directMapping = (XMLDirectMapping) mapping;
            if (directMapping.hasConverter()) {
                newValue = directMapping.getConverter().convertDataValueToObjectValue(newValue, session);
            } else {
                CoreField field = mapping.getField();
                newValue = session.getDatasourcePlatform().getConversionManager().convertObject(newValue, descriptor.getObjectBuilder().getFieldClassification((XMLField) field));
            }
        }
        mapping.setAttributeValueInObject(entity, newValue);
    } else if (declaredProperty.isMany()) {
        // Get a ListWrapper and set it's current elements
        ListWrapper listWrapper = (ListWrapper) getDeclaredProperty(propertyIndex);
        listWrapper.addAll((List) newValue);
    } else {
        // OLD VALUE
        if (mapping.isAbstractCompositeObjectMapping()) {
            XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
            XMLInverseReferenceMapping inverseReferenceMapping = compositeMapping.getInverseReferenceMapping();
            if (oldValue != null && inverseReferenceMapping != null && inverseReferenceMapping.getAttributeAccessor() != null) {
                inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(oldValue, null);
            }
        }
        // NEW VALUE
        newValue = jaxbHelperContext.unwrap((DataObject) value);
        mapping.getAttributeAccessor().setAttributeValueInObject(entity, newValue);
        if (mapping.isAbstractCompositeObjectMapping()) {
            XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
            XMLInverseReferenceMapping inverseReferenceMapping = compositeMapping.getInverseReferenceMapping();
            if (value != null && inverseReferenceMapping != null && inverseReferenceMapping.getAttributeAccessor() != null) {
                inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(newValue, entity);
            }
        }
    }
}
Also used : XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) ContainerMapping(org.eclipse.persistence.mappings.ContainerMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) List(java.util.List) CoreField(org.eclipse.persistence.internal.core.helper.CoreField) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 14 with XMLInverseReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping in project eclipselink by eclipse-ee4j.

the class ReferenceAdapter method unmarshal.

/*
     * (non-Javadoc)
     *
     * @see
     * jakarta.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
     */
@SuppressWarnings("unchecked")
@Override
public T unmarshal(Object object) throws Exception {
    if (object == null) {
        return null;
    }
    PersistenceWeavedRest persistenceWeavedRest = null;
    Link link;
    if (object instanceof PersistenceWeavedRest) {
        persistenceWeavedRest = (PersistenceWeavedRest) object;
        link = persistenceWeavedRest._persistence_getHref();
    } else if (object instanceof Link) {
        link = (Link) object;
    } else {
        return null;
    }
    if (null == link || link.getHref() == null) {
        if (persistenceWeavedRest != null) {
            ClassDescriptor descriptor = context.getJAXBDescriptorForClass(persistenceWeavedRest.getClass());
            if (persistenceWeavedRest instanceof FetchGroupTracker && JpaHelper.getDatabaseSession(context.getEmf()).doesObjectExist(persistenceWeavedRest)) {
                if (context.doesExist(null, persistenceWeavedRest)) {
                    FetchGroup fetchGroup = new FetchGroup();
                    for (DatabaseMapping mapping : descriptor.getMappings()) {
                        if (!(mapping instanceof XMLInverseReferenceMapping)) {
                            fetchGroup.addAttribute(mapping.getAttributeName());
                        }
                    }
                    (new FetchGroupManager()).setObjectFetchGroup(persistenceWeavedRest, fetchGroup, null);
                }
            }
            return (T) persistenceWeavedRest;
        }
    }
    // Construct object from the href
    if ((link != null) && (link.getHref() != null)) {
        String uri = link.getHref().replace("\\/", "/");
        String entityType = uri.substring(uri.indexOf("/entity/"), uri.lastIndexOf('/'));
        entityType = entityType.substring(entityType.lastIndexOf('/') + 1);
        String entityId = uri.substring(uri.lastIndexOf('/') + 1);
        ClassDescriptor descriptor = context.getDescriptor(entityType);
        Object id = IdHelper.buildId(context, descriptor.getAlias(), entityId);
        T foundEntity = (T) getObjectById(entityType, id);
        return foundEntity;
    }
    return null;
}
Also used : FetchGroupTracker(org.eclipse.persistence.queries.FetchGroupTracker) FetchGroupManager(org.eclipse.persistence.descriptors.FetchGroupManager) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) PersistenceWeavedRest(org.eclipse.persistence.internal.jpa.rs.weaving.PersistenceWeavedRest) FetchGroup(org.eclipse.persistence.queries.FetchGroup) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) Link(org.eclipse.persistence.internal.jpa.rs.metadata.model.Link)

Example 15 with XMLInverseReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping in project eclipselink by eclipse-ee4j.

the class PersistenceContext method wrap.

/**
 * Make adjustments to an unmarshalled entity based on what is found in the weaved fields
 */
protected Object wrap(Object entity) {
    if ((entity != null) && (PersistenceWeavedRest.class.isAssignableFrom(entity.getClass()))) {
        if (!doesExist(null, entity)) {
            return entity;
        }
        ClassDescriptor descriptor = getJAXBDescriptorForClass(entity.getClass());
        if (entity instanceof FetchGroupTracker) {
            FetchGroup fetchGroup = new FetchGroup();
            for (DatabaseMapping mapping : descriptor.getMappings()) {
                if (!(mapping instanceof XMLInverseReferenceMapping)) {
                    fetchGroup.addAttribute(mapping.getAttributeName());
                }
            }
            (new FetchGroupManager()).setObjectFetchGroup(entity, fetchGroup, null);
            ((FetchGroupTracker) entity)._persistence_setSession(JpaHelper.getDatabaseSession(getEmf()));
        } else if (descriptor.hasRelationships()) {
            for (DatabaseMapping mapping : descriptor.getMappings()) {
                if (mapping instanceof XMLInverseReferenceMapping) {
                    // we require Fetch groups to handle relationships
                    JPARSLogger.error(getSessionLog(), "weaving_required_for_relationships", new Object[] {});
                    throw JPARSException.invalidConfiguration();
                }
            }
        }
    }
    return entity;
}
Also used : FetchGroupTracker(org.eclipse.persistence.queries.FetchGroupTracker) FetchGroupManager(org.eclipse.persistence.descriptors.FetchGroupManager) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) FetchGroup(org.eclipse.persistence.queries.FetchGroup) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Aggregations

XMLInverseReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping)15 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)9 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)9 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)7 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)4 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)3 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)3 DataObject (commonj.sdo.DataObject)2 FetchGroupManager (org.eclipse.persistence.descriptors.FetchGroupManager)2 PersistenceWeavedRest (org.eclipse.persistence.internal.jpa.rs.weaving.PersistenceWeavedRest)2 Mapping (org.eclipse.persistence.internal.oxm.mappings.Mapping)2 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)2 ContainerMapping (org.eclipse.persistence.mappings.ContainerMapping)2 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)2 FetchGroup (org.eclipse.persistence.queries.FetchGroup)2 FetchGroupTracker (org.eclipse.persistence.queries.FetchGroupTracker)2 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)2 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)2 List (java.util.List)1