Search in sources :

Example 1 with ContainerIndirectionPolicy

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

the class ContainerIndirectionPolicySerializationTest method test.

@Override
public void test() throws IOException, ClassNotFoundException {
    ContainerIndirectionPolicy policy = new ContainerIndirectionPolicy();
    policy.setContainerClass(IndirectList.class);
    policy.initialize();
    byte[] bytes = SerializationHelper.serialize(policy);
    ContainerIndirectionPolicy deserializedPolicy = (ContainerIndirectionPolicy) SerializationHelper.deserialize(bytes);
    deserializedPolicy.initialize();
    Object container = deserializedPolicy.valueFromRow(Boolean.TRUE);
    assertTrue(container.getClass().equals(IndirectList.class));
}
Also used : ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) IndirectList(org.eclipse.persistence.indirection.IndirectList)

Example 2 with ContainerIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy 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 3 with ContainerIndirectionPolicy

use of org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy 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)

Example 4 with ContainerIndirectionPolicy

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

the class NoConstructorIndirectionContainerClassTest method setup.

@Override
protected void setup() {
    policy = new ContainerIndirectionPolicy();
    // policy.setContainerClass(NoConstructorIndirectionContainerClassTest.class);//no problems
    // problems
    policy.setContainerClass(ClassWithoutConstructor.class);
    expectedException = DescriptorException.noConstructorIndirectionContainerClass(policy, ClassWithoutConstructor.class);
}
Also used : ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy)

Example 5 with ContainerIndirectionPolicy

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

the class InvalidIndirectionContainerClassTest method setup.

@Override
protected void setup() {
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    expectedException = DescriptorException.invalidIndirectionContainerClass(new ContainerIndirectionPolicy(), null);
    descriptor = getSession().getDescriptor(org.eclipse.persistence.testing.models.employee.domain.Employee.class);
    mapping = (OneToManyMapping) descriptor.getMappingForAttributeName("phoneNumbers");
    orgIndirectionPolicy = mapping.getIndirectionPolicy();
    // An invalid indirection container class
    mapping.useContainerIndirection(Vector.class);
    orgIntegrityChecker = getSession().getIntegrityChecker();
    getSession().setIntegrityChecker(new IntegrityChecker());
    getSession().getIntegrityChecker().dontCatchExceptions();
}
Also used : IntegrityChecker(org.eclipse.persistence.exceptions.IntegrityChecker) ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy)

Aggregations

ContainerIndirectionPolicy (org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy)8 NoIndirectionPolicy (org.eclipse.persistence.internal.indirection.NoIndirectionPolicy)3 BasicIndirectionPolicy (org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy)2 IndirectionPolicy (org.eclipse.persistence.internal.indirection.IndirectionPolicy)2 ProxyIndirectionPolicy (org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy)2 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)2 InMemoryQueryIndirectionPolicy (org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy)2 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)1 IntegrityChecker (org.eclipse.persistence.exceptions.IntegrityChecker)1 Expression (org.eclipse.persistence.expressions.Expression)1 IndirectList (org.eclipse.persistence.indirection.IndirectList)1 IndirectMap (org.eclipse.persistence.indirection.IndirectMap)1 FieldTransformation (org.eclipse.persistence.internal.descriptors.FieldTransformation)1 MethodBasedFieldTransformation (org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation)1 TransformerBasedFieldTransformation (org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation)1 FunctionExpression (org.eclipse.persistence.internal.expressions.FunctionExpression)1 AggregateCollectionMapping (org.eclipse.persistence.mappings.AggregateCollectionMapping)1 CollectionMapping (org.eclipse.persistence.mappings.CollectionMapping)1 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)1