Search in sources :

Example 1 with NoIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.NoIndirectionPolicy in project eclipselink by eclipse-ee4j.

the class ObjectPersistenceRuntimeXMLProject method buildManyToManyMappingMappingDescriptor.

protected ClassDescriptor buildManyToManyMappingMappingDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(ManyToManyMapping.class);
    descriptor.getInheritancePolicy().setParentClass(CollectionMapping.class);
    XMLDirectMapping relationTableMapping = new XMLDirectMapping();
    relationTableMapping.setAttributeName("relationTableName");
    // CR#2407 Call getRelationTableQualifiedName that includes table qualifier.
    relationTableMapping.setGetMethodName("getRelationTableQualifiedName");
    relationTableMapping.setSetMethodName("setRelationTableName");
    relationTableMapping.setXPath(getSecondaryNamespaceXPath() + "relation-table/text()");
    descriptor.addMapping(relationTableMapping);
    XMLCompositeCollectionMapping sourceToRelationKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
    sourceToRelationKeyFieldAssociationsMapping.setReferenceClass(Association.class);
    // Handle translation of foreign key associations to hashtables.
    sourceToRelationKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            List<DatabaseField> sourceFields = ((ManyToManyMapping) object).getSourceKeyFields();
            List<DatabaseField> relationFields = ((ManyToManyMapping) object).getSourceRelationKeyFields();
            List<Association> associations = new ArrayList<>(sourceFields.size());
            for (int index = 0; index < sourceFields.size(); index++) {
                associations.add(new Association(relationFields.get(index), sourceFields.get(index)));
            }
            return associations;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            ManyToManyMapping mapping = (ManyToManyMapping) object;
            @SuppressWarnings({ "unchecked" }) List<Association> associations = (List<Association>) value;
            mapping.setSourceKeyFields(NonSynchronizedVector.newInstance(associations.size()));
            mapping.setSourceRelationKeyFields(NonSynchronizedVector.newInstance(associations.size()));
            Iterator<Association> iterator = associations.iterator();
            while (iterator.hasNext()) {
                Association association = iterator.next();
                mapping.getSourceKeyFields().add((DatabaseField) association.getValue());
                mapping.getSourceRelationKeyFields().add((DatabaseField) association.getKey());
            }
        }
    });
    sourceToRelationKeyFieldAssociationsMapping.setAttributeName("sourceToRelationKeyFieldAssociationsMapping");
    sourceToRelationKeyFieldAssociationsMapping.setXPath(getSecondaryNamespaceXPath() + "source-relation-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
    descriptor.addMapping(sourceToRelationKeyFieldAssociationsMapping);
    XMLCompositeCollectionMapping targetToRelationKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
    targetToRelationKeyFieldAssociationsMapping.setReferenceClass(Association.class);
    // Handle translation of foreign key associations to hashtables.
    targetToRelationKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            List<DatabaseField> targetFields = ((ManyToManyMapping) object).getTargetKeyFields();
            List<DatabaseField> relationFields = ((ManyToManyMapping) object).getTargetRelationKeyFields();
            List<Association> associations = new ArrayList<>(targetFields.size());
            for (int index = 0; index < targetFields.size(); index++) {
                associations.add(new Association(relationFields.get(index), targetFields.get(index)));
            }
            return associations;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            ManyToManyMapping mapping = (ManyToManyMapping) object;
            @SuppressWarnings({ "unchecked" }) List<Association> associations = (List<Association>) value;
            mapping.setTargetKeyFields(NonSynchronizedVector.newInstance(associations.size()));
            mapping.setTargetRelationKeyFields(NonSynchronizedVector.newInstance(associations.size()));
            Iterator<Association> iterator = associations.iterator();
            while (iterator.hasNext()) {
                Association association = iterator.next();
                mapping.getTargetKeyFields().add((DatabaseField) association.getValue());
                mapping.getTargetRelationKeyFields().add((DatabaseField) association.getKey());
            }
        }
    });
    targetToRelationKeyFieldAssociationsMapping.setAttributeName("targetToRelationKeyFieldAssociations");
    targetToRelationKeyFieldAssociationsMapping.setXPath(getSecondaryNamespaceXPath() + "target-relation-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
    descriptor.addMapping(targetToRelationKeyFieldAssociationsMapping);
    XMLDirectMapping relationshipPartnerAttributeNameMapping = new XMLDirectMapping();
    relationshipPartnerAttributeNameMapping.setAttributeName("relationshipPartnerAttributeName");
    relationshipPartnerAttributeNameMapping.setGetMethodName("getRelationshipPartnerAttributeName");
    relationshipPartnerAttributeNameMapping.setSetMethodName("setRelationshipPartnerAttributeName");
    relationshipPartnerAttributeNameMapping.setXPath(getPrimaryNamespaceXPath() + "bidirectional-target-attribute/text()");
    descriptor.addMapping(relationshipPartnerAttributeNameMapping);
    XMLDirectMapping usesBatchReadingMapping = new XMLDirectMapping();
    usesBatchReadingMapping.setAttributeName("usesBatchReading");
    usesBatchReadingMapping.setGetMethodName("shouldUseBatchReading");
    usesBatchReadingMapping.setSetMethodName("setUsesBatchReading");
    usesBatchReadingMapping.setXPath(getPrimaryNamespaceXPath() + "batch-reading/text()");
    usesBatchReadingMapping.setNullValue(Boolean.FALSE);
    descriptor.addMapping(usesBatchReadingMapping);
    XMLCompositeObjectMapping containerPolicyMapping = new XMLCompositeObjectMapping();
    containerPolicyMapping.setAttributeName("collectionPolicy");
    containerPolicyMapping.setGetMethodName("getContainerPolicy");
    containerPolicyMapping.setSetMethodName("setContainerPolicy");
    containerPolicyMapping.setReferenceClass(ContainerPolicy.class);
    containerPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "container");
    descriptor.addMapping(containerPolicyMapping);
    XMLCompositeObjectMapping indirectionPolicyMapping = new XMLCompositeObjectMapping();
    indirectionPolicyMapping.setReferenceClass(IndirectionPolicy.class);
    // Handle translation of NoIndirectionPolicy -> null.
    indirectionPolicyMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            IndirectionPolicy policy = ((ForeignReferenceMapping) object).getIndirectionPolicy();
            if (policy instanceof NoIndirectionPolicy) {
                return null;
            }
            return policy;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            IndirectionPolicy policy = (IndirectionPolicy) value;
            if (value == null) {
                policy = new NoIndirectionPolicy();
            }
            ((ForeignReferenceMapping) object).setIndirectionPolicy(policy);
        }
    });
    indirectionPolicyMapping.setAttributeName("indirectionPolicy");
    indirectionPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "indirection");
    descriptor.addMapping(indirectionPolicyMapping);
    XMLCompositeObjectMapping selectionQueryMapping = new XMLCompositeObjectMapping();
    selectionQueryMapping.setAttributeName("selectionQuery");
    selectionQueryMapping.setGetMethodName("getSelectionQuery");
    selectionQueryMapping.setSetMethodName("setSelectionQuery");
    selectionQueryMapping.setReferenceClass(ReadQuery.class);
    selectionQueryMapping.setXPath(getPrimaryNamespaceXPath() + "selection-query");
    descriptor.addMapping(selectionQueryMapping);
    XMLCompositeObjectMapping insertQueryMapping = new XMLCompositeObjectMapping();
    insertQueryMapping.setAttributeName("insertQuery");
    insertQueryMapping.setGetMethodName("getInsertQuery");
    insertQueryMapping.setSetMethodName("setInsertQuery");
    insertQueryMapping.setReferenceClass(DataModifyQuery.class);
    insertQueryMapping.setXPath(getPrimaryNamespaceXPath() + "insert-query");
    descriptor.addMapping(insertQueryMapping);
    XMLCompositeObjectMapping deleteQueryMapping = new XMLCompositeObjectMapping();
    deleteQueryMapping.setAttributeName("deleteQuery");
    deleteQueryMapping.setGetMethodName("getDeleteQuery");
    deleteQueryMapping.setSetMethodName("setDeleteQuery");
    deleteQueryMapping.setReferenceClass(DataModifyQuery.class);
    deleteQueryMapping.setXPath(getPrimaryNamespaceXPath() + "delete-query");
    descriptor.addMapping(deleteQueryMapping);
    XMLCompositeObjectMapping deleteAllQueryMapping = new XMLCompositeObjectMapping();
    deleteAllQueryMapping.setAttributeName("deleteAllQuery");
    deleteAllQueryMapping.setGetMethodName("getDeleteAllQuery");
    deleteAllQueryMapping.setSetMethodName("setDeleteAllQuery");
    deleteAllQueryMapping.setReferenceClass(DataModifyQuery.class);
    deleteAllQueryMapping.setXPath(getPrimaryNamespaceXPath() + "delete-all-query");
    descriptor.addMapping(deleteAllQueryMapping);
    XMLCompositeObjectMapping historyPolicyMapping = new XMLCompositeObjectMapping();
    historyPolicyMapping.setAttributeName("historyPolicy");
    historyPolicyMapping.setGetMethodName("getHistoryPolicy");
    historyPolicyMapping.setSetMethodName("setHistoryPolicy");
    historyPolicyMapping.setReferenceClass(HistoryPolicy.class);
    historyPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "history-policy");
    descriptor.addMapping(historyPolicyMapping);
    return descriptor;
}
Also used : ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) ProxyIndirectionPolicy(org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy) IndirectionPolicy(org.eclipse.persistence.internal.indirection.IndirectionPolicy) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) InMemoryQueryIndirectionPolicy(org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) Association(org.eclipse.persistence.mappings.Association) PropertyAssociation(org.eclipse.persistence.mappings.PropertyAssociation) TypedAssociation(org.eclipse.persistence.mappings.TypedAssociation) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 2 with NoIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.NoIndirectionPolicy in project eclipselink by eclipse-ee4j.

