Search in sources :

Example 1 with BasicIndirectionPolicy

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

the class DynamicPropertiesInitializatonPolicy method initializeDefaultValue.

/**
 * Initialize the default value handling primitives, collections and
 * indirection.
 */
private void initializeDefaultValue(DatabaseMapping mapping, DynamicEntityImpl entity) {
    Object value = null;
    if (mapping.isDirectToFieldMapping() && mapping.getAttributeClassification().isPrimitive()) {
        Class<?> primClass = mapping.getAttributeClassification();
        if (primClass == ClassConstants.PBOOLEAN) {
            value = false;
        } else if (primClass == ClassConstants.PINT) {
            value = 0;
        } else if (primClass == ClassConstants.PLONG) {
            value = 0L;
        } else if (primClass == ClassConstants.PCHAR) {
            value = Character.MIN_VALUE;
        } else if (primClass == ClassConstants.PDOUBLE) {
            value = 0.0d;
        } else if (primClass == ClassConstants.PFLOAT) {
            value = 0.0f;
        } else if (primClass == ClassConstants.PSHORT) {
            value = Short.MIN_VALUE;
        } else if (primClass == ClassConstants.PBYTE) {
            value = Byte.MIN_VALUE;
        }
    } else if (mapping.isForeignReferenceMapping()) {
        ForeignReferenceMapping refMapping = (ForeignReferenceMapping) mapping;
        if (refMapping.usesIndirection() && refMapping.getIndirectionPolicy() instanceof BasicIndirectionPolicy) {
            value = new ValueHolder<>(value);
        } else if (refMapping.isCollectionMapping()) {
            value = refMapping.getContainerPolicy().containerInstance();
        }
    } else if (mapping.isAggregateObjectMapping()) {
        value = mapping.getReferenceDescriptor().getObjectBuilder().buildNewInstance();
    }
    PropertyWrapper propertyWrapper = entity.getPropertiesMap().get(mapping.getAttributeName());
    // NB - only the value is set, not the 'isSet' boolean
    propertyWrapper.setValue(value);
}
Also used : PropertyWrapper(org.eclipse.persistence.internal.dynamic.DynamicEntityImpl.PropertyWrapper) ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) ValueHolder(org.eclipse.persistence.indirection.ValueHolder)

Example 2 with BasicIndirectionPolicy

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

the class ForeignReferenceMapping method preInitialize.

/**
 * INTERNAL:
 * Initialize the state of mapping.
 */
@Override
public void preInitialize(AbstractSession session) throws DescriptorException {
    super.preInitialize(session);
    // If weaving was used the mapping must be configured to use the weaved get/set methods.
    if ((this.indirectionPolicy instanceof BasicIndirectionPolicy) && ClassConstants.PersistenceWeavedLazy_Class.isAssignableFrom(getDescriptor().getJavaClass())) {
        Class<?> attributeType = getAttributeAccessor().getAttributeClass();
        // Check that not already weaved or coded.
        if (!(ClassConstants.ValueHolderInterface_Class.isAssignableFrom(attributeType))) {
            if (!indirectionPolicy.isWeavedObjectBasicIndirectionPolicy()) {
                if (getAttributeAccessor().isMethodAttributeAccessor()) {
                    useWeavedIndirection(getGetMethodName(), getSetMethodName(), true);
                } else if (getAttributeAccessor().isInstanceVariableAttributeAccessor()) {
                    useWeavedIndirection(Helper.getWeavedGetMethodName(getAttributeName()), Helper.getWeavedSetMethodName(getAttributeName()), false);
                }
            }
            setGetMethodName(Helper.getWeavedValueHolderGetMethodName(getAttributeName()));
            setSetMethodName(Helper.getWeavedValueHolderSetMethodName(getAttributeName()));
            // Must re-initialize the attribute accessor.
            super.preInitialize(session);
        }
    }
    if (getPartitioningPolicyName() != null) {
        PartitioningPolicy policy = session.getProject().getPartitioningPolicy(getPartitioningPolicyName());
        if (policy == null) {
            session.getIntegrityChecker().handleError(DescriptorException.missingPartitioningPolicy(getPartitioningPolicyName(), null, this));
        }
        setPartitioningPolicy(policy);
    }
    if (this.isCascadeOnDeleteSetOnDatabase && !session.getPlatform().supportsDeleteOnCascade()) {
        this.isCascadeOnDeleteSetOnDatabase = false;
    }
}
Also used : WeavedObjectBasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.WeavedObjectBasicIndirectionPolicy) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) PartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.PartitioningPolicy)

