diff options
author | tle | 2008-05-13 21:59:56 +0000 |
---|---|---|
committer | tle | 2008-05-13 21:59:56 +0000 |
commit | 8cc680c221058cc8f1c8c0ed676cd27cd6118a14 (patch) | |
tree | 7cbc1d9f387120d29e44740cdc2b23379c9bce30 | |
parent | 3255b6a9f3ba5f4cf16bfa275640cfabf2bd7178 (diff) | |
download | webtools.dali-8cc680c221058cc8f1c8c0ed676cd27cd6118a14.tar.gz webtools.dali-8cc680c221058cc8f1c8c0ed676cd27cd6118a14.tar.xz webtools.dali-8cc680c221058cc8f1c8c0ed676cd27cd6118a14.zip |
231021 - EclipseLink persistence.xml Entity Caching values not updating from source
6 files changed, 152 insertions, 23 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/CacheProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/CacheProperties.java index 2c413df319..399026b8fb 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/CacheProperties.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/CacheProperties.java @@ -20,10 +20,9 @@ public class CacheProperties implements Cloneable, Serializable { private String entityName; + // ********** EclipseLink properties ********** private CacheType type; - private Integer size; - private Boolean isShared; private static final long serialVersionUID = 1L; @@ -59,6 +58,12 @@ public class CacheProperties implements Cloneable, Serializable } } + public boolean isEmpty() { + return (this.type == null) && + (this.size == null) && + (this.isShared == null); + } + // ********** getter/setter ********** public String getEntityName() { return entityName; diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/Caching.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/Caching.java index 82cf030feb..882aac3e6c 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/Caching.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/Caching.java @@ -70,6 +70,7 @@ public interface Caching extends PersistenceUnitProperties ListIterator<String> entities(); int entitiesSize(); + boolean entityExists(String entity); String addEntity(String entity); void removeEntity(String entity); String ENTITIES_LIST_PROPERTY = "entitiesListProperty"; diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/EclipseLinkCaching.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/EclipseLinkCaching.java index 387ec39deb..45ed9c6261 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/EclipseLinkCaching.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/EclipseLinkCaching.java @@ -407,13 +407,18 @@ public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties } // ****** convenience methods ******* - + + /** + * Put the given Entity CacheProperties in this entitiesCacheProperties map. + * @param entityName - Entity name. The entity may be a new or an existing entity. + * @param properties - Entity CacheProperties + */ private void putEntityCacheProperties(String entityName, CacheProperties properties) { - this.addOrReplaceEntity(entityName, properties); + this.addOrReplacePropertiesForEntity(entityName, properties); } // ****** entities list ******* - + public ListIterator<String> entities() { return CollectionTools.list(this.entitiesCacheProperties.keySet()).listIterator(); } @@ -422,12 +427,32 @@ public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties return this.entitiesCacheProperties.size(); } + /* + * Verifies if this entitiesCacheProperties map contains the given Entity. + */ + public boolean entityExists(String entity) { + return this.entitiesCacheProperties.containsKey(entity); + } + public String addEntity(String entity) { - return this.addOrReplaceEntity(entity, new CacheProperties(entity)); + if (entityExists(entity)) { + throw new IllegalStateException("Entity " + entity + " already exist."); + } + return this.addOrReplacePropertiesForEntity(entity, new CacheProperties(entity)); } - private String addOrReplaceEntity(String entity, CacheProperties properties) { - if (this.entitiesCacheProperties.containsKey(entity)) { + /** + * Adds or replaces the given Entity CacheProperties in this + * entitiesCacheProperties map. + * If the specified Entity exists and the given CacheProperties is empty + * (i.e. all properties are null) the mapping will be removed from the map. + * + * @param entity - Entity name + * @param properties - Entity CacheProperties + * @return Entity name added + */ + private String addOrReplacePropertiesForEntity(String entity, CacheProperties properties) { + if (this.entityExists(entity)) { this.replaceEntity_(entity, properties); return null; } @@ -436,14 +461,29 @@ public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties return entity; } + /** + * Replaces the given Entity CacheProperties in this + * entitiesCacheProperties map. + * If the given Entity CacheProperties is empty (i.e. all properties are null) the + * mapping will be removed from the map. + * @param entity - Entity name + * @param properties - Entity CacheProperties + * @return Entity name replaced + */ private CacheProperties replaceEntity_(String entity, CacheProperties properties) { CacheProperties old = this.entitiesCacheProperties.get(entity); - this.entitiesCacheProperties.put(entity, properties); + if (properties.isEmpty()) { + this.entitiesCacheProperties.remove(entity); + this.fireListChanged(ENTITIES_LIST_PROPERTY); + } + else { + this.entitiesCacheProperties.put(entity, properties); + } return old; } public void removeEntity(String entity) { - if (!this.entitiesCacheProperties.containsKey(entity)) { + if ( ! this.entityExists(entity)) { return; } this.clearCacheProperties(entity); diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityCacheProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityCacheProperties.java index b4a33092f5..1bf6f8351a 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityCacheProperties.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityCacheProperties.java @@ -13,6 +13,11 @@ import org.eclipse.jpt.eclipselink.core.internal.context.caching.CacheType; import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching; import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.jpt.utility.internal.model.AbstractModel; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; +import org.eclipse.jpt.utility.model.value.PropertyValueModel; /** * EntityCacheProperties @@ -22,20 +27,45 @@ public class EntityCacheProperties extends AbstractModel { private Caching caching; private String entityName; + + private PropertyValueModel<CacheType> cacheTypeHolder; + private PropertyChangeListener cacheTypeListener; + private PropertyValueModel<Integer> cacheSizeHolder; + private PropertyChangeListener cacheSizeListener; + private PropertyValueModel<Boolean> sharedCacheHolder; + private PropertyChangeListener sharedCacheListener; private static final long serialVersionUID = 1L; - public static final String CACHE_SIZE_PROPERTY = Caching.CACHE_SIZE_PROPERTY; public static final String CACHE_TYPE_PROPERTY = Caching.CACHE_TYPE_PROPERTY; - public static final String SHARED_CACHE_PROPERTY = Caching.SHARED_CACHE_DEFAULT_PROPERTY; + public static final String CACHE_SIZE_PROPERTY = Caching.CACHE_SIZE_PROPERTY; + public static final String SHARED_CACHE_PROPERTY = Caching.SHARED_CACHE_PROPERTY; // ********** constructors ********** public EntityCacheProperties(Caching caching, String entityName) { super(); this.caching = caching; this.entityName = entityName; + + PropertyValueModel<Caching> cachingHolder = new SimplePropertyValueModel<Caching>(this.caching); + this.initialize(cachingHolder); } - + + protected void initialize(PropertyValueModel<Caching> cachingHolder) { + this.cacheTypeHolder = this.buildCacheTypeAA(cachingHolder); + this.cacheTypeListener = this.buildCacheTypeChangeListener(); + this.cacheTypeHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.cacheTypeListener); + + this.cacheSizeHolder = this.buildCacheSizeAA(cachingHolder); + this.cacheSizeListener = this.buildCacheSizeChangeListener(); + this.cacheSizeHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.cacheSizeListener); + + this.sharedCacheHolder = this.buildSharedCacheAA(cachingHolder); + this.sharedCacheListener = this.buildSharedCacheChangeListener(); + this.sharedCacheHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.sharedCacheListener); + } + + // ********** behavior ********** public boolean entityNameIsValid() { return !StringTools.stringIsEmpty(this.entityName); } @@ -90,6 +120,62 @@ public class EntityCacheProperties extends AbstractModel { this.firePropertyChanged(SHARED_CACHE_PROPERTY, oldSharedCache, sharedCache); } + // ********** PropertyChangeListener ********** + + private PropertyValueModel<CacheType> buildCacheTypeAA(PropertyValueModel<Caching> subjectHolder) { + return new PropertyAspectAdapter<Caching, CacheType>( + subjectHolder, CACHE_TYPE_PROPERTY) { + @Override + protected CacheType buildValue_() { + return this.subject.getCacheType(EntityCacheProperties.this.entityName); + } + }; + } + + private PropertyChangeListener buildCacheTypeChangeListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + EntityCacheProperties.this.firePropertyChanged(CACHE_TYPE_PROPERTY, e.getOldValue(), e.getNewValue()); + } + }; + } + + private PropertyValueModel<Integer> buildCacheSizeAA(PropertyValueModel<Caching> subjectHolder) { + return new PropertyAspectAdapter<Caching, Integer>( + subjectHolder, CACHE_SIZE_PROPERTY) { + @Override + protected Integer buildValue_() { + return this.subject.getCacheSize(EntityCacheProperties.this.entityName); + } + }; + } + + private PropertyChangeListener buildCacheSizeChangeListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + EntityCacheProperties.this.firePropertyChanged(CACHE_SIZE_PROPERTY, e.getOldValue(), e.getNewValue()); + } + }; + } + + private PropertyValueModel<Boolean> buildSharedCacheAA(PropertyValueModel<Caching> subjectHolder) { + return new PropertyAspectAdapter<Caching, Boolean>( + subjectHolder, SHARED_CACHE_PROPERTY) { + @Override + protected Boolean buildValue_() { + return this.subject.getSharedCache(EntityCacheProperties.this.entityName); + } + }; + } + + private PropertyChangeListener buildSharedCacheChangeListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + EntityCacheProperties.this.firePropertyChanged(SHARED_CACHE_PROPERTY, e.getOldValue(), e.getNewValue()); + } + }; + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityListComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityListComposite.java index 19b54f0e5c..3a7454513a 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityListComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityListComposite.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.eclipselink.ui.internal.caching; import java.util.ListIterator; + import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.window.Window; @@ -112,9 +113,11 @@ public class EntityListComposite extends AbstractPane<Caching> if (dialog.open() == Window.OK) { String name = dialog.getSelectedName(); - String entity = this.subject().addEntity(name); - - listSelectionModel.setSelectedValue(entity); + if( ! this.subject().entityExists(name)) { + String entity = this.subject().addEntity(name); + + listSelectionModel.setSelectedValue(entity); + } } } diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java index f1725847e2..9e53dd42e4 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java @@ -155,13 +155,7 @@ public class CachingAdapterTests extends PersistenceUnitTestCase assertNotNull("No Event Fired.", this.entitiesEvent); // verify event for the expected property assertEquals("Wrong Event.", this.entitiesEvent.getAspectName(), Caching.ENTITIES_LIST_PROPERTY); - - // try to add it again - this.clearEvent(); - this.caching.addEntity(ENTITY_TEST_2); - // verify event received - assertNull("Event was Fired.", this.entitiesEvent); - + // remove this.clearEvent(); this.caching.removeEntity(ENTITY_TEST_2); |