Search in sources :

Example 1 with EISCompositeCollectionMapping

use of org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping in project eclipselink by eclipse-ee4j.

the class PersistenceContext method setRelationshipInfo.

private void setRelationshipInfo(Object entity) {
    if ((entity != null) && (entity instanceof PersistenceWeavedRest)) {
        ClassDescriptor descriptor = getServerSession().getClassDescriptor(entity.getClass());
        if (descriptor != null) {
            ((PersistenceWeavedRest) entity)._persistence_setRelationships(new ArrayList<>());
            for (DatabaseMapping mapping : descriptor.getMappings()) {
                if (mapping.isForeignReferenceMapping()) {
                    ForeignReferenceMapping frMapping = (ForeignReferenceMapping) mapping;
                    RelationshipInfo info = new RelationshipInfo();
                    info.setAttributeName(frMapping.getAttributeName());
                    info.setOwningEntity(entity);
                    info.setOwningEntityAlias(descriptor.getAlias());
                    info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity, (AbstractSession) getServerSession()));
                    ((PersistenceWeavedRest) entity)._persistence_getRelationships().add(info);
                } else if (mapping.isEISMapping()) {
                    if (mapping instanceof EISCompositeCollectionMapping) {
                        EISCompositeCollectionMapping eisMapping = (EISCompositeCollectionMapping) mapping;
                        RelationshipInfo info = new RelationshipInfo();
                        info.setAttributeName(eisMapping.getAttributeName());
                        info.setOwningEntity(entity);
                        info.setOwningEntityAlias(descriptor.getAlias());
                        info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity, (AbstractSession) getServerSession()));
                        ((PersistenceWeavedRest) entity)._persistence_getRelationships().add(info);
                    }
                }
            }
        }
    }
}
Also used : ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) RelationshipInfo(org.eclipse.persistence.internal.jpa.rs.weaving.RelationshipInfo) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) PersistenceWeavedRest(org.eclipse.persistence.internal.jpa.rs.weaving.PersistenceWeavedRest) EISCompositeCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 2 with EISCompositeCollectionMapping

use of org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping in project eclipselink by eclipse-ee4j.

the class DynamicXMLMetadataSource method createJAXBProperty.

/**
 * Create a JAXB property for a particular mapping.
 * This will only create JAXBProperties for mappings that are virtual - either because their
 * parent object is a dynamic class, or because the owning static class has virtual properties
 */
private JAXBElement<XmlElement> createJAXBProperty(DatabaseMapping mapping, ObjectFactory objectFactory, JavaType owningType, boolean isDynamic) {
    if (!mapping.getAttributeAccessor().isVirtualAttributeAccessor() && !isDynamic) {
        return null;
    }
    XmlElement xmlElement = new XmlElement();
    xmlElement.setJavaAttribute(mapping.getAttributeName());
    if (mapping.isObjectReferenceMapping()) {
        xmlElement.setType(((ObjectReferenceMapping) mapping).getReferenceClassName());
    } else if (mapping.isCollectionMapping()) {
        if (mapping.isEISMapping()) {
            // It will be fine for simple collections
            if (mapping instanceof EISCompositeDirectCollectionMapping) {
                xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
            } else if (mapping instanceof EISCompositeCollectionMapping) {
                xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
                xmlElement.setType(((EISCompositeCollectionMapping) mapping).getReferenceClassName());
            }
        } else {
            xmlElement.setType(((CollectionMapping) mapping).getReferenceClassName());
            xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
        }
    } else {
        xmlElement.setType(mapping.getAttributeClassification().getName());
    }
    if (mapping.getAttributeAccessor().isVirtualAttributeAccessor()) {
        VirtualAttributeAccessor jpaAccessor = (VirtualAttributeAccessor) mapping.getAttributeAccessor();
        if (owningType.getXmlVirtualAccessMethods() == null) {
            XmlVirtualAccessMethods virtualAccessMethods = new XmlVirtualAccessMethods();
            virtualAccessMethods.setGetMethod(jpaAccessor.getGetMethodName());
            virtualAccessMethods.setSetMethod(jpaAccessor.getSetMethodName());
            owningType.setXmlVirtualAccessMethods(virtualAccessMethods);
        } else if (!owningType.getXmlVirtualAccessMethods().getGetMethod().equals(jpaAccessor.getGetMethodName())) {
            XmlAccessMethods accessMethods = new XmlAccessMethods();
            accessMethods.setGetMethod(jpaAccessor.getGetMethodName());
            accessMethods.setSetMethod(jpaAccessor.getSetMethodName());
            xmlElement.setXmlAccessMethods(accessMethods);
        }
    }
    return objectFactory.createXmlElement(xmlElement);
}
Also used : EISCompositeDirectCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeDirectCollectionMapping) XmlAccessMethods(org.eclipse.persistence.jaxb.xmlmodel.XmlAccessMethods) VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) EISCompositeCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping) EISCompositeCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping) EISCompositeDirectCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeDirectCollectionMapping) XmlVirtualAccessMethods(org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethods)