Example 3 with BasicIndirectionPolicy

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

the class ValueHolderInstantiationMismatchTest 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();
        OneToOneMapping dMapping = (OneToOneMapping) descriptor.getMappingForAttributeName("addressWithProblems");
        org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems person = new org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems();
        BasicIndirectionPolicy indirectionPolicy = (BasicIndirectionPolicy) dMapping.getIndirectionPolicy();
        indirectionPolicy.validateAttributeOfInstantiatedObject(new java.util.Vector());
    } catch (EclipseLinkException exception) {
        caughtException = exception;
    }
}
Also used : IntegrityChecker(org.eclipse.persistence.exceptions.IntegrityChecker) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 4 with BasicIndirectionPolicy

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

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

the class ProjectClassGenerator method addTransformationMappingLines.

protected void addTransformationMappingLines(NonreflectiveMethodDefinition method, String mappingName, TransformationMapping mapping) {
    if (!mapping.isWriteOnly()) {
        if (mapping.getAttributeMethodName() != null) {
            method.addLine(mappingName + ".setAttributeTransformation(\"" + mapping.getAttributeMethodName() + "\");");
        } else {
            method.addLine(mappingName + ".setAttributeTransformer(new " + mapping.getAttributeTransformerClassName() + "());");
        }
    }
    Iterator<FieldTransformation> fieldTransformations = mapping.getFieldTransformations().iterator();
    while (fieldTransformations.hasNext()) {
        FieldTransformation trans = fieldTransformations.next();
        String fieldName = trans.getFieldName();
        if (trans instanceof MethodBasedFieldTransformation) {
            String methodName = ((MethodBasedFieldTransformation) trans).getMethodName();
            method.addLine(mappingName + ".addFieldTransformation(\"" + fieldName + "\", \"" + methodName + "\");");
        } else {
            String transformerClass = ((TransformerBasedFieldTransformation) trans).getTransformerClassName();
            method.addLine(mappingName + ".addFieldTransformer(\"" + fieldName + "\", new " + transformerClass + "());");
        }
    }
    IndirectionPolicy policy = mapping.getIndirectionPolicy();
    if (policy instanceof ContainerIndirectionPolicy) {
        String containerClassName = ((ContainerIndirectionPolicy) policy).getContainerClassName();
        method.addLine(mappingName + ".useContainerIndirection(" + containerClassName + ".class);");
    } else if (policy instanceof BasicIndirectionPolicy) {
        method.addLine(mappingName + ".useBasicIndirection();");
    }
    method.addLine(mappingName + ".setIsMutable(" + mapping.isMutable() + ");");
}
Also used : TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation) ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) 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) TransformerBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.TransformerBasedFieldTransformation) FieldTransformation(org.eclipse.persistence.internal.descriptors.FieldTransformation) MethodBasedFieldTransformation(org.eclipse.persistence.internal.descriptors.MethodBasedFieldTransformation)

Aggregations

BasicIndirectionPolicy (org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy)7 ForeignReferenceMapping (org.eclipse.persistence.mappings.ForeignReferenceMapping)3 ValueHolderInterface (org.eclipse.persistence.indirection.ValueHolderInterface)2 ContainerIndirectionPolicy (org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy)2 IndirectionPolicy (org.eclipse.persistence.internal.indirection.IndirectionPolicy)2 NoIndirectionPolicy (org.eclipse.persistence.internal.indirection.NoIndirectionPolicy)2 ProxyIndirectionPolicy (org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy)2 TransparentIndirectionPolicy (org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy)2 MetadataClass (org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass)2 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 InMemoryQueryIndirectionPolicy (org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)1 PartitioningPolicy (org.eclipse.persistence.descriptors.partitioning.PartitioningPolicy)1 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)1 IntegrityChecker (org.eclipse.persistence.exceptions.IntegrityChecker)1 Expression (org.eclipse.persistence.expressions.Expression)1 IndirectMap (org.eclipse.persistence.indirection.IndirectMap)1 ValueHolder (org.eclipse.persistence.indirection.ValueHolder)1