/** * INTERNAL: * Allow the inheritance properties of the descriptor to be initialized. * The descriptor's parent must first be initialized. */ public void initializeFromParent(CachePolicy parentPolicy, ClassDescriptor descriptor, ClassDescriptor descriptorDescriptor, AbstractSession session) throws DescriptorException { // If the parent is isolated, then the child must also be isolated. if (!parentPolicy.isSharedIsolation()) { // Do not override cache isolation when explicitly enabled by @Cacheable(true) annotation in current class. boolean copyParrent = cacheable == null || cacheable == false; if (!isIsolated() && (getCacheIsolation() != parentPolicy.getCacheIsolation()) && copyParrent) { session.log(SessionLog.WARNING, SessionLog.METADATA, "overriding_cache_isolation", new Object[]{descriptorDescriptor.getAlias(), parentPolicy.getCacheIsolation(), descriptor.getAlias(), getCacheIsolation()}); setCacheIsolation(parentPolicy.getCacheIsolation()); } } // Child must maintain the same indexes as the parent. for (CacheIndex index : parentPolicy.getCacheIndexes().values()) { addCacheIndex(index); } if ((getDatabaseChangeNotificationType() == null) && (parentPolicy.getDatabaseChangeNotificationType() != null)) { setDatabaseChangeNotificationType(parentPolicy.getDatabaseChangeNotificationType()); } if ((getCacheSynchronizationType() == UNDEFINED_OBJECT_CHANGE_BEHAVIOR) && (parentPolicy.getCacheSynchronizationType() != UNDEFINED_OBJECT_CHANGE_BEHAVIOR)) { setCacheSynchronizationType(parentPolicy.getCacheSynchronizationType()); } }
/** * Return the cache policy. * The cache policy allows for the configuration of caching options. */ public CachePolicy getCachePolicy() { if (this.cachePolicy == null) { this.cachePolicy = new CachePolicy(); } return cachePolicy; }
/** * A CacheInterceptor is an adaptor that when overridden and assigned to a Descriptor all interaction * between EclipseLink and the internal cache for that class will pass through the Interceptor. * Advanced users could use this interceptor to audit, profile or log cache access. This Interceptor * could also be used to redirect or augment the TopLink cache with an alternate cache mechanism. * EclipseLink's configurated IdentityMaps will be passed to the Interceptor constructor. * * As with IdentityMaps an entire class inheritance hierarchy will share the same interceptor. * @see org.eclipse.persistence.sessions.interceptors.CacheInterceptor */ public Class getCacheInterceptorClass() { return getCachePolicy().getCacheInterceptorClass(); }
if (hasCacheIndexes()) { for (CacheIndex index : getCacheIndexes().values()) { for (int count = 0; count < index.getFields().size(); count++) { index.getFields().set(count, descriptor.buildField(index.getFields().get(count))); if (isSharedIsolation()) { setCacheIsolation(CacheIsolationType.PROTECTED); ClassDescriptor referencedDescriptor = ((ForeignReferenceMapping)mapping).getReferenceDescriptor(); if (referencedDescriptor!= null) { if (isSharedIsolation() && !referencedDescriptor.getCachePolicy().isSharedIsolation()) { setCacheIsolation(CacheIsolationType.PROTECTED); ClassDescriptor referencedDescriptor = ((AggregateObjectMapping)mapping).getReferenceDescriptor(); if (referencedDescriptor != null) { if (isSharedIsolation() && !referencedDescriptor.getCachePolicy().isSharedIsolation()) { setCacheIsolation(CacheIsolationType.PROTECTED);
fields.add(rowId); CacheIndex existingIndex = descriptor.getCachePolicy().getCacheIndex(fields); if (existingIndex == null) { if (descriptor.isChildDescriptor()) { existingIndex = descriptor.getInheritancePolicy().getRootParentDescriptor().getCachePolicy().getCacheIndex(fields); existingIndex.setIsInsertable(false); descriptor.getCachePolicy().addCacheIndex(existingIndex);
/** * PUBLIC: * Add the cache index to the descriptor's cache settings. * This allows for cache hits to be obtained on non-primary key fields. * The primary key is always indexed in the cache. * Cache indexes are defined by their database column names. */ public void addCacheIndex(DatabaseField fields[]) { addCacheIndex(new CacheIndex(fields)); }
/** * INTERNAL: * Post initializations after mappings are initialized. */ public void postInitialize(AbstractSession session) throws DescriptorException { // PERF: Cache if needs to unwrap to optimize unwrapping. this.hasWrapperPolicy = this.descriptor.hasWrapperPolicy() || session.getProject().hasProxyIndirection(); // PERF: Used by ObjectLevelReadQuery ResultSetAccessOptimization. this.shouldKeepRow = false; for (DatabaseField field : this.descriptor.getFields()) { if (field.keepInRow()) { this.shouldKeepRow = true; break; } } // PERF: is there an cache index field that's would not be selected by SOP query. Ignored unless descriptor uses SOP and CachePolicy has cache indexes. if (this.descriptor.hasSerializedObjectPolicy() && this.descriptor.getCachePolicy().hasCacheIndexes()) { for (List<DatabaseField> indexFields : this.descriptor.getCachePolicy().getCacheIndexes().keySet()) { if (!this.descriptor.getSerializedObjectPolicy().getSelectionFields().containsAll(indexFields)) { this.hasCacheIndexesInSopObject = true; break; } } } }
/** * INTERNAL: * Allow the descriptor to initialize any dependencies on this session. */ public void preInitialize(AbstractSession session) throws DescriptorException { // Avoid repetitive initialization (this does not solve loops) if (isInitialized(PREINITIALIZED)) { return; } setInitializationStage(PREINITIALIZED); // Allow mapping pre init, must be done before validate. for (Enumeration mappingsEnum = getMappings().elements(); mappingsEnum.hasMoreElements();) { try { DatabaseMapping mapping = (DatabaseMapping) mappingsEnum.nextElement(); mapping.preInitialize(session); } catch (DescriptorException exception) { session.getIntegrityChecker().handleError(exception); } } getCachePolicy().useNoIdentityMap(); getQueryManager().getDoesExistQuery().setExistencePolicy(DoesExistQuery.CheckDatabase); validateBeforeInitialization(session); preInitializeInheritancePolicy(session); verifyTableQualifiers(session.getDatasourcePlatform()); initializeProperties(session); if (hasInterfacePolicy()) { preInterfaceInitialization(session); } getCachePolicy().assignDefaultValues(session); }
CacheKey cacheKey = descriptor.getCachePolicy().checkCacheByIndex(selectionCriteria, translationRow, descriptor, session); if (cacheKey != null) { if (query.requiresDeferredLocks()) { && ((uow == null) || (!uow.isNestedUnitOfWork() && descriptor.getCachePolicy().shouldIsolateObjectsInUnitOfWork()))) { return InvalidObject.instance;
for (ClassDescriptor descriptor : session.getDescriptors().values()) { if (!descriptor.getTables().isEmpty()) { if ((descriptor.getCachePolicy().getDatabaseChangeNotificationType() != null) && (descriptor.getCachePolicy().getDatabaseChangeNotificationType() != DatabaseChangeNotificationType.NONE)) { this.descriptorsByTable.put(descriptor.getTables().get(0), descriptor);
/** * PUBLIC: * Return the cache index for the field names. */ public CacheIndex getCacheIndex(List<DatabaseField> fields) { return getCacheIndexes().get(fields); }
/** * INTERNAL: * Some attributes have default values defined in Project. * If such the value for the attribute hasn't been set then the default value is assigned. */ protected void assignDefaultValues(AbstractSession session) { if (this.idValidation == null) { this.idValidation = session.getProject().getDefaultIdValidation(); } getCachePolicy().assignDefaultValues(session); }
@Override public void onDatabaseChangeNotification(DatabaseChangeEvent changeEvent) { databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_change_event", changeEvent); if (changeEvent.getTableChangeDescription() != null) { for (TableChangeDescription tableChange : changeEvent.getTableChangeDescription()) { ClassDescriptor descriptor = OracleChangeNotificationListener.this.descriptorsByTable.get(new DatabaseTable(tableChange.getTableName())); if (descriptor != null) { CacheIndex index = descriptor.getCachePolicy().getCacheIndex(fields); for (RowChangeDescription rowChange : tableChange.getRowChangeDescription()) { CacheId id = new CacheId(new Object[]{rowChange.getRowid().stringValue()}); CacheKey key = databaseSession.getIdentityMapAccessorInstance().getIdentityMapManager().getCacheKeyByIndex( index, id, true, descriptor); if (key != null) { if ((key.getTransactionId() == null) || !key.getTransactionId().equals(changeEvent.getTransactionId(true))) { databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_invalidate", key.getKey(), descriptor.getJavaClass().getName()); key.setInvalidationState(CacheKey.CACHE_KEY_INVALID); } } } } } } } });
clonedDescriptor.setCachePolicy(this.cachePolicy.clone());
this.cachePolicy.convertClassNamesToClasses(classLoader);
if (hasCacheIndexes()) { for (CacheIndex index : getCacheIndexes().values()) { for (int count = 0; count < index.getFields().size(); count++) { index.getFields().set(count, descriptor.buildField(index.getFields().get(count))); if (isSharedIsolation()) { setCacheIsolation(CacheIsolationType.PROTECTED); ClassDescriptor referencedDescriptor = ((ForeignReferenceMapping)mapping).getReferenceDescriptor(); if (referencedDescriptor!= null) { if (isSharedIsolation() && !referencedDescriptor.getCachePolicy().isSharedIsolation()) { setCacheIsolation(CacheIsolationType.PROTECTED); ClassDescriptor referencedDescriptor = ((AggregateObjectMapping)mapping).getReferenceDescriptor(); if (referencedDescriptor != null) { if (isSharedIsolation() && !referencedDescriptor.getCachePolicy().isSharedIsolation()) { setCacheIsolation(CacheIsolationType.PROTECTED);
fields.add(rowId); CacheIndex existingIndex = descriptor.getCachePolicy().getCacheIndex(fields); if (existingIndex == null) { if (descriptor.isChildDescriptor()) { existingIndex = descriptor.getInheritancePolicy().getRootParentDescriptor().getCachePolicy().getCacheIndex(fields); existingIndex.setIsInsertable(false); descriptor.getCachePolicy().addCacheIndex(existingIndex);
/** * PUBLIC: * Add the cache index to the descriptor's cache settings. * This allows for cache hits to be obtained on non-primary key fields. * The primary key is always indexed in the cache. * Cache indexes are defined by their database column names. */ public void addCacheIndex(String... fields) { addCacheIndex(new CacheIndex(fields)); }
/** * INTERNAL: * Post initializations after mappings are initialized. */ public void postInitialize(AbstractSession session) throws DescriptorException { // PERF: Cache if needs to unwrap to optimize unwrapping. this.hasWrapperPolicy = this.descriptor.hasWrapperPolicy() || session.getProject().hasProxyIndirection(); // PERF: Used by ObjectLevelReadQuery ResultSetAccessOptimization. this.shouldKeepRow = false; for (DatabaseField field : this.descriptor.getFields()) { if (field.keepInRow()) { this.shouldKeepRow = true; break; } } // PERF: is there an cache index field that's would not be selected by SOP query. Ignored unless descriptor uses SOP and CachePolicy has cache indexes. if (this.descriptor.hasSerializedObjectPolicy() && this.descriptor.getCachePolicy().hasCacheIndexes()) { for (List<DatabaseField> indexFields : this.descriptor.getCachePolicy().getCacheIndexes().keySet()) { if (!this.descriptor.getSerializedObjectPolicy().getSelectionFields().containsAll(indexFields)) { this.hasCacheIndexesInSopObject = true; break; } } } }
/** * INTERNAL: * Allow the descriptor to initialize any dependencies on this session. */ public void preInitialize(AbstractSession session) throws DescriptorException { // Avoid repetitive initialization (this does not solve loops) if (isInitialized(PREINITIALIZED)) { return; } setInitializationStage(PREINITIALIZED); // Allow mapping pre init, must be done before validate. for (Enumeration mappingsEnum = getMappings().elements(); mappingsEnum.hasMoreElements();) { try { DatabaseMapping mapping = (DatabaseMapping) mappingsEnum.nextElement(); mapping.preInitialize(session); } catch (DescriptorException exception) { session.getIntegrityChecker().handleError(exception); } } getCachePolicy().useNoIdentityMap(); getQueryManager().getDoesExistQuery().setExistencePolicy(DoesExistQuery.CheckDatabase); validateBeforeInitialization(session); preInitializeInheritancePolicy(session); verifyTableQualifiers(session.getDatasourcePlatform()); initializeProperties(session); if (hasInterfacePolicy()) { preInterfaceInitialization(session); } getCachePolicy().assignDefaultValues(session); }