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