the class EISObjectPersistenceXMLProject method buildEISOneToManyMappingDescriptor.

protected ClassDescriptor buildEISOneToManyMappingDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(EISOneToManyMapping.class);
    XMLCompositeCollectionMapping foreignKeyFieldNamesMapping = new XMLCompositeCollectionMapping();
    foreignKeyFieldNamesMapping.setAttributeName("sourceForeignKeyFields");
    foreignKeyFieldNamesMapping.useCollectionClass(java.util.ArrayList.class);
    foreignKeyFieldNamesMapping.setGetMethodName("getSourceForeignKeyFields");
    foreignKeyFieldNamesMapping.setSetMethodName("setSourceForeignKeyFields");
    foreignKeyFieldNamesMapping.setXPath(getPrimaryNamespaceXPath() + "source-foreign-key-fields/" + getPrimaryNamespaceXPath() + "field");
    foreignKeyFieldNamesMapping.setReferenceClass(DatabaseField.class);
    descriptor.addMapping(foreignKeyFieldNamesMapping);
    XMLCompositeCollectionMapping targetForeignKeyFieldNamesMapping = new XMLCompositeCollectionMapping();
    targetForeignKeyFieldNamesMapping.setAttributeName("targetForeignKeyFields");
    targetForeignKeyFieldNamesMapping.useCollectionClass(java.util.ArrayList.class);
    targetForeignKeyFieldNamesMapping.setGetMethodName("getTargetForeignKeyFields");
    targetForeignKeyFieldNamesMapping.setSetMethodName("setTargetForeignKeyFields");
    targetForeignKeyFieldNamesMapping.setXPath(getPrimaryNamespaceXPath() + "target-foreign-key-fields/" + getPrimaryNamespaceXPath() + "field");
    targetForeignKeyFieldNamesMapping.setReferenceClass(DatabaseField.class);
    descriptor.addMapping(targetForeignKeyFieldNamesMapping);
    XMLCompositeObjectMapping foreignKeyGroupingElementMapping = new XMLCompositeObjectMapping();
    foreignKeyGroupingElementMapping.setAttributeName("field");
    foreignKeyGroupingElementMapping.setReferenceClass(DatabaseField.class);
    foreignKeyGroupingElementMapping.setGetMethodName("getForeignKeyGroupingElement");
    foreignKeyGroupingElementMapping.setSetMethodName("setForeignKeyGroupingElement");
    foreignKeyGroupingElementMapping.setXPath(getPrimaryNamespaceXPath() + "foreign-key-grouping-element");
    descriptor.addMapping(foreignKeyGroupingElementMapping);
    XMLDirectMapping relationshipPartnerAttributeNameMapping = new XMLDirectMapping();
    relationshipPartnerAttributeNameMapping.setAttributeName("relationshipPartnerAttributeName");
    relationshipPartnerAttributeNameMapping.setGetMethodName("getRelationshipPartnerAttributeName");
    relationshipPartnerAttributeNameMapping.setSetMethodName("setRelationshipPartnerAttributeName");
    relationshipPartnerAttributeNameMapping.setXPath(getPrimaryNamespaceXPath() + "bidirectional-target-attribute/text()");
    descriptor.addMapping(relationshipPartnerAttributeNameMapping);
    XMLCompositeObjectMapping containerPolicyMapping = new XMLCompositeObjectMapping();
    containerPolicyMapping.setAttributeName("collectionPolicy");
    containerPolicyMapping.setGetMethodName("getContainerPolicy");
    containerPolicyMapping.setSetMethodName("setContainerPolicy");
    containerPolicyMapping.setReferenceClass(ContainerPolicy.class);
    containerPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "container");
    descriptor.addMapping(containerPolicyMapping);
    XMLCompositeObjectMapping indirectionPolicyMapping = new XMLCompositeObjectMapping();
    indirectionPolicyMapping.setReferenceClass(IndirectionPolicy.class);
    // Handle translation of NoIndirectionPolicy -> null.
    indirectionPolicyMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            IndirectionPolicy policy = ((ForeignReferenceMapping) object).getIndirectionPolicy();
            if (policy instanceof NoIndirectionPolicy) {
                return null;
            }
            return policy;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            IndirectionPolicy policy = (IndirectionPolicy) value;
            if (value == null) {
                policy = new NoIndirectionPolicy();
            }
            ((ForeignReferenceMapping) object).setIndirectionPolicy(policy);
        }
    });
    indirectionPolicyMapping.setAttributeName("indirectionPolicy");
    indirectionPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "indirection");
    descriptor.addMapping(indirectionPolicyMapping);
    XMLCompositeObjectMapping selectionQueryMapping = new XMLCompositeObjectMapping();
    selectionQueryMapping.setAttributeName("selectionQuery");
    selectionQueryMapping.setReferenceClass(ReadQuery.class);
    selectionQueryMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            if (((ForeignReferenceMapping) object).hasCustomSelectionQuery()) {
                return ((ForeignReferenceMapping) object).getSelectionQuery();
            }
            return null;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            if (value instanceof ReadQuery) {
                ((ForeignReferenceMapping) object).setCustomSelectionQuery((ReadQuery) value);
            }
        }
    });
    selectionQueryMapping.setXPath(getPrimaryNamespaceXPath() + "selection-query");
    descriptor.addMapping(selectionQueryMapping);
    // delete-all query
    XMLCompositeObjectMapping deleteAllQueryMapping = new XMLCompositeObjectMapping();
    deleteAllQueryMapping.setAttributeName("deleteAllQuery");
    deleteAllQueryMapping.setReferenceClass(ModifyQuery.class);
    deleteAllQueryMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            boolean hasCustomDeleteAllQuery = ((EISOneToManyMapping) object).hasCustomDeleteAllQuery();
            if (hasCustomDeleteAllQuery) {
                return ((EISOneToManyMapping) object).getDeleteAllQuery();
            } else {
                return null;
            }
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            if (value instanceof ModifyQuery) {
                ((EISOneToManyMapping) object).setCustomDeleteAllQuery((ModifyQuery) value);
            }
        }
    });
    deleteAllQueryMapping.setXPath(getPrimaryNamespaceXPath() + "delete-all-query");
    descriptor.addMapping(deleteAllQueryMapping);
    descriptor.getInheritancePolicy().setParentClass(CollectionMapping.class);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ModifyQuery(org.eclipse.persistence.queries.ModifyQuery) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) IndirectionPolicy(org.eclipse.persistence.internal.indirection.IndirectionPolicy) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) ReadQuery(org.eclipse.persistence.queries.ReadQuery) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 3 with NoIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.NoIndirectionPolicy in project eclipselink by eclipse-ee4j.

