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);
}
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;
}
}
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;
}
}
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 + "\");");
}
}
}
}
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() + ");");
}
Aggregations