Search in sources :

Example 1 with EISOneToManyMapping

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

the class ManyToManyAccessor method process.

/**
 * INTERNAL:
 * Process a many to many metadata accessor into a EclipseLink
 * ManyToManyMapping.
 */
@Override
public void process() {
    super.process();
    // Create a M-M mapping and process common collection mapping metadata.
    // Allow for different descriptor types (EIS) to create different mapping types.
    CollectionMapping mapping = getDescriptor().getClassDescriptor().newManyToManyMapping();
    process(mapping);
    if (hasMappedBy()) {
        // We are processing the non-owning side of a M-M relationship. Get
        // the owning mapping from the reference descriptor metadata and
        // process the keys from it.
        DatabaseMapping owningMapping = getOwningMapping();
        if (owningMapping.isManyToManyMapping()) {
            ManyToManyMapping ownerMapping = (ManyToManyMapping) owningMapping;
            processMappedByRelationTable(ownerMapping.getRelationTableMechanism(), ((ManyToManyMapping) mapping).getRelationTableMechanism());
            // Set the mapping read-only.
            mapping.setIsReadOnly(true);
        } else {
            // Invalid owning mapping type, throw an exception.
            throw ValidationException.invalidMapping(getJavaClass(), getReferenceClass());
        }
    } else if (mapping instanceof ManyToManyMapping) {
        // Processing the owning side of a M-M, process the join table.
        processJoinTable(mapping, ((ManyToManyMapping) mapping).getRelationTableMechanism(), getJoinTableMetadata());
    } else if (mapping instanceof EISOneToManyMapping) {
        processEISOneToManyMapping((EISOneToManyMapping) mapping);
    }
}
Also used : ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) EISOneToManyMapping(org.eclipse.persistence.eis.mappings.EISOneToManyMapping) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping)

Example 2 with EISOneToManyMapping

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

the class OneToManyAccessor method processManyToManyMapping.

/**
 * INTERNAL:
 * Process an many to many mapping for this accessor since a join table
 * was specified.
 */
protected void processManyToManyMapping() {
    // Create a M-M mapping and process common collection mapping metadata
    // first followed by specific metadata.
    // Allow for different descriptor types (EIS) to create different mapping types.
    CollectionMapping mapping = getDescriptor().getClassDescriptor().newManyToManyMapping();
    process(mapping);
    if (mapping instanceof ManyToManyMapping) {
        // 266912: If this 1:n accessor is different than the n:n mapping - track this
        ((ManyToManyMapping) mapping).setDefinedAsOneToManyMapping(true);
        // Process the JoinTable metadata.
        processJoinTable(mapping, ((ManyToManyMapping) mapping).getRelationTableMechanism(), getJoinTableMetadata());
    } else if (mapping instanceof EISOneToManyMapping) {
        processEISOneToManyMapping((EISOneToManyMapping) mapping);
    }
}
Also used : ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) EISOneToManyMapping(org.eclipse.persistence.eis.mappings.EISOneToManyMapping) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping)

Example 3 with EISOneToManyMapping

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

the class IndirectionProject method getEmployeeDescriptor.

