use of org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class InvalidAttributeTypeForProxyIndirectionTest method test.
@Override
public void test() {
ProxyIndirectionPolicy policy = new ProxyIndirectionPolicy();
mapping.setReferenceClass(attributeType);
mapping.addTargetForeignKeyFieldName("EMPLOYEE.MANAGER_ID", "EMPLOYEE.EMP_ID");
policy.setMapping(mapping);
try {
policy.validateDeclaredAttributeType(attributeType, getSession().getIntegrityChecker());
} catch (EclipseLinkException exception) {
caughtException = exception;
}
}
use of org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy 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.ProxyIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class ClassDescriptor method initialize.
/**
* INTERNAL:
* Initialize the mappings as a separate step.
* This is done as a separate step to ensure that inheritance has been first resolved.
*/
public void initialize(AbstractSession session) throws DescriptorException {
// Avoid repetitive initialization (this does not solve loops)
if (isInitialized(INITIALIZED) || isInvalid()) {
return;
}
setInitializationStage(INITIALIZED);
// make sure that parent mappings are initialized?
if (isChildDescriptor()) {
ClassDescriptor parentDescriptor = getInheritancePolicy().getParentDescriptor();
parentDescriptor.initialize(session);
getCachePolicy().initializeFromParent(parentDescriptor.getCachePolicy(), this, parentDescriptor, session);
// Setup this early before useOptimisticLocking is called so that subclass
// versioned by superclass are also covered
getInheritancePolicy().initializeOptimisticLocking();
// EL bug 336486
getInheritancePolicy().initializeCacheInvalidationPolicy();
if (parentDescriptor.hasSerializedObjectPolicy()) {
if (!hasSerializedObjectPolicy()) {
// If SerializedObjectPolicy set on parent descriptor then should be set on children, too
setSerializedObjectPolicy(parentDescriptor.getSerializedObjectPolicy().instantiateChild());
}
}
}
// This prevents null key errors when merging maps
if (shouldOrderMappings()) {
Vector<DatabaseMapping> mappings = getMappings();
DatabaseMapping[] mappingsArray = new DatabaseMapping[mappings.size()];
for (int index = 0; index < mappings.size(); index++) {
mappingsArray[index] = mappings.get(index);
}
Arrays.sort(mappingsArray, new MappingCompare());
mappings = NonSynchronizedVector.newInstance(mappingsArray.length);
for (int index = 0; index < mappingsArray.length; index++) {
mappings.add(mappingsArray[index]);
}
setMappings(mappings);
}
boolean initializeCascadeLocking = (usesOptimisticLocking() && getOptimisticLockingPolicy().isCascaded()) || hasCascadeLockingPolicies();
for (DatabaseMapping mapping : getMappings()) {
validateMappingType(mapping);
mapping.initialize(session);
if (!mapping.isCacheable()) {
this.hasNoncacheableMappings = true;
}
if (mapping.isForeignReferenceMapping()) {
if (((ForeignReferenceMapping) mapping).getIndirectionPolicy() instanceof ProxyIndirectionPolicy) {
session.getProject().setHasProxyIndirection(true);
}
ClassDescriptor referencedDescriptor = mapping.getReferenceDescriptor();
if (referencedDescriptor != null) {
referencedDescriptor.referencingClasses.add(this);
}
}
if (mapping.isAggregateObjectMapping()) {
ClassDescriptor referencedDescriptor = mapping.getReferenceDescriptor();
if (referencedDescriptor != null) {
referencedDescriptor.referencingClasses.add(this);
}
}
// mappings.
if (initializeCascadeLocking) {
prepareCascadeLockingPolicy(mapping);
}
// JPA 2.0 Derived identities - build a map of derived id mappings.
if (mapping.derivesId()) {
this.derivesIdMappings.put(mapping.getAttributeName(), mapping);
}
// Add all the fields in the mapping to myself.
Helper.addAllUniqueToVector(getFields(), mapping.getFields());
}
if (initializeCascadeLocking) {
this.cascadedLockingInitialized = true;
}
if (hasMappingsPostCalculateChangesOnDeleted()) {
session.getProject().setHasMappingsPostCalculateChangesOnDeleted(true);
}
// field is in correct position.
if (!isAggregateDescriptor()) {
if (!isChildDescriptor()) {
// Add write lock field to getFields
if (usesOptimisticLocking()) {
getOptimisticLockingPolicy().initializeProperties();
}
}
if (hasSerializedObjectPolicy()) {
getSerializedObjectPolicy().initializeField(session);
}
}
// All the query keys should be initialized.
for (Iterator<QueryKey> queryKeys = getQueryKeys().values().iterator(); queryKeys.hasNext(); ) {
QueryKey queryKey = queryKeys.next();
queryKey.initialize(this);
}
if (getPartitioningPolicyName() != null) {
PartitioningPolicy policy = session.getProject().getPartitioningPolicy(getPartitioningPolicyName());
if (policy == null) {
session.getIntegrityChecker().handleError(DescriptorException.missingPartitioningPolicy(getPartitioningPolicyName(), this, null));
}
setPartitioningPolicy(policy);
}
// If this descriptor has inheritance then it needs to be initialized before all fields is set.
if (hasInheritance()) {
getInheritancePolicy().initialize(session);
if (getInheritancePolicy().isChildDescriptor()) {
ClassDescriptor parentDescriptor = getInheritancePolicy().getParentDescriptor();
for (DatabaseMapping mapping : parentDescriptor.getMappings()) {
if (mapping.isAggregateObjectMapping() || ((mapping.isForeignReferenceMapping() && (!mapping.isDirectCollectionMapping())) && (!((ForeignReferenceMapping) mapping).usesIndirection()))) {
// add those mappings from the parent.
getLockableMappings().add(mapping);
}
// JPA 2.0 Derived identities - build a map of derived id mappings.
if (mapping.derivesId()) {
this.derivesIdMappings.put(mapping.getAttributeName(), mapping);
}
}
if (parentDescriptor.hasPreDeleteMappings()) {
getPreDeleteMappings().addAll(parentDescriptor.getPreDeleteMappings());
}
if (parentDescriptor.hasMappingsPostCalculateChanges()) {
getMappingsPostCalculateChanges().addAll(parentDescriptor.getMappingsPostCalculateChanges());
}
if (parentDescriptor.hasMappingsPostCalculateChangesOnDeleted()) {
getMappingsPostCalculateChangesOnDeleted().addAll(parentDescriptor.getMappingsPostCalculateChangesOnDeleted());
}
}
}
// This resort will change the previous sort order, only do it if has inheritance.
if (hasInheritance() && shouldOrderMappings()) {
Vector<DatabaseMapping> mappings = getMappings();
DatabaseMapping[] mappingsArray = new DatabaseMapping[mappings.size()];
for (int index = 0; index < mappings.size(); index++) {
mappingsArray[index] = mappings.get(index);
}
Arrays.sort(mappingsArray, new MappingCompare());
mappings = NonSynchronizedVector.newInstance(mappingsArray.length);
for (int index = 0; index < mappingsArray.length; index++) {
mappings.add(mappingsArray[index]);
}
setMappings(mappings);
}
// Initialize the allFields to its fields, this can be done now because the fields have been computed.
setAllFields((Vector) getFields().clone());
getObjectBuilder().initialize(session);
// initialized.
if (hasMultitenantPolicy()) {
getMultitenantPolicy().initialize(session);
}
if (shouldOrderMappings()) {
// PERF: Ensure direct primary key mappings are first.
for (int index = getObjectBuilder().getPrimaryKeyMappings().size() - 1; index >= 0; index--) {
DatabaseMapping mapping = getObjectBuilder().getPrimaryKeyMappings().get(index);
if ((mapping != null) && mapping.isAbstractColumnMapping()) {
getMappings().remove(mapping);
getMappings().add(0, mapping);
DatabaseField field = mapping.getField();
getFields().remove(field);
getFields().add(0, field);
getAllFields().remove(field);
getAllFields().add(0, field);
}
}
}
if (usesOptimisticLocking() && (!isChildDescriptor())) {
getOptimisticLockingPolicy().initialize(session);
}
if (hasInterfacePolicy() || isDescriptorForInterface()) {
interfaceInitialization(session);
}
if (hasWrapperPolicy()) {
getWrapperPolicy().initialize(session);
}
if (hasReturningPolicy()) {
getReturningPolicy().initialize(session);
}
if (hasSerializedObjectPolicy()) {
getSerializedObjectPolicy().initialize(session);
}
getQueryManager().initialize(session);
getEventManager().initialize(session);
getCopyPolicy().initialize(session);
getInstantiationPolicy().initialize(session);
getCachePolicy().initialize(this, session);
if (getHistoryPolicy() != null) {
getHistoryPolicy().initialize(session);
} else if (hasInheritance()) {
// Only one level of inheritance needs to be checked as parent descriptors
// are initialized before children are
ClassDescriptor parentDescriptor = getInheritancePolicy().getParentDescriptor();
if ((parentDescriptor != null) && (parentDescriptor.getHistoryPolicy() != null)) {
setHistoryPolicy((HistoryPolicy) parentDescriptor.getHistoryPolicy().clone());
}
}
if (getCMPPolicy() != null) {
getCMPPolicy().initialize(this, session);
}
// Validate the fetch group setting during descriptor initialization.
if (hasFetchGroupManager()) {
getFetchGroupManager().initialize(session);
}
// By default if change policy is not configured set to attribute change tracking if weaved.
if ((getObjectChangePolicyInternal() == null) && (ChangeTracker.class.isAssignableFrom(getJavaClass()))) {
// Only auto init if this class "itself" was weaved for change tracking, i.e. not just a superclass.
if (Arrays.asList(getJavaClass().getInterfaces()).contains(PersistenceWeavedChangeTracking.class) || (DynamicEntityImpl.class.isAssignableFrom(getJavaClass()))) {
// when it was weaved it was not initialized, and may now know that it does not support change tracking.
if (supportsChangeTracking(session.getProject())) {
setObjectChangePolicy(new AttributeChangeTrackingPolicy());
}
}
}
// 3934266 move validation to the policy allowing for this to be done in the sub policies.
getObjectChangePolicy().initialize(session, this);
// default redirector.
if (this.defaultReadAllQueryRedirector == null) {
this.defaultReadAllQueryRedirector = this.defaultQueryRedirector;
}
if (this.defaultReadObjectQueryRedirector == null) {
this.defaultReadObjectQueryRedirector = this.defaultQueryRedirector;
}
if (this.defaultReportQueryRedirector == null) {
this.defaultReportQueryRedirector = this.defaultQueryRedirector;
}
if (this.defaultInsertObjectQueryRedirector == null) {
this.defaultInsertObjectQueryRedirector = this.defaultQueryRedirector;
}
if (this.defaultUpdateObjectQueryRedirector == null) {
this.defaultUpdateObjectQueryRedirector = this.defaultQueryRedirector;
}
}
use of org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class InvalidGetMethodReturnTypeForProxyIndirectionTest method test.
@Override
public void test() {
ProxyIndirectionPolicy policy = new ProxyIndirectionPolicy();
mapping.setReferenceClass(attributeType);
mapping.addTargetForeignKeyFieldName("EMPLOYEE.MANAGER_ID", "EMPLOYEE.EMP_ID");
policy.setMapping(mapping);
try {
policy.validateGetMethodReturnType(attributeType, getSession().getIntegrityChecker());
} catch (EclipseLinkException exception) {
caughtException = exception;
}
}
use of org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class InvalidSetMethodParameterTypeForProxyIndirectionTest method test.
@Override
public void test() {
ProxyIndirectionPolicy policy = new ProxyIndirectionPolicy();
mapping.setReferenceClass(attributeType);
mapping.addTargetForeignKeyFieldName("EMPLOYEE.MANAGER_ID", "EMPLOYEE.EMP_ID");
policy.setMapping(mapping);
try {
policy.validateSetMethodParameterType(attributeType, getSession().getIntegrityChecker());
} catch (EclipseLinkException exception) {
caughtException = exception;
}
}
Aggregations