use of org.eclipse.persistence.descriptors.partitioning.PartitioningPolicy 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.descriptors.partitioning.PartitioningPolicy in project eclipselink by eclipse-ee4j.
the class Project method convertClassNamesToClasses.
/**
* INTERNAL:
* Convert all the class-name-based settings in this project to actual class-based settings.
* This will also reset any class references to the version of the class from the class loader.
*/
@Override
public void convertClassNamesToClasses(ClassLoader classLoader) {
Iterator<ClassDescriptor> ordered = orderedDescriptors.iterator();
while (ordered.hasNext()) {
ClassDescriptor descriptor = ordered.next();
descriptor.convertClassNamesToClasses(classLoader);
}
for (AttributeGroup group : this.getAttributeGroups().values()) {
group.convertClassNamesToClasses(classLoader);
}
// Clear old descriptors to allow rehash on new classes.
this.descriptors = new HashMap<>();
// convert class names to classes for each SQLResultSetMapping
if (this.sqlResultSetMappings != null) {
for (SQLResultSetMapping mapping : this.sqlResultSetMappings.values()) {
mapping.convertClassNamesToClasses(classLoader);
}
}
if (this.partitioningPolicies != null) {
for (PartitioningPolicy policy : this.partitioningPolicies.values()) {
policy.convertClassNamesToClasses(classLoader);
}
}
}
use of org.eclipse.persistence.descriptors.partitioning.PartitioningPolicy in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method updatePartitioning.
/**
* Checks for partitioning properties.
*/
protected void updatePartitioning(Map m, ClassLoader loader) {
// Partitioning
String partitioning = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.PARTITIONING, m, this.session);
if (partitioning != null) {
PartitioningPolicy partitioningPolicy = this.session.getProject().getPartitioningPolicy(partitioning);
if (partitioningPolicy == null) {
throw DescriptorException.missingPartitioningPolicy(partitioning, null, null);
}
this.session.setPartitioningPolicy(partitioningPolicy);
}
String callbackClassName = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.PARTITIONING_CALLBACK, m, this.session);
if (callbackClassName != null) {
DataPartitioningCallback callback = null;
try {
Class<? extends DataPartitioningCallback> cls = findClassForProperty(callbackClassName, PersistenceUnitProperties.PARTITIONING_CALLBACK, loader);
Constructor<? extends DataPartitioningCallback> constructor = cls.getConstructor();
callback = constructor.newInstance();
} catch (Exception exception) {
throw EntityManagerSetupException.failedToInstantiateProperty(callbackClassName, PersistenceUnitProperties.PARTITIONING_CALLBACK, exception);
}
this.session.getLogin().setPartitioningCallback(callback);
}
}
use of org.eclipse.persistence.descriptors.partitioning.PartitioningPolicy 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.descriptors.partitioning.PartitioningPolicy in project eclipselink by eclipse-ee4j.
the class DatabaseSessionImpl method initializeDescriptors.
/**
* INTERNAL:
* Allow each descriptor to initialize any dependencies on this session.
* This is done in two passes to allow the inheritance to be resolved first.
* Normally the descriptors are added before login, then initialized on login.
*/
public void initializeDescriptors() {
// Must clone to avoid modification of the map while enumerating.
initializeDescriptors((Map) ((HashMap) getDescriptors()).clone(), true);
// Initialize serializer
if (this.serializer != null) {
this.serializer.initialize(null, null, this);
}
// Initialize partitioning policies.
for (PartitioningPolicy policy : getProject().getPartitioningPolicies().values()) {
policy.initialize(this);
}
if (getProject().getMultitenantPolicy() != null) {
getProject().getMultitenantPolicy().initialize(this);
}
// Process JPA named queries and add as session queries,
// this must be done after descriptor init as requires to parse the JPQL.
processJPAQueries();
// Configure default query cache for all named queries.
QueryResultsCachePolicy defaultQueryCachePolicy = getProject().getDefaultQueryResultsCachePolicy();
if (defaultQueryCachePolicy != null) {
for (List<DatabaseQuery> queries : getQueries().values()) {
for (DatabaseQuery query : queries) {
if (query.isReadQuery() && (query.getDescriptor() != null) && !query.getDescriptor().getCachePolicy().isIsolated()) {
ReadQuery readQuery = (ReadQuery) query;
if (!readQuery.shouldCacheQueryResults()) {
readQuery.setQueryResultsCachePolicy(defaultQueryCachePolicy.clone());
}
}
}
}
}
for (AttributeGroup group : getProject().getAttributeGroups().values()) {
getAttributeGroups().put(group.getName(), group);
this.getDescriptor(group.getType()).addAttributeGroup(group);
}
}
Aggregations