Example 3 with EISCompositeCollectionMapping

use of org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping in project eclipselink by eclipse-ee4j.

the class NestedForeignKeyProject method getTeamDescriptor.

private EISDescriptor getTeamDescriptor() {
    EISDescriptor descriptor = new EISDescriptor();
    descriptor.setJavaClass(Team.class);
    descriptor.setDataTypeName("team");
    descriptor.setPrimaryKeyFieldName("@id");
    EISDirectMapping idMapping = new EISDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    descriptor.addMapping(idMapping);
    EISCompositeCollectionMapping employeesMapping = new EISCompositeCollectionMapping();
    employeesMapping.setAttributeName("employees");
    employeesMapping.useCollectionClass(java.util.Vector.class);
    employeesMapping.setReferenceClass(Employee.class);
    employeesMapping.setXPath("employee");
    descriptor.addMapping(employeesMapping);
    // Insert
    XQueryInteraction insertCall = new XQueryInteraction();
    insertCall.setFunctionName("insert");
    insertCall.setProperty("fileName", "team.xml");
    insertCall.setXQueryString("team");
    descriptor.getQueryManager().setInsertCall(insertCall);
    // Read object
    XQueryInteraction readObjectCall = new XQueryInteraction();
    readObjectCall.setFunctionName("read");
    readObjectCall.setProperty("fileName", "team.xml");
    readObjectCall.setXQueryString("team[@id='#@id']");
    readObjectCall.setOutputResultPath("result");
    descriptor.getQueryManager().setReadObjectCall(readObjectCall);
    // Read all
    XQueryInteraction readAllCall = new XQueryInteraction();
    readAllCall.setFunctionName("read-all");
    readAllCall.setProperty("fileName", "team.xml");
    readAllCall.setXQueryString("team");
    readAllCall.setOutputResultPath("result");
    descriptor.getQueryManager().setReadAllCall(readAllCall);
    // Delete
    XQueryInteraction deleteCall = new XQueryInteraction();
    deleteCall.setFunctionName("delete");
    deleteCall.setProperty("fileName", "team.xml");
    deleteCall.setXQueryString("team[@id='#@id']");
    descriptor.getQueryManager().setDeleteCall(deleteCall);
    // Update
    XQueryInteraction updateCall = new XQueryInteraction();
    updateCall.setFunctionName("update");
    updateCall.setProperty("fileName", "team.xml");
    updateCall.setXQueryString("team[@id='#@id']");
    descriptor.getQueryManager().setUpdateCall(updateCall);
    return descriptor;
}
Also used : EISCompositeCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping) XQueryInteraction(org.eclipse.persistence.eis.interactions.XQueryInteraction) EISDescriptor(org.eclipse.persistence.eis.EISDescriptor) EISDirectMapping(org.eclipse.persistence.eis.mappings.EISDirectMapping)

Example 4 with EISCompositeCollectionMapping

use of org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping in project eclipselink by eclipse-ee4j.

the class OwnedToExternalRootProject method getTeamDescriptor.

private EISDescriptor getTeamDescriptor() {
    EISDescriptor descriptor = new EISDescriptor();
    descriptor.setJavaClass(Team.class);
    descriptor.setDataTypeName("team");
    descriptor.setPrimaryKeyFieldName("@id");
    EISDirectMapping idMapping = new EISDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    descriptor.addMapping(idMapping);
    EISCompositeCollectionMapping employeesMapping = new EISCompositeCollectionMapping();
    employeesMapping.setAttributeName("employees");
    employeesMapping.useCollectionClass(java.util.Vector.class);
    employeesMapping.setReferenceClass(Employee.class);
    employeesMapping.setXPath("employee");
    descriptor.addMapping(employeesMapping);
    // Insert
    XQueryInteraction insertCall = new XQueryInteraction();
    insertCall.setFunctionName("insert");
    insertCall.setProperty("fileName", "team.xml");
    insertCall.setXQueryString("team");
    descriptor.getQueryManager().setInsertCall(insertCall);
    // Read object
    XQueryInteraction readObjectCall = new XQueryInteraction();
    readObjectCall.setFunctionName("read");
    readObjectCall.setProperty("fileName", "team.xml");
    readObjectCall.setXQueryString("team[@id='#@id']");
    readObjectCall.setOutputResultPath("result");
    descriptor.getQueryManager().setReadObjectCall(readObjectCall);
    // Read all
    XQueryInteraction readAllCall = new XQueryInteraction();
    readAllCall.setFunctionName("read-all");
    readAllCall.setProperty("fileName", "team.xml");
    readAllCall.setXQueryString("team");
    readAllCall.setOutputResultPath("result");
    descriptor.getQueryManager().setReadAllCall(readAllCall);
    // Delete
    XQueryInteraction deleteCall = new XQueryInteraction();
    deleteCall.setFunctionName("delete");
    deleteCall.setProperty("fileName", "team.xml");
    deleteCall.setXQueryString("team[@id='#@id']");
    descriptor.getQueryManager().setDeleteCall(deleteCall);
    // Update
    XQueryInteraction updateCall = new XQueryInteraction();
    updateCall.setFunctionName("update");
    updateCall.setProperty("fileName", "team.xml");
    updateCall.setXQueryString("team[@id='#@id']");
    descriptor.getQueryManager().setUpdateCall(updateCall);
    return descriptor;
}
Also used : EISCompositeCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping) XQueryInteraction(org.eclipse.persistence.eis.interactions.XQueryInteraction) EISDescriptor(org.eclipse.persistence.eis.EISDescriptor) EISDirectMapping(org.eclipse.persistence.eis.mappings.EISDirectMapping)