the class SetMethodParameterTypeNotValidTest method test.

@Override
public void test() {
    try {
        getSession().setIntegrityChecker(new IntegrityChecker());
        getSession().getIntegrityChecker().dontCatchExceptions();
        // the following causes the correct error to occure.
        RelationalDescriptor descriptor = descriptor();
        OneToManyMapping dMapping = (OneToManyMapping) descriptor.getMappingForAttributeName("managedEmployeesWithProblems");
        org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems person = new org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems();
        NoIndirectionPolicy indirectionPolicy = (NoIndirectionPolicy) dMapping.getIndirectionPolicy();
        indirectionPolicy.validateSetMethodParameterTypeForCollection(org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems.class, getSession().getIntegrityChecker());
    } catch (EclipseLinkException exception) {
        caughtException = exception;
    }
}
Also used : IntegrityChecker(org.eclipse.persistence.exceptions.IntegrityChecker) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy)

Example 4 with NoIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.NoIndirectionPolicy in project eclipselink by eclipse-ee4j.

the class InvalidIndirectionPolicyOperationTest method test.

@Override
public void test() {
    try {
        if (methodName.equals("ContainerIndirectionPolicy.nullValueFromRow")) {
            ContainerIndirectionPolicy policy = new ContainerIndirectionPolicy();
            policy.nullValueFromRow();
        } else if (methodName.equals("NoIndirectionPolicy.getValueFromRemoteValueHolder")) {
            NoIndirectionPolicy policy = new NoIndirectionPolicy();
            policy.getValueFromRemoteValueHolder(null);
        } else if (methodName.equals("NoIndirectionPolicy.mergeRemoteValueHolder")) {
            NoIndirectionPolicy policy = new NoIndirectionPolicy();
            policy.mergeRemoteValueHolder(null, null, null);
        } else {
            throw new org.eclipse.persistence.testing.framework.TestProblemException("Wrong method name for testing Invalid Indirection Policy Operation");
        }
    } catch (EclipseLinkException exception) {
        caughtException = exception;
    }
}
Also used : ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy)