private EISDescriptor getEmployeeDescriptor() {
    EISDescriptor descriptor = new EISDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDataTypeName("employee");
    descriptor.setPrimaryKeyFieldName("first-name/text()");
    EISDirectMapping firstNameMapping = new EISDirectMapping();
    firstNameMapping.setAttributeName("firstName");
    firstNameMapping.setXPath("first-name/text()");
    descriptor.addMapping(firstNameMapping);
    EISDirectMapping lastNameMapping = new EISDirectMapping();
    lastNameMapping.setAttributeName("lastName");
    lastNameMapping.setXPath("last-name/text()");
    descriptor.addMapping(lastNameMapping);
    EISOneToManyMapping projectMapping = new EISOneToManyMapping();
    projectMapping.setAttributeName("projects");
    projectMapping.setReferenceClass(Project.class);
    projectMapping.setForeignKeyGroupingElement("project");
    projectMapping.setIsForeignKeyRelationship(true);
    XQueryInteraction projectInteraction = new XQueryInteraction();
    projectInteraction.setFunctionName("read-projects");
    projectInteraction.setProperty("fileName", "project.xml");
    projectInteraction.setXQueryString("project[@id='#project-id/text()' and name/text()='#project-name/text()']");
    projectInteraction.setOutputResultPath("result");
    projectMapping.setSelectionCall(projectInteraction);
    descriptor.getQueryManager().setReadAllQuery(new ReadAllQuery(projectInteraction));
    projectMapping.addForeignKeyFieldName("project-id/text()", "@id");
    projectMapping.addForeignKeyFieldName("project-name/text()", "name/text()");
    descriptor.addMapping(projectMapping);
    // Insert
    XQueryInteraction insertCall = new XQueryInteraction();
    insertCall.setFunctionName("insert");
    insertCall.setProperty("fileName", "employee.xml");
    insertCall.setXQueryString("employee");
    descriptor.getQueryManager().setInsertCall(insertCall);
    // Read object
    XQueryInteraction readObjectCall = new XQueryInteraction();
    readObjectCall.setFunctionName("read");
    readObjectCall.setProperty("fileName", "employee.xml");
    readObjectCall.setXQueryString("employee[first-name='#first-name/text()']");
    readObjectCall.setOutputResultPath("result");
    descriptor.getQueryManager().setReadObjectCall(readObjectCall);
    // Read all
    XQueryInteraction readAllCall = new XQueryInteraction();
    readAllCall.setFunctionName("read-all");
    readAllCall.setProperty("fileName", "employee.xml");
    readAllCall.setXQueryString("employee");
    readAllCall.setOutputResultPath("result");
    descriptor.getQueryManager().setReadAllCall(readAllCall);
    // Delete
    XQueryInteraction deleteCall = new XQueryInteraction();
    deleteCall.setFunctionName("delete");
    deleteCall.setProperty("fileName", "employee.xml");
    deleteCall.setXQueryString("employee[first-name='#first-name/text()']");
    descriptor.getQueryManager().setDeleteCall(deleteCall);
    // Update
    XQueryInteraction updateCall = new XQueryInteraction();
    updateCall.setFunctionName("update");
    updateCall.setProperty("fileName", "employee.xml");
    updateCall.setXQueryString("employee[first-name='#first-name/text()']");
    descriptor.getQueryManager().setUpdateCall(updateCall);
    return descriptor;
}
Also used : ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) XQueryInteraction(org.eclipse.persistence.eis.interactions.XQueryInteraction) EISDescriptor(org.eclipse.persistence.eis.EISDescriptor) EISDirectMapping(org.eclipse.persistence.eis.mappings.EISDirectMapping) EISOneToManyMapping(org.eclipse.persistence.eis.mappings.EISOneToManyMapping)

Example 4 with EISOneToManyMapping

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

the class RootToRootProject method getEmployeeDescriptor.