Example 5 with EISCompositeCollectionMapping

use of org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping in project eclipselink by eclipse-ee4j.

the class NestedOwnedToExternalRootProject method getCompanyDescriptor.

private EISDescriptor getCompanyDescriptor() {
    EISDescriptor descriptor = new EISDescriptor();
    descriptor.setJavaClass(Company.class);
    descriptor.setDataTypeName("company");
    descriptor.setPrimaryKeyFieldName("name/text()");
    EISDirectMapping nameMapping = new EISDirectMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setXPath("name/text()");
    descriptor.addMapping(nameMapping);
    EISCompositeCollectionMapping departmentsMapping = new EISCompositeCollectionMapping();
    departmentsMapping.setAttributeName("departments");
    departmentsMapping.useCollectionClass(java.util.Vector.class);
    departmentsMapping.setReferenceClass(Department.class);
    departmentsMapping.setXPath("department");
    descriptor.addMapping(departmentsMapping);
    // Insert
    XQueryInteraction insertCall = new XQueryInteraction();
    insertCall.setFunctionName("insert");
    insertCall.setProperty("fileName", "company.xml");
    insertCall.setXQueryString("company");
    descriptor.getQueryManager().setInsertCall(insertCall);
    // Read object
    XQueryInteraction readObjectCall = new XQueryInteraction();
    readObjectCall.setFunctionName("read");
    readObjectCall.setProperty("fileName", "company.xml");
    readObjectCall.setXQueryString("company[name/text()='#name/text()']");
    readObjectCall.setOutputResultPath("result");
    descriptor.getQueryManager().setReadObjectCall(readObjectCall);
    // Read all
    XQueryInteraction readAllCall = new XQueryInteraction();
    readAllCall.setFunctionName("read-all");
    readAllCall.setProperty("fileName", "company.xml");
    readAllCall.setXQueryString("company");
    readAllCall.setOutputResultPath("result");
    descriptor.getQueryManager().setReadAllCall(readAllCall);
    // Delete
    XQueryInteraction deleteCall = new XQueryInteraction();
    deleteCall.setFunctionName("delete");
    deleteCall.setProperty("fileName", "company.xml");
    deleteCall.setXQueryString("company[name/text()='#name/text()']");
    descriptor.getQueryManager().setDeleteCall(deleteCall);
    // Update
    XQueryInteraction updateCall = new XQueryInteraction();
    updateCall.setFunctionName("update");
    updateCall.setProperty("fileName", "company.xml");
    updateCall.setXQueryString("company[name/text()='#name/text()']");
    descriptor.getQueryManager().setUpdateCall(updateCall);
    return descriptor;
}
Also used : EISCompositeCollectionMapping(org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping) XQueryInteraction(org.eclipse.persistence.eis.interactions.XQueryInteraction) EISDescriptor(org.eclipse.persistence.eis.EISDescriptor) EISDirectMapping(org.eclipse.persistence.eis.mappings.EISDirectMapping)

Aggregations

EISCompositeCollectionMapping (org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping)27 EISDescriptor (org.eclipse.persistence.eis.EISDescriptor)24 EISDirectMapping (org.eclipse.persistence.eis.mappings.EISDirectMapping)24 XQueryInteraction (org.eclipse.persistence.eis.interactions.XQueryInteraction)17 CollectionMapping (org.eclipse.persistence.mappings.CollectionMapping)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 EISCompositeDirectCollectionMapping (org.eclipse.persistence.eis.mappings.EISCompositeDirectCollectionMapping)1 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)1 Attribute (org.eclipse.persistence.internal.jpa.rs.metadata.model.Attribute)1 PersistenceWeavedRest (org.eclipse.persistence.internal.jpa.rs.weaving.PersistenceWeavedRest)1 RelationshipInfo (org.eclipse.persistence.internal.jpa.rs.weaving.RelationshipInfo)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 XmlAccessMethods (org.eclipse.persistence.jaxb.xmlmodel.XmlAccessMethods)1 XmlElement (org.eclipse.persistence.jaxb.xmlmodel.XmlElement)1 XmlVirtualAccessMethods (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethods)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)1