Example 5 with NoIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.NoIndirectionPolicy in project eclipselink by eclipse-ee4j.

the class ProjectClassGenerator method addForeignReferenceMappingLines.

protected void addForeignReferenceMappingLines(NonreflectiveMethodDefinition method, String mappingName, ForeignReferenceMapping mapping) {
    if (mapping.getReferenceClassName() != null) {
        method.addLine(mappingName + ".setReferenceClass(" + mapping.getReferenceClassName() + ".class);");
    }
    if (mapping.getRelationshipPartnerAttributeName() != null) {
        method.addLine(mappingName + ".setRelationshipPartnerAttributeName(\"" + mapping.getRelationshipPartnerAttributeName() + "\");");
    }
    IndirectionPolicy policy = mapping.getIndirectionPolicy();
    if (policy instanceof ContainerIndirectionPolicy) {
        String containerClassName = ((ContainerIndirectionPolicy) policy).getContainerClassName();
        method.addLine(mappingName + ".useContainerIndirection(" + containerClassName + ".class);");
    // Bug#4251902 used in ObjectReferenceMapping
    } else if (policy instanceof ProxyIndirectionPolicy) {
        method.addLine(mappingName + ".useProxyIndirection();");
    } else if (policy instanceof BasicIndirectionPolicy) {
        method.addLine(mappingName + ".useBasicIndirection();");
    } else if (policy instanceof NoIndirectionPolicy) {
        method.addLine(mappingName + ".dontUseIndirection();");
    }
    if (mapping.shouldUseBatchReading()) {
        method.addLine(mappingName + ".useBatchReading();");
    }
    if (mapping.isJoinFetched()) {
        if (mapping.isInnerJoinFetched()) {
            method.addLine(mappingName + ".useInnerJoinFetch();");
        } else if (mapping.isOuterJoinFetched()) {
            method.addLine(mappingName + ".useOuterJoinFetch();");
        }
    }
    if ((!mapping.isDirectCollectionMapping()) && mapping.isPrivateOwned()) {
        method.addLine(mappingName + ".privateOwnedRelationship();");
    }
    if (mapping.isCollectionMapping()) {
        CollectionMapping collectionMapping = (CollectionMapping) mapping;
        String collectionClassName = collectionMapping.getContainerPolicy().getContainerClassName();
        if (mapping.getContainerPolicy().isCollectionPolicy()) {
            if (policy instanceof TransparentIndirectionPolicy) {
                method.addLine(mappingName + ".useTransparentCollection();");
            }
            if (!collectionClassName.equals(Vector.class.getName())) {
                method.addLine(mappingName + ".useCollectionClass(" + collectionClassName + ".class);");
            }
        } else if (collectionMapping.isDirectMapMapping()) {
            if (policy instanceof TransparentIndirectionPolicy) {
                method.addLine(mappingName + ".useTransparentMap();");
                if (!collectionClassName.equals(IndirectMap.class.getName())) {
                    method.addLine(mappingName + ".useMapClass(" + collectionClassName + ".class);");
                }
            } else {
                method.addLine(mappingName + ".useMapClass(" + collectionClassName + ".class);");
            }
        } else if (collectionMapping.getContainerPolicy().isMapPolicy()) {
            String keyMethodName = ((org.eclipse.persistence.internal.queries.MapContainerPolicy) collectionMapping.getContainerPolicy()).getKeyName();
            if (policy instanceof TransparentIndirectionPolicy) {
                method.addLine(mappingName + ".useTransparentMap(\"" + keyMethodName + "\");");
                if (!collectionClassName.equals(IndirectMap.class.getName())) {
                    method.addLine(mappingName + ".useMapClass(" + collectionClassName + ".class, \"" + keyMethodName + "\");");
                }
            } else {
                method.addLine(mappingName + ".useMapClass(" + collectionClassName + ".class, \"" + keyMethodName + "\");");
            }
        }
        // Ordering.
        Iterator<Expression> queryKeyExpressions = collectionMapping.getOrderByQueryKeyExpressions().iterator();
        while (queryKeyExpressions.hasNext()) {
            FunctionExpression expression = (FunctionExpression) queryKeyExpressions.next();
            String queryKeyName = expression.getBaseExpression().getName();
            if (expression.getOperator().getSelector() == ExpressionOperator.Descending) {
                method.addLine(mappingName + ".addDescendingOrdering(\"" + queryKeyName + "\");");
            } else {
                method.addLine(mappingName + ".addAscendingOrdering(\"" + queryKeyName + "\");");
            }
        }
    }
}
Also used : ProxyIndirectionPolicy(org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy) ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) InMemoryQueryIndirectionPolicy(org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy) IndirectionPolicy(org.eclipse.persistence.internal.indirection.IndirectionPolicy) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) IndirectMap(org.eclipse.persistence.indirection.IndirectMap) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) FunctionExpression(org.eclipse.persistence.internal.expressions.FunctionExpression) ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) ProxyIndirectionPolicy(org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy) FunctionExpression(org.eclipse.persistence.internal.expressions.FunctionExpression) Expression(org.eclipse.persistence.expressions.Expression) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) DirectCollectionMapping(org.eclipse.persistence.mappings.DirectCollectionMapping) CollectionMapping(org.eclipse.persistence.mappings.CollectionMapping) AggregateCollectionMapping(org.eclipse.persistence.mappings.AggregateCollectionMapping)

Aggregations

NoIndirectionPolicy (org.eclipse.persistence.internal.indirection.NoIndirectionPolicy)13 IndirectionPolicy (org.eclipse.persistence.internal.indirection.IndirectionPolicy)10 ContainerIndirectionPolicy (org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy)9 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)9 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)9 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)9 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)9 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)9 BasicIndirectionPolicy (org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy)8 ProxyIndirectionPolicy (org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy)8 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)8 InMemoryQueryIndirectionPolicy (org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)7 Association (org.eclipse.persistence.mappings.Association)7 Iterator (java.util.Iterator)6 PropertyAssociation (org.eclipse.persistence.mappings.PropertyAssociation)6 TypedAssociation (org.eclipse.persistence.mappings.TypedAssociation)6 XMLField (org.eclipse.persistence.oxm.XMLField)3