private EISDescriptor getEmployeeDescriptor() {
    EISDescriptor descriptor = new EISDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDataTypeName("employee");
    descriptor.setPrimaryKeyFieldName("first-name/text()");
    EISDirectMapping firstNameMapping = new EISDirectMapping();
    firstNameMapping.setAttributeName("firstName");
    firstNameMapping.setXPath("first-name/text()");
    descriptor.addMapping(firstNameMapping);
    /*
        EISObjectCollectionMapping projectMapping = new EISObjectCollectionMapping();
      projectMapping.setAttributeName("projects");
    projectMapping.setReferenceClass(Project.class);
        projectMapping.setFieldName("project");
    projectMapping.dontUseIndirection();
        XQueryInteraction projectInteraction = new XQueryInteraction();
    projectInteraction.setFunctionName("read-projects");
    projectInteraction.setProperty("fileName", "project.xml");
    projectInteraction.setXQueryString("project[@id='#project-id']");
    projectInteraction.setOutputResultPath("result");
    projectMapping.setSelectionCall(projectInteraction);
        descriptor.getQueryManager().setReadAllQuery(new ReadAllQuery(projectInteraction));
        projectMapping.addSourceForeignKeyFieldName("project-id", "@id");
*/
    EISOneToManyMapping projectMapping = new EISOneToManyMapping();
    projectMapping.setAttributeName("projects");
    projectMapping.setReferenceClass(Project.class);
    projectMapping.setForeignKeyGroupingElement("job/task/project");
    projectMapping.setIsForeignKeyRelationship(true);
    projectMapping.dontUseIndirection();
    XQueryInteraction projectInteraction = new XQueryInteraction();
    projectInteraction.setFunctionName("read-projects");
    projectInteraction.setProperty("fileName", "project.xml");
    projectInteraction.setXQueryString("project[@id='#project-id/text()']");
    projectInteraction.setOutputResultPath("result");
    projectMapping.setSelectionCall(projectInteraction);
    // descriptor.getQueryManager().setReadAllQuery(new ReadAllQuery(projectInteraction));
    // projectMapping.addSourceForeignKeyFieldName("project-id", "@id");
    projectMapping.addForeignKeyFieldName("project-id/text()", "@id");
    descriptor.addMapping(projectMapping);
    // Insert
    XQueryInteraction insertCall = new XQueryInteraction();
    insertCall.setFunctionName("insert");
    insertCall.setProperty("fileName", "employee.xml");
    insertCall.setXQueryString("employee");
    descriptor.getQueryManager().setInsertCall(insertCall);
    // Read object
    XQueryInteraction readObjectCall = new XQueryInteraction();
    readObjectCall.setFunctionName("read");
    readObjectCall.setProperty("fileName", "employee.xml");
    readObjectCall.setXQueryString("employee[first-name='#first-name/text()']");
    readObjectCall.setOutputResultPath("result");
    descriptor.getQueryManager().setReadObjectCall(readObjectCall);
    // Read all
    XQueryInteraction readAllCall = new XQueryInteraction();
    readAllCall.setFunctionName("read-all");
    readAllCall.setProperty("fileName", "employee.xml");
    readAllCall.setXQueryString("employee");
    readAllCall.setOutputResultPath("result");
    descriptor.getQueryManager().setReadAllCall(readAllCall);
    // Delete
    XQueryInteraction deleteCall = new XQueryInteraction();
    deleteCall.setFunctionName("delete");
    deleteCall.setProperty("fileName", "employee.xml");
    deleteCall.setXQueryString("employee[first-name='#first-name/text()']");
    descriptor.getQueryManager().setDeleteCall(deleteCall);
    // Update
    XQueryInteraction updateCall = new XQueryInteraction();
    updateCall.setFunctionName("update");
    updateCall.setProperty("fileName", "employee.xml");
    updateCall.setXQueryString("employee[first-name='#first-name/text()']");
    descriptor.getQueryManager().setUpdateCall(updateCall);
    return descriptor;
}
Also used : XQueryInteraction(org.eclipse.persistence.eis.interactions.XQueryInteraction) EISDescriptor(org.eclipse.persistence.eis.EISDescriptor) EISDirectMapping(org.eclipse.persistence.eis.mappings.EISDirectMapping) EISOneToManyMapping(org.eclipse.persistence.eis.mappings.EISOneToManyMapping)

Example 5 with EISOneToManyMapping

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

the class NestedOwnedToExternalRootProject method getEmployeeDescriptor.

private EISDescriptor getEmployeeDescriptor() {
    EISDescriptor descriptor = new EISDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDataTypeName("employee");
    descriptor.descriptorIsAggregate();
    EISDirectMapping firstNameMapping = new EISDirectMapping();
    firstNameMapping.setAttributeName("firstName");
    firstNameMapping.setXPath("first-name/text()");
    descriptor.addMapping(firstNameMapping);
    EISOneToManyMapping projectMapping = new EISOneToManyMapping();
    projectMapping.setReferenceClass(Project.class);
    projectMapping.setAttributeName("projects");
    projectMapping.setForeignKeyGroupingElement("project");
    projectMapping.dontUseIndirection();
    XQueryInteraction projectInteraction = new XQueryInteraction();
    projectInteraction.setFunctionName("read-projects");
    projectInteraction.setProperty("fileName", "project.xml");
    projectInteraction.setXQueryString("project[@id='#project-id/text()']");
    projectInteraction.setOutputResultPath("result");
    projectMapping.setSelectionCall(projectInteraction);
    projectMapping.addForeignKeyFieldName("project-id/text()", "@id");
    descriptor.addMapping(projectMapping);
    return descriptor;
}
Also used : XQueryInteraction(org.eclipse.persistence.eis.interactions.XQueryInteraction) EISDescriptor(org.eclipse.persistence.eis.EISDescriptor) EISDirectMapping(org.eclipse.persistence.eis.mappings.EISDirectMapping) EISOneToManyMapping(org.eclipse.persistence.eis.mappings.EISOneToManyMapping)

Aggregations

EISOneToManyMapping (org.eclipse.persistence.eis.mappings.EISOneToManyMapping)29 EISDescriptor (org.eclipse.persistence.eis.EISDescriptor)27 XQueryInteraction (org.eclipse.persistence.eis.interactions.XQueryInteraction)27 EISDirectMapping (org.eclipse.persistence.eis.mappings.EISDirectMapping)27 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)9 CollectionMapping (org.eclipse.persistence.mappings.CollectionMapping)2 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)2 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)1