diff options
author | tle | 2009-06-12 21:57:59 +0000 |
---|---|---|
committer | tle | 2009-06-12 21:57:59 +0000 |
commit | b9992a70fc32099778471b71a81a6238f0cbf3a4 (patch) | |
tree | 0955f1c1cd90b19638113dea75fbe985929187a6 | |
parent | a9e4681dffb1654a7c14b42730b00ed998710b3d (diff) | |
download | webtools.dali-b9992a70fc32099778471b71a81a6238f0cbf3a4.tar.gz webtools.dali-b9992a70fc32099778471b71a81a6238f0cbf3a4.tar.xz webtools.dali-b9992a70fc32099778471b71a81a6238f0cbf3a4.zip |
272982 - Memory leak in EntityCacheProperties
28 files changed, 849 insertions, 1012 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnitProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnitProperties.java index ad8a421909..ea1443018b 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnitProperties.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnitProperties.java @@ -92,7 +92,7 @@ public abstract class EclipseLinkPersistenceUnitProperties extends AbstractModel * Returns the property name used for change notification of the given * property. */ - public String propertyIdFor(PersistenceUnit.Property property) { + public String propertyIdOf(PersistenceUnit.Property property) { String propertyId = this.propertyNames().get(property.getName()); if (propertyId == null) { throw new IllegalArgumentException("Illegal property: " + property); //$NON-NLS-1$ @@ -100,7 +100,10 @@ public abstract class EclipseLinkPersistenceUnitProperties extends AbstractModel return propertyId; } - protected String eclipseLinkKeyFor(String propertyId) { + /* + * Get the EclipseLink key of the given property + */ + protected String eclipseLinkKeyOf(String propertyId) { for (String eclipseLinkKey : this.propertyNames().keySet()) { if (this.propertyNames().get(eclipseLinkKey).equals(propertyId)) { return eclipseLinkKey; @@ -317,7 +320,7 @@ public abstract class EclipseLinkPersistenceUnitProperties extends AbstractModel @SuppressWarnings("unchecked") protected void putProperty(String key, Object value, boolean allowDuplicates) { - String elKey = this.eclipseLinkKeyFor(key); + String elKey = this.eclipseLinkKeyOf(key); if ((value != null) && value.getClass().isEnum()) { this.putEnumValue(elKey, (Enum) value, allowDuplicates); } else { @@ -339,7 +342,7 @@ public abstract class EclipseLinkPersistenceUnitProperties extends AbstractModel * property value */ protected void removeProperty(String key, String value) { - String elKey = this.eclipseLinkKeyFor(key); + String elKey = this.eclipseLinkKeyOf(key); this.getPersistenceUnit().removeProperty(elKey, value); } @@ -352,15 +355,15 @@ public abstract class EclipseLinkPersistenceUnitProperties extends AbstractModel * Extracts the entityName of the specified property name. If the property name * has no suffix, return an empty string. */ - protected String getEntityName(PersistenceUnit.Property property) { - return getEntityName(property.getName()); + protected String extractEntityNameOf(PersistenceUnit.Property property) { + return extractEntityNameOf(property.getName()); } /** * Extracts the entityName of the specified string. If the string * has no suffix, return an empty string. */ - protected String getEntityName(String propertyName) { + protected String extractEntityNameOf(String propertyName) { int index = propertyName.lastIndexOf('.'); if (index == -1) { return ""; //$NON-NLS-1$ @@ -370,7 +373,7 @@ public abstract class EclipseLinkPersistenceUnitProperties extends AbstractModel // ****** Static methods ******* /** - * Returns the EclipseLink string value for the given property value. + * Returns the EclipseLink string value of the given property value. */ public static String getEclipseLinkStringValueOf(Object value) { if (value == null) { diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/PersistenceUnitProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/PersistenceUnitProperties.java index d13ad8a244..ef66ffe8db 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/PersistenceUnitProperties.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/PersistenceUnitProperties.java @@ -26,7 +26,7 @@ public interface PersistenceUnitProperties extends Model /** * Returns the property name used for change notification of the given property. */ - String propertyIdFor(PersistenceUnit.Property property); + String propertyIdOf(PersistenceUnit.Property property); /** * Return the PersistenceUnit of this Properties. diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/CacheProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/CacheProperties.java deleted file mode 100644 index e801f0bad8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/CacheProperties.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching; - -import java.io.Serializable; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * CacheProperties - */ -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; - - // ********** constructors ********** - public CacheProperties(String entityName) { - this.entityName = entityName; - } - - // ********** behaviors ********** - @Override - public boolean equals(Object o) { - if(o == null) { - return false; - } - CacheProperties cache = (CacheProperties) o; - return ( - (this.type == null ? - cache.type == null : this.type.equals(cache.type)) && - (this.isShared == null ? - cache.isShared == null : this.isShared.equals(cache.isShared)) && - (this.size == null ? - cache.size == null : this.size.equals(cache.size))); - } - - @Override - public CacheProperties clone() { - try { - return (CacheProperties)super.clone(); - } - catch (CloneNotSupportedException ex) { - throw new InternalError(); - } - } - - public boolean isEmpty() { - return (this.type == null) && - (this.size == null) && - (this.isShared == null); - } - - // ********** getter/setter ********** - public String getEntityName() { - return entityName; - } - - public CacheType getType() { - return this.type; - } - - public void setType(CacheType cacheType) { - this.type = cacheType; - } - - public Integer getSize() { - return this.size; - } - - public void setSize(Integer cacheSize) { - this.size = cacheSize; - } - - public Boolean isShared() { - return this.isShared; - } - - public void setShared(Boolean isShared) { - this.isShared = isShared; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - StringTools.buildSimpleToStringOn(this, sb); - sb.append(" ("); - this.toString(sb); - sb.append(')'); - return sb.toString(); - } - - public void toString(StringBuilder sb) { - sb.append("type: "); - sb.append(this.type); - sb.append(", size: "); - sb.append(this.size); - sb.append(", isShared: "); - sb.append(this.isShared); - sb.append(", entityName: "); - sb.append(this.entityName); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/Caching.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/Caching.java index 820a530938..3c2da6ef89 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/Caching.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/Caching.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2008 Oracle. All rights reserved. +* Copyright (c) 2008, 2009 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -43,24 +43,24 @@ public interface Caching extends PersistenceUnitProperties CacheType getDefaultCacheType(); - CacheType getCacheType(String entityName); - void setCacheType(CacheType cacheType, String entityName); + CacheType getCacheTypeOf(String entityName); + void setCacheTypeOf(String entityName, CacheType cacheType); static final String CACHE_TYPE_PROPERTY = "cacheType"; //$NON-NLS-1$ // EclipseLink key string static final String ECLIPSELINK_CACHE_TYPE = "eclipselink.cache.type."; //$NON-NLS-1$ static final CacheType DEFAULT_CACHE_TYPE = CacheType.soft_weak; Integer getDefaultCacheSize(); - Integer getCacheSize(String entityName); - void setCacheSize(Integer cacheSize, String entityName); + Integer getCacheSizeOf(String entityName); + void setCacheSizeOf(String entityName, Integer cacheSize); static final String CACHE_SIZE_PROPERTY = "cacheSize"; //$NON-NLS-1$ // EclipseLink key string static final String ECLIPSELINK_CACHE_SIZE = "eclipselink.cache.size."; //$NON-NLS-1$ static final Integer DEFAULT_CACHE_SIZE = Integer.valueOf(100); Boolean getDefaultSharedCache(); - Boolean getSharedCache(String entityName); - void setSharedCache(Boolean sharedCache, String entityName); + Boolean getSharedCacheOf(String entityName); + void setSharedCacheOf(String entityName, Boolean sharedCache); static final String SHARED_CACHE_PROPERTY = "sharedCache"; //$NON-NLS-1$ // EclipseLink key string static final String ECLIPSELINK_SHARED_CACHE = "eclipselink.cache.shared."; //$NON-NLS-1$ @@ -75,10 +75,10 @@ public interface Caching extends PersistenceUnitProperties static final FlushClearCache DEFAULT_FLUSH_CLEAR_CACHE = FlushClearCache.drop_invalidate; - ListIterator<String> entities(); + ListIterator<Entity> entities(); int entitiesSize(); boolean entityExists(String entity); - String addEntity(String entity); + Entity addEntity(String entity); void removeEntity(String entity); String ENTITIES_LIST_PROPERTY = "entities"; //$NON-NLS-1$ diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/EclipseLinkCaching.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/EclipseLinkCaching.java index c5b7ce8ad1..84e3af627d 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/EclipseLinkCaching.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/EclipseLinkCaching.java @@ -9,13 +9,15 @@ *******************************************************************************/ package org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching; -import java.util.HashMap; +import java.util.ArrayList; +import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Set; + import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnitProperties; -import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; /** * EclipseLinkCaching encapsulates EclipseLink Caching properties. @@ -29,8 +31,7 @@ public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties private Boolean sharedCacheDefault; private FlushClearCache flushClearCache; - // key = Entity name ; value = Cache properties - private Map<String, CacheProperties> entitiesCacheProperties; + private List<Entity> entities; // ********** constructors ********** public EclipseLinkCaching(PersistenceUnit parent) { @@ -44,8 +45,7 @@ public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties @Override protected void initializeProperties() { // TOREVIEW - handle incorrect String in persistence.xml - this.entitiesCacheProperties = - new HashMap<String, CacheProperties>(); + this.entities = new ArrayList<Entity>(); this.cacheTypeDefault = this.getEnumValue(ECLIPSELINK_CACHE_TYPE_DEFAULT, CacheType.values()); this.cacheSizeDefault = @@ -67,24 +67,21 @@ public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties this.initializeEntitiesSharedCache(sharedCacheProperties); } - private void initializeEntitiesCacheType(Set<PersistenceUnit.Property> properties) { - for (PersistenceUnit.Property property : properties) { - String entityName = this.getEntityName(property); - this.setCacheType_(property.getValue(), entityName); + private void initializeEntitiesCacheType(Set<PersistenceUnit.Property> cacheTypeProperties) { + for (PersistenceUnit.Property cacheTypeProperty : cacheTypeProperties) { + this.setEntityCacheTypeOf(cacheTypeProperty); } } - private void initializeEntitiesCacheSize(Set<PersistenceUnit.Property> properties) { - for (PersistenceUnit.Property property : properties) { - String entityName = this.getEntityName(property); - this.setCacheSize_(property.getValue(), entityName); + private void initializeEntitiesCacheSize(Set<PersistenceUnit.Property> cacheSizeProperties) { + for (PersistenceUnit.Property cacheSizeProperty : cacheSizeProperties) { + this.setEntityCacheSizeOf(cacheSizeProperty); } } - private void initializeEntitiesSharedCache(Set<PersistenceUnit.Property> properties) { - for (PersistenceUnit.Property property : properties) { - String entityName = this.getEntityName(property); - this.setSharedCache_(property.getValue(), entityName); + private void initializeEntitiesSharedCache(Set<PersistenceUnit.Property> sharedCacheProperties) { + for (PersistenceUnit.Property sharedCacheProperty : sharedCacheProperties) { + this.setEntitySharedCacheOf(sharedCacheProperty); } } @@ -184,9 +181,9 @@ public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties * property. */ @Override - public String propertyIdFor(PersistenceUnit.Property property) { + public String propertyIdOf(PersistenceUnit.Property property) { try { - return super.propertyIdFor(property); + return super.propertyIdOf(property); } catch (IllegalArgumentException e) { if (property.getName().startsWith(ECLIPSELINK_CACHE_TYPE)) { @@ -201,23 +198,42 @@ public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties } throw new IllegalArgumentException("Illegal property: " + property.toString()); } + + public Entity addEntity(String entityName) { + if (this.entityExists(entityName)) { + throw new IllegalStateException("Entity " + entityName + " already exists."); + } + Entity newEntity = this.buildEntity(entityName); + this.entities.add(newEntity); + this.fireListChanged(ENTITIES_LIST_PROPERTY); + return newEntity; + } + + public void removeEntity(String entityName) { + if ( ! this.entityExists(entityName)) { + return; + } + Entity entity = this.getEntityNamed(entityName); + this.clearEntity(entity); + this.removeEntity(entity); + } // ********** CacheType ********** - public CacheType getCacheType(String entityName) { - CacheProperties cache = this.cachePropertiesOf(entityName); - return (cache == null) ? null : cache.getType(); + public CacheType getCacheTypeOf(String entityName) { + Entity entity = this.getEntityNamed(entityName); + return (entity == null) ? null : entity.getCacheType(); } - public void setCacheType(CacheType newCacheType, String entityName) { - CacheProperties old = this.setCacheType_(newCacheType, entityName); + public void setCacheTypeOf(String entityName, CacheType newCacheType) { + Entity old = this.setEntityCacheTypeOf(entityName, newCacheType); this.putEnumValue(ECLIPSELINK_CACHE_TYPE, entityName, newCacheType, false); - this.firePropertyChanged(CACHE_TYPE_PROPERTY, old, this.cachePropertiesOf(entityName)); + this.firePropertyChanged(CACHE_TYPE_PROPERTY, old, this.getEntityNamed(entityName)); } private void cacheTypeChanged(String propertyName, String stringValue) { - String entityName = this.getEntityName(propertyName); - CacheProperties old = this.setCacheType_(stringValue, entityName); - this.firePropertyChanged(CACHE_TYPE_PROPERTY, old, this.cachePropertiesOf(entityName)); + String entityName = this.extractEntityNameOf(propertyName); + Entity old = this.setEntityCacheTypeOf(entityName, stringValue); + this.firePropertyChanged(CACHE_TYPE_PROPERTY, old, this.getEntityNamed(entityName)); } public CacheType getDefaultCacheType() { @@ -225,21 +241,21 @@ public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties } // ********** CacheSize ********** - public Integer getCacheSize(String entityName) { - CacheProperties cache = this.cachePropertiesOf(entityName); - return (cache == null) ? null : cache.getSize(); + public Integer getCacheSizeOf(String entityName) { + Entity entity = this.getEntityNamed(entityName); + return (entity == null) ? null : entity.getCacheSize(); } - public void setCacheSize(Integer newCacheSize, String entityName) { - CacheProperties old = this.setCacheSize_(newCacheSize, entityName); + public void setCacheSizeOf(String entityName, Integer newCacheSize) { + Entity old = this.setEntityCacheSizeOf(entityName, newCacheSize); this.putIntegerValue(ECLIPSELINK_CACHE_SIZE + entityName, newCacheSize); - this.firePropertyChanged(CACHE_SIZE_PROPERTY, old, this.cachePropertiesOf(entityName)); + this.firePropertyChanged(CACHE_SIZE_PROPERTY, old, this.getEntityNamed(entityName)); } private void cacheSizeChanged(String propertyName, String stringValue) { - String entityName = this.getEntityName(propertyName); - CacheProperties old = this.setCacheSize_(stringValue, entityName); - this.firePropertyChanged(CACHE_SIZE_PROPERTY, old, this.cachePropertiesOf(entityName)); + String entityName = this.extractEntityNameOf(propertyName); + Entity old = this.setEntityCacheSizeOf(entityName, stringValue); + this.firePropertyChanged(CACHE_SIZE_PROPERTY, old, this.getEntityNamed(entityName)); } public Integer getDefaultCacheSize() { @@ -247,21 +263,21 @@ public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties } // ********** SharedCache ********** - public Boolean getSharedCache(String entityName) { - CacheProperties cache = this.cachePropertiesOf(entityName); - return (cache == null) ? null : cache.isShared(); + public Boolean getSharedCacheOf(String entityName) { + Entity entity = this.getEntityNamed(entityName); + return (entity == null) ? null : entity.cacheIsShared(); } - public void setSharedCache(Boolean newSharedCache, String entityName) { - CacheProperties old = this.setSharedCache_(newSharedCache, entityName); + public void setSharedCacheOf(String entityName, Boolean newSharedCache) { + Entity old = this.setEntitySharedCacheOf(entityName, newSharedCache); this.putBooleanValue(ECLIPSELINK_SHARED_CACHE, entityName, newSharedCache, false); - this.firePropertyChanged(SHARED_CACHE_PROPERTY, old, this.cachePropertiesOf(entityName)); + this.firePropertyChanged(SHARED_CACHE_PROPERTY, old, this.getEntityNamed(entityName)); } private void sharedCacheChanged(String propertyName, String stringValue) { - String entityName = this.getEntityName(propertyName); - CacheProperties old = this.setSharedCache_(stringValue, entityName); - this.firePropertyChanged(SHARED_CACHE_PROPERTY, old, this.cachePropertiesOf(entityName)); + String entityName = this.extractEntityNameOf(propertyName); + Entity old = this.setEntitySharedCacheOf(entityName, stringValue); + this.firePropertyChanged(SHARED_CACHE_PROPERTY, old, this.getEntityNamed(entityName)); } public Boolean getDefaultSharedCache() { @@ -362,160 +378,172 @@ public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties return DEFAULT_FLUSH_CLEAR_CACHE; } - // ****** CacheProperties ******* + // ****** Entity CacheType ******* /** - * Convenience method to update the CacheType in entitiesCache map. Returns - * the old value of CacheProperties + * Returns the old Entity */ - private CacheProperties setCacheType_(String stringValue, String entityName) { + private Entity setEntityCacheTypeOf(String entityName, String stringValue) { CacheType newValue = getEnumValueOf(stringValue, CacheType.values()); - return this.setCacheType_(newValue, entityName); + return this.setEntityCacheTypeOf(entityName, newValue); } - private CacheProperties setCacheType_(CacheType newValue, String entityName) { - CacheProperties properties = this.cachePropertiesOf(entityName); - CacheProperties old = properties.clone(); - properties.setType(newValue); - this.putEntityCacheProperties(entityName, properties); - return old; + /** + * Returns the old Entity + */ + private Entity setEntityCacheTypeOf(String entityName, CacheType cacheType) { + Entity entity = (this.entityExists(entityName)) ? + this.getEntityNamed(entityName) : + this.addEntity(entityName); + return this.setEntityCacheTypeOf(entity, cacheType); } /** - * Convenience method to update the CacheSize in entitiesCache map. Returns - * the old value of CacheProperties + * Returns the old Entity */ - private CacheProperties setCacheSize_(String stringValue, String entityName) { - Integer newValue = getIntegerValueOf(stringValue); - return this.setCacheSize_(newValue, entityName); + private Entity setEntityCacheTypeOf(Entity entity, CacheType cacheType) { + if(entity == null) { + throw new IllegalArgumentException(); + } + Entity old = entity.clone(); + entity.setCacheType(cacheType); + return old; } - private CacheProperties setCacheSize_(Integer newValue, String entityName) { - CacheProperties properties = this.cachePropertiesOf(entityName); - CacheProperties old = properties.clone(); - properties.setSize(newValue); - this.putEntityCacheProperties(entityName, properties); - return old; + private void setEntityCacheTypeOf(PersistenceUnit.Property cacheTypeProperty) { + String entityName = this.extractEntityNameOf(cacheTypeProperty); + this.setEntityCacheTypeOf(entityName, cacheTypeProperty.getValue()); } + // ****** Entity Cache size ******* /** - * Convenience method to update the SharedCache in entitiesCacheProperties map. - * Returns the old value of CacheProperties + * Returns the old Entity */ - private CacheProperties setSharedCache_(String newString, String entityName) { - Boolean newValue = getBooleanValueOf(newString); - return setSharedCache_(newValue, entityName); + private Entity setEntityCacheSizeOf(String entityName, String stringValue) { + Integer newValue = getIntegerValueOf(stringValue); + return this.setEntityCacheSizeOf(entityName, newValue); } - private CacheProperties setSharedCache_(Boolean newValue, String entityName) { - CacheProperties properties = this.cachePropertiesOf(entityName); - CacheProperties old = properties.clone(); - properties.setShared(newValue); - this.putEntityCacheProperties(entityName, properties); - return old; + /** + * Returns the old Entity + */ + private Entity setEntityCacheSizeOf(String entityName, Integer size) { + Entity entity = (this.entityExists(entityName)) ? + this.getEntityNamed(entityName) : + this.addEntity(entityName); + return this.setEntityCacheSizeOf(entity, size); } /** - * Returns the CacheProperties of the Entity with the given name. + * Returns the old Entity */ - private CacheProperties cachePropertiesOf(String entityName) { - CacheProperties properties = this.entitiesCacheProperties.get(entityName); - if (properties == null) { - properties = new CacheProperties(entityName); + private Entity setEntityCacheSizeOf(Entity entity, Integer size) { + if(entity == null) { + throw new IllegalArgumentException(); } - return properties; + Entity old = entity.clone(); + entity.setCacheSize(size); + return old; } + private void setEntityCacheSizeOf(PersistenceUnit.Property cacheSizeProperty) { + String entityName = this.extractEntityNameOf(cacheSizeProperty); + this.setEntityCacheSizeOf(entityName, cacheSizeProperty.getValue()); + } + + // ****** Entity SharedCache ******* /** - * Set all CacheProperties to default. + * Returns the old Entity */ - private void clearCacheProperties(String entityName) { - this.setCacheType(null, entityName); - this.setCacheSize(null, entityName); - this.setSharedCache(null, entityName); + private Entity setEntitySharedCacheOf(String entityName, String stringValue) { + Boolean newValue = getBooleanValueOf(stringValue); + return this.setEntitySharedCacheOf(entityName, newValue); } - // ****** 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 + * Returns the old Entity */ - private void putEntityCacheProperties(String entityName, CacheProperties properties) { - this.addOrReplacePropertiesForEntity(entityName, properties); + private Entity setEntitySharedCacheOf(String entityName, Boolean sharedCache) { + Entity entity = (this.entityExists(entityName)) ? + this.getEntityNamed(entityName) : + this.addEntity(entityName); + return this.setEntitySharedCacheOf(entity, sharedCache); } - // ****** entities list ******* - - public ListIterator<String> entities() { - return CollectionTools.list(this.entitiesCacheProperties.keySet()).listIterator(); + /** + * Returns the old Entity + */ + private Entity setEntitySharedCacheOf(Entity entity, Boolean sharedCache) { + if(entity == null) { + throw new IllegalArgumentException(); + } + Entity old = entity.clone(); + entity.setSharedCache(sharedCache); + return old; } - public int entitiesSize() { - return this.entitiesCacheProperties.size(); + private void setEntitySharedCacheOf(PersistenceUnit.Property sharedCacheProperty) { + String entityName = this.extractEntityNameOf(sharedCacheProperty); + this.setEntitySharedCacheOf(entityName, sharedCacheProperty.getValue()); } - /* - * Verifies if this entitiesCacheProperties map contains the given Entity. - */ - public boolean entityExists(String entity) { - return this.entitiesCacheProperties.containsKey(entity); - } + // ****** convenience methods ******* - public String addEntity(String entity) { - if (entityExists(entity)) { - throw new IllegalStateException("Entity " + entity + " already exists."); + /** + * Set all Entity properties to default. + */ + private void clearEntity(Entity entity) { + if(entity.isEmpty()) { + return; } - return this.addOrReplacePropertiesForEntity(entity, new CacheProperties(entity)); + String entityName = entity.getName(); + this.setCacheTypeOf(entityName, null); + this.setCacheSizeOf(entityName, null); + this.setSharedCacheOf(entityName, null); } /** - * 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 + * Returns the Entity with the given name. */ - private String addOrReplacePropertiesForEntity(String entity, CacheProperties properties) { - if (this.entityExists(entity)) { - this.replaceEntity_(entity, properties); - return null; + private Entity getEntityNamed(String name) { + for(Entity entity: this.entities) { + if(entity.getName().equals(name)) { + return entity; + } + } + return null; + } + + private Entity buildEntity(String name) { + return new Entity(this, name); + } + + private void removeEntity(Entity entity) { + if(entity == null) { + throw new IllegalArgumentException(); } - this.entitiesCacheProperties.put(entity, properties); + this.entities.remove(entity); this.fireListChanged(ENTITIES_LIST_PROPERTY); - 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 + * Return whether the Entity exist. */ - private CacheProperties replaceEntity_(String entity, CacheProperties properties) { - CacheProperties old = this.entitiesCacheProperties.get(entity); - if (properties.isEmpty()) { - this.entitiesCacheProperties.remove(entity); - this.fireListChanged(ENTITIES_LIST_PROPERTY); - } - else { - this.entitiesCacheProperties.put(entity, properties); + public boolean entityExists(String name) { + for(Entity entity: this.entities) { + if(entity.getName().equals(name)) { + return true; + } } - return old; + return false; } - public void removeEntity(String entity) { - if ( ! this.entityExists(entity)) { - return; - } - this.clearCacheProperties(entity); - this.entitiesCacheProperties.remove(entity); - this.fireListChanged(ENTITIES_LIST_PROPERTY); + // ****** entities list ******* + + public ListIterator<Entity> entities() { + return new CloneListIterator<Entity>(this.entities); + } + + public int entitiesSize() { + return this.entities.size(); } } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/Entity.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/Entity.java new file mode 100644 index 0000000000..94953344b5 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/Entity.java @@ -0,0 +1,141 @@ +/******************************************************************************* +* Copyright (c) 2009 Oracle. All rights reserved. +* This program and the accompanying materials are made available under the +* terms of the Eclipse Public License v1.0, which accompanies this distribution +* and is available at http://www.eclipse.org/legal/epl-v10.html. +* +* Contributors: +* Oracle - initial API and implementation +*******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching; + +import java.io.Serializable; + +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.model.AbstractModel; + +/** + * Entity + */ +public class Entity extends AbstractModel implements Cloneable, Serializable +{ + private String name; + private Caching parent; + + public static final String CACHE_TYPE_PROPERTY = Caching.CACHE_TYPE_PROPERTY; //$NON-NLS-1$ + public static final String CACHE_SIZE_PROPERTY = Caching.CACHE_SIZE_PROPERTY; //$NON-NLS-1$ + public static final String SHARED_CACHE_PROPERTY = Caching.SHARED_CACHE_PROPERTY; //$NON-NLS-1$ + + // ********** EclipseLink properties ********** + private CacheType cacheType; + private Integer cacheSize; + private Boolean cacheIsShared; + + private static final long serialVersionUID = 1L; + + // ********** constructors ********** + public Entity(Caching parent, String name) { + this(parent); + this.initialize(name); + } + + private Entity(Caching parent) { + this.parent = parent; + } + + private void initialize(String name) { + if(StringTools.stringIsEmpty(name)) { + throw new IllegalArgumentException(); + } + this.name = name; + } + + // ********** behaviors ********** + @Override + public boolean equals(Object o) { + if(o == null) { + return false; + } + Entity entity = (Entity) o; + return ( + (this.cacheType == null ? + entity.cacheType == null : this.cacheType.equals(entity.cacheType)) && + (this.cacheIsShared == null ? + entity.cacheIsShared == null : this.cacheIsShared.equals(entity.cacheIsShared)) && + (this.cacheSize == null ? + entity.cacheSize == null : this.cacheSize.equals(entity.cacheSize))); + } + + @Override + public Entity clone() { + try { + return (Entity)super.clone(); + } + catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + public boolean isEmpty() { + return (this.cacheType == null) && + (this.cacheSize == null) && + (this.cacheIsShared == null); + } + + public boolean entityNameIsValid() { + return ! StringTools.stringIsEmpty(this.name); + } + + public Caching getParent() { + return this.parent; + } + + // ********** name ********** + public String getName() { + return name; + } + + // ********** cacheType ********** + protected CacheType getCacheType() { + return this.cacheType; + } + + protected void setCacheType(CacheType cacheType) { + CacheType old = this.cacheType; + this.cacheType = cacheType; + this.firePropertyChanged(CACHE_TYPE_PROPERTY, old, cacheType); + } + + // ********** cacheSize ********** + protected Integer getCacheSize() { + return this.cacheSize; + } + + protected void setCacheSize(Integer cacheSize) { + Integer old = this.cacheSize; + this.cacheSize = cacheSize; + this.firePropertyChanged(CACHE_SIZE_PROPERTY, old, cacheSize); + } + + // ********** cacheIsShared ********** + protected Boolean cacheIsShared() { + return this.cacheIsShared; + } + + protected void setSharedCache(Boolean isShared) { + Boolean old = this.cacheIsShared; + this.cacheIsShared = isShared; + this.firePropertyChanged(SHARED_CACHE_PROPERTY, old, isShared); + } + + public void toString(StringBuilder sb) { + sb.append("name: "); + sb.append(this.name); + sb.append(", cacheType: "); + sb.append(this.cacheType); + sb.append(", cacheSize: "); + sb.append(this.cacheSize); + sb.append(", cacheIsShared: "); + sb.append(this.cacheIsShared); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/Customization.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/Customization.java index 9b16b72172..d5b1696a24 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/Customization.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/Customization.java @@ -75,8 +75,8 @@ public interface Customization extends PersistenceUnitProperties static final Boolean DEFAULT_WEAVING_EAGER = Boolean.FALSE; String getDefaultDescriptorCustomizer(); - String getDescriptorCustomizer(String entityName); - void setDescriptorCustomizer(String newDescriptorCustomizer, String entityName); + String getDescriptorCustomizerOf(String entityName); + void setDescriptorCustomizerOf(String entityName, String newDescriptorCustomizer); static final String DESCRIPTOR_CUSTOMIZER_PROPERTY = "descriptorCustomizer"; //$NON-NLS-1$ // EclipseLink key string static final String ECLIPSELINK_DESCRIPTOR_CUSTOMIZER = "eclipselink.descriptor.customizer."; //$NON-NLS-1$ @@ -92,10 +92,10 @@ public interface Customization extends PersistenceUnitProperties // EclipseLink key string static final String ECLIPSELINK_SESSION_CUSTOMIZER = "eclipselink.session.customizer"; //$NON-NLS-1$ - ListIterator<String> entities(); + ListIterator<Entity> entities(); int entitiesSize(); boolean entityExists(String entity); - String addEntity(String entity); + Entity addEntity(String entity); void removeEntity(String entity); static final String ENTITIES_LIST_PROPERTY = "entities"; //$NON-NLS-1$ diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/CustomizerProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/CustomizerProperties.java deleted file mode 100644 index a78c1d6662..0000000000 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/CustomizerProperties.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization; - -import java.io.Serializable; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * CustomizerProperties - */ -public class CustomizerProperties implements Cloneable, Serializable -{ - private String entityName; - - // ********** EclipseLink properties ********** - private String className; - - private static final long serialVersionUID = 1L; - - // ********** constructors ********** - public CustomizerProperties(String entityName) { - this.entityName = entityName; - } - - // ********** behaviors ********** - @Override - public boolean equals(Object o) { - if(o == null) { - return false; - } - CustomizerProperties customizer = (CustomizerProperties) o; - return ( - (this.className == null ? - customizer.className == null : this.className.equals(customizer.className))); - } - - @Override - public CustomizerProperties clone() { - try { - return (CustomizerProperties)super.clone(); - } - catch (CloneNotSupportedException ex) { - throw new InternalError(); - } - } - - public boolean isEmpty() { - return this.className == null; - } - - // ********** getter/setter ********** - public String getEntityName() { - return this.entityName; - } - - public String getClassName() { - return this.className; - } - - public void setClassName(String newClassName) { - this.className = newClassName; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - StringTools.buildSimpleToStringOn(this, sb); - sb.append(" ("); - this.toString(sb); - sb.append(')'); - return sb.toString(); - } - - public void toString(StringBuilder sb) { - sb.append(" class: "); - sb.append(this.className); - sb.append(", entityName: "); - sb.append(this.entityName); - } -}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/EclipseLinkCustomization.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/EclipseLinkCustomization.java index bb656bb68e..191abb52d0 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/EclipseLinkCustomization.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/EclipseLinkCustomization.java @@ -10,13 +10,13 @@ package org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization; import java.util.ArrayList; -import java.util.HashMap; +import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Set; + import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnitProperties; -import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; /** @@ -34,12 +34,11 @@ public class EclipseLinkCustomization extends EclipseLinkPersistenceUnitProperti private Boolean weavingInternal; private Boolean weavingEager; private Boolean validationOnly; - private ArrayList<String> sessionCustomizers; + private List<String> sessionCustomizers; private String profiler; // storing EclipseLinkStringValue since value can be Profiler or custom class private String exceptionHandler; - // key = Entity name ; value = Customizer properties - private Map<String, CustomizerProperties> entitiesCustomizerProperties; + private List<Entity> entities; // ********** constructors ********** public EclipseLinkCustomization(PersistenceUnit parent) { @@ -53,8 +52,7 @@ public class EclipseLinkCustomization extends EclipseLinkPersistenceUnitProperti @Override protected void initializeProperties() { // TOREVIEW - handle incorrect String in persistence.xml - this.entitiesCustomizerProperties = - new HashMap<String, CustomizerProperties>(); + this.entities = new ArrayList<Entity>(); this.throwExceptions = this.getBooleanValue(ECLIPSELINK_THROW_EXCEPTIONS); @@ -97,10 +95,9 @@ public class EclipseLinkCustomization extends EclipseLinkPersistenceUnitProperti } } - private void initializeEntitiesCustomizerClass(Set<PersistenceUnit.Property> properties) { - for (PersistenceUnit.Property property : properties) { - String entityName = this.getEntityName(property); - this.setCustomizerClass_(property, entityName); + private void initializeEntitiesCustomizerClass(Set<PersistenceUnit.Property> descriptorCustomizerProperties) { + for (PersistenceUnit.Property descriptorCustomizerProperty : descriptorCustomizerProperties) { + this.setEntityDescriptorCustomizerOf(descriptorCustomizerProperty); } } @@ -263,9 +260,9 @@ public class EclipseLinkCustomization extends EclipseLinkPersistenceUnitProperti * property. */ @Override - public String propertyIdFor(PersistenceUnit.Property property) { + public String propertyIdOf(PersistenceUnit.Property property) { try { - return super.propertyIdFor(property); + return super.propertyIdOf(property); } catch (IllegalArgumentException e) { if (property.getName().startsWith(ECLIPSELINK_DESCRIPTOR_CUSTOMIZER)) { @@ -274,6 +271,25 @@ public class EclipseLinkCustomization extends EclipseLinkPersistenceUnitProperti } throw new IllegalArgumentException("Illegal property: " + property); //$NON-NLS-1$ } + + public Entity addEntity(String entityName) { + if (this.entityExists(entityName)) { + throw new IllegalStateException("Entity " + entityName + " already exists."); + } + Entity newEntity = this.buildEntity(entityName); + this.entities.add(newEntity); + this.fireListChanged(ENTITIES_LIST_PROPERTY); + return newEntity; + } + + public void removeEntity(String entityName) { + if ( ! this.entityExists(entityName)) { + return; + } + Entity entity = this.getEntityNamed(entityName); + this.clearEntity(entity); + this.removeEntity(entity); + } // ********** ThrowExceptions ********** @@ -548,148 +564,56 @@ public class EclipseLinkCustomization extends EclipseLinkPersistenceUnitProperti // ********** DescriptorCustomizer ********** - public String getDescriptorCustomizer(String entityName) { - CustomizerProperties customizer = this.customizerPropertiesOf(entityName); - return (customizer == null) ? null : customizer.getClassName(); + public String getDescriptorCustomizerOf(String entityName) { + Entity entity = this.getEntityNamed(entityName); + return (entity == null) ? null : entity.getDescriptorCustomizer(); } - public void setDescriptorCustomizer(String newDescriptorCustomizer, String entityName) { - CustomizerProperties old = this.setCustomizerClass_(newDescriptorCustomizer, entityName); + public void setDescriptorCustomizerOf(String entityName, String newDescriptorCustomizer) { + Entity old = this.setEntityDescriptorCustomizerOf(entityName, newDescriptorCustomizer); this.putStringValue(ECLIPSELINK_DESCRIPTOR_CUSTOMIZER, entityName, newDescriptorCustomizer, false); - this.firePropertyChanged(DESCRIPTOR_CUSTOMIZER_PROPERTY, old, this.customizerPropertiesOf(entityName)); + this.firePropertyChanged(DESCRIPTOR_CUSTOMIZER_PROPERTY, old, this.getEntityNamed(entityName)); } - + private void descriptorCustomizerChanged(String propertyName, String stringValue) { - String entityName = this.getEntityName(propertyName); - CustomizerProperties old = this.setCustomizerClass_(stringValue, entityName); - this.firePropertyChanged(DESCRIPTOR_CUSTOMIZER_PROPERTY, old, this.customizerPropertiesOf(entityName)); + String entityName = this.extractEntityNameOf(propertyName); + Entity old = this.setEntityDescriptorCustomizerOf(entityName, stringValue); + this.firePropertyChanged(DESCRIPTOR_CUSTOMIZER_PROPERTY, old, this.getEntityNamed(entityName)); } public String getDefaultDescriptorCustomizer() { return DEFAULT_DESCRIPTOR_CUSTOMIZER; } - - // ****** CustomizerProperties ******* - - /** - * Convenience method to update the CustomizerClass in entitiesCustomizerProperties map. - * Returns the old value of CustomizerProperties - */ - private CustomizerProperties setCustomizerClass_(PersistenceUnit.Property newProperty, String entityName) { - String newValue = (newProperty == null) ? null : newProperty.getValue(); - return this.setCustomizerClass_(newValue, entityName); - } - - private CustomizerProperties setCustomizerClass_(String newValue, String entityName) { - CustomizerProperties properties = this.customizerPropertiesOf(entityName); - CustomizerProperties old = properties.clone(); - properties.setClassName(newValue); - this.putEntityCustomizerProperties(entityName, properties); - return old; - } - - /** - * Returns the CustomizerProperties of the Entity with the given name. - */ - private CustomizerProperties customizerPropertiesOf(String entityName) { - CustomizerProperties properties = this.entitiesCustomizerProperties.get(entityName); - if (properties == null) { - properties = new CustomizerProperties(entityName); - } - return properties; - } - - /** - * Set all CustomizerProperties to default. - */ - private void clearCustomizerProperties(String entityName) { - this.setDescriptorCustomizer(null, entityName); - } - - // ****** convenience methods ******* /** - * Put the given Entity CustomizerProperties in this entitiesCustomizerProperties map. - * @param entityName - Entity name. The entity may be a new or an existing entity. - * @param properties - Entity CustomizerProperties + * Returns the old Entity */ - private void putEntityCustomizerProperties(String entityName, CustomizerProperties properties) { - this.addOrReplacePropertiesForEntity(entityName, properties); + private Entity setEntityDescriptorCustomizerOf(String entityName, String descriptorCustomizerClassName) { + Entity entity = (this.entityExists(entityName)) ? + this.getEntityNamed(entityName) : + this.addEntity(entityName); + return this.setEntityDescriptorCustomizerOf(entity, descriptorCustomizerClassName); } - - - // ****** entities list ******* - - public ListIterator<String> entities() { - return CollectionTools.list(this.entitiesCustomizerProperties.keySet()).listIterator(); - } - - public int entitiesSize() { - return this.entitiesCustomizerProperties.size(); - } - - /* - * Verifies if this entitiesCacheProperties map contains the given Entity. - */ - public boolean entityExists(String entity) { - return this.entitiesCustomizerProperties.containsKey(entity); - } - - public String addEntity(String entity) { - if (entityExists(entity)) { - throw new IllegalStateException("Entity already exists: " + entity); //$NON-NLS-1$ - } - return this.addOrReplacePropertiesForEntity(entity, new CustomizerProperties(entity)); - } - /** - * Adds or Replaces the given Entity CustomizerProperties in - * this entitiesCustomizerProperties map. - * If the specified Entity exists and the given CustomizerProperties is empty - * (i.e. all properties are null) the mapping will be removed from the map. - * @param entity - Entity name - * @param properties - Entity CustomizerProperties - * @return + * Returns the old Entity */ - private String addOrReplacePropertiesForEntity(String entity, CustomizerProperties properties) { - if (entityExists(entity)) { - this.replaceEntity_(entity, properties); - return null; + private Entity setEntityDescriptorCustomizerOf(Entity entity, String descriptorCustomizerClassName) { + if(entity == null) { + throw new IllegalArgumentException(); } - this.entitiesCustomizerProperties.put(entity, properties); - this.fireListChanged(ENTITIES_LIST_PROPERTY); - return entity; + Entity old = entity.clone(); + entity.setDescriptorCustomizer(descriptorCustomizerClassName); + return old; } - + /** - * Replaces the given Entity CustomizerProperties in this - * entitiesCustomizerProperties map. - * If the Entity CustomizerProperties is empty (i.e. all properties is null) the - * mapping will be removed from the map. - * @param entity - Entity name - * @param properties - Entity CustomizerProperties - * @return + * Convenience method to update the descriptorCustomizerClassName in entities. + * Returns the old Entity */ - private CustomizerProperties replaceEntity_(String entity, CustomizerProperties properties) { - CustomizerProperties old = this.entitiesCustomizerProperties.get(entity); - if (properties.isEmpty()) { - this.entitiesCustomizerProperties.remove(entity); - this.fireListChanged(ENTITIES_LIST_PROPERTY); - } - else { - this.entitiesCustomizerProperties.put(entity, properties); - } - return old; - } - - public void removeEntity(String entity) { - if ( ! entityExists(entity)) { - return; - } - this.clearCustomizerProperties(entity); - this.entitiesCustomizerProperties.remove(entity); - this.fireListChanged(ENTITIES_LIST_PROPERTY); + private Entity setEntityDescriptorCustomizerOf(PersistenceUnit.Property descriptorCustomizerProperty) { + String entityName = this.extractEntityNameOf(descriptorCustomizerProperty); + return this.setEntityDescriptorCustomizerOf(entityName, descriptorCustomizerProperty.getValue()); } // ********** Profiler ********** @@ -753,4 +677,63 @@ public class EclipseLinkCustomization extends EclipseLinkPersistenceUnitProperti return DEFAULT_PROFILER; } -}
\ No newline at end of file + + // ****** convenience methods ******* + + /** + * Set all Entity properties to default. + */ + private void clearEntity(Entity entity) { + if(entity.isEmpty()) { + return; + } + String entityName = entity.getName(); + this.setDescriptorCustomizerOf(entityName, null); + } + + /** + * Returns the Entity with the given name. + */ + private Entity getEntityNamed(String name) { + for(Entity entity: this.entities) { + if(entity.getName().equals(name)) { + return entity; + } + } + return null; + } + + private Entity buildEntity(String name) { + return new Entity(this, name); + } + + private void removeEntity(Entity entity) { + if(entity == null) { + throw new IllegalArgumentException(); + } + this.entities.remove(entity); + this.fireListChanged(ENTITIES_LIST_PROPERTY); + } + + /** + * Return whether the Entity exist. + */ + public boolean entityExists(String name) { + for(Entity entity: this.entities) { + if(entity.getName().equals(name)) { + return true; + } + } + return false; + } + + // ****** entities list ******* + + public ListIterator<Entity> entities() { + return new CloneListIterator<Entity>(this.entities); + } + + public int entitiesSize() { + return this.entities.size(); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/Entity.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/Entity.java new file mode 100644 index 0000000000..433d44b178 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/Entity.java @@ -0,0 +1,105 @@ +/******************************************************************************* +* Copyright (c) 2009 Oracle. All rights reserved. +* This program and the accompanying materials are made available under the +* terms of the Eclipse Public License v1.0, which accompanies this distribution +* and is available at http://www.eclipse.org/legal/epl-v10.html. +* +* Contributors: +* Oracle - initial API and implementation +*******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization; + +import java.io.Serializable; + +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.model.AbstractModel; + +/** + * Entity + */ +public class Entity extends AbstractModel implements Cloneable, Serializable +{ + private String name; + private Customization parent; + + public static final String DESCRIPTOR_CUSTOMIZER_PROPERTY = Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY; //$NON-NLS-1$ + + // ********** EclipseLink properties ********** + private String descriptorCustomizer; + + private static final long serialVersionUID = 1L; + + // ********** constructors ********** + public Entity(Customization parent, String name) { + this(parent); + this.initialize(name); + } + + private Entity(Customization parent) { + this.parent = parent; + } + + private void initialize(String name) { + if(StringTools.stringIsEmpty(name)) { + throw new IllegalArgumentException(); + } + this.name = name; + } + + // ********** behaviors ********** + @Override + public boolean equals(Object o) { + if(o == null) { + return false; + } + Entity customizer = (Entity) o; + return ( + (this.descriptorCustomizer == null ? + customizer.descriptorCustomizer == null : + this.descriptorCustomizer.equals(customizer.descriptorCustomizer))); + } + + @Override + public Entity clone() { + try { + return (Entity)super.clone(); + } + catch (CloneNotSupportedException ex) { + throw new InternalError(); + } + } + + public boolean isEmpty() { + return this.descriptorCustomizer == null; + } + + public boolean entityNameIsValid() { + return ! StringTools.stringIsEmpty(this.name); + } + + public Customization getParent() { + return this.parent; + } + + // ********** getter/setter ********** + public String getName() { + return this.name; + } + + protected String getDescriptorCustomizer() { + return this.descriptorCustomizer; + } + + protected void setDescriptorCustomizer(String descriptorCustomizer) { + String old = this.descriptorCustomizer; + this.descriptorCustomizer = descriptorCustomizer; + this.firePropertyChanged(DESCRIPTOR_CUSTOMIZER_PROPERTY, old, descriptorCustomizer); + } + + public void toString(StringBuilder sb) { + sb.append("name: "); + sb.append(this.name); + sb.append(", descriptorCustomizer: "); + sb.append(this.descriptorCustomizer); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/CacheSizeComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/CacheSizeComposite.java index 92cd039eee..eaf471cac5 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/CacheSizeComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/CacheSizeComposite.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.eclipselink.ui.internal.persistence.caching; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Caching; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Entity; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkHelpContextIds; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkUiMessages; import org.eclipse.jpt.ui.internal.widgets.IntegerCombo; @@ -23,7 +24,7 @@ import org.eclipse.swt.widgets.Composite; /** * CacheSizeComposite */ -public class CacheSizeComposite extends Pane<EntityCacheProperties> +public class CacheSizeComposite extends Pane<Entity> { /** * Creates a new <code>CacheTypeComposite</code>. @@ -33,7 +34,7 @@ public class CacheSizeComposite extends Pane<EntityCacheProperties> * @param parent * The parent container */ - public CacheSizeComposite(Pane<EntityCacheProperties> parentComposite, + public CacheSizeComposite(Pane<Entity> parentComposite, Composite parent) { super(parentComposite, parent); @@ -41,11 +42,11 @@ public class CacheSizeComposite extends Pane<EntityCacheProperties> @Override protected void initializeLayout(Composite container) { - addCacheSizeCombo(container); + this.addCacheSizeCombo(container); } private void addCacheSizeCombo(Composite container) { - new IntegerCombo<EntityCacheProperties>(this, container) { + new IntegerCombo<Entity>(this, container) { @Override protected String getLabelText() { @@ -73,26 +74,34 @@ public class CacheSizeComposite extends Pane<EntityCacheProperties> @Override protected WritablePropertyValueModel<Integer> buildSelectedItemHolder() { - return new PropertyAspectAdapter<EntityCacheProperties, Integer>(getSubjectHolder(), EntityCacheProperties.CACHE_SIZE_PROPERTY) { + return new PropertyAspectAdapter<Entity, Integer>(this.getSubjectHolder(), Entity.CACHE_SIZE_PROPERTY) { @Override protected Integer buildValue_() { - return this.subject.getCacheSize(); + return getSubjectParent().getCacheSizeOf(getSubjectName()); } @Override protected void setValue_(Integer value) { - this.subject.setCacheSize(value); + getSubjectParent().setCacheSizeOf(getSubjectName(), value); } }; } }; } + private String getSubjectName() { + return this.getSubjectHolder().getValue().getName(); + } + + private Caching getSubjectParent() { + return this.getSubjectHolder().getValue().getParent(); + } + private PropertyValueModel<Caching> buildCachingHolder() { - return new TransformationPropertyValueModel<EntityCacheProperties, Caching>(getSubjectHolder()) { + return new TransformationPropertyValueModel<Entity, Caching>(this.getSubjectHolder()) { @Override - protected Caching transform_(EntityCacheProperties value) { - return value.getCaching(); + protected Caching transform_(Entity value) { + return value.getParent(); } }; } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/CacheTypeComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/CacheTypeComposite.java index 15bf299e5e..926935c561 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/CacheTypeComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/CacheTypeComposite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. + * Copyright (c) 2008, 2009 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -12,6 +12,7 @@ package org.eclipse.jpt.eclipselink.ui.internal.persistence.caching; import java.util.Collection; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.CacheType; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Caching; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Entity; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkHelpContextIds; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkUiMessages; import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper; @@ -27,7 +28,7 @@ import org.eclipse.swt.widgets.Composite; /** * CacheTypeComposite */ -public class CacheTypeComposite extends Pane<EntityCacheProperties> +public class CacheTypeComposite extends Pane<Entity> { /** * Creates a new <code>CacheTypeComposite</code>. @@ -37,7 +38,7 @@ public class CacheTypeComposite extends Pane<EntityCacheProperties> * @param parent * The parent container */ - public CacheTypeComposite(Pane<EntityCacheProperties> parentComposite, + public CacheTypeComposite(Pane<Entity> parentComposite, Composite parent) { super(parentComposite, parent); @@ -54,7 +55,7 @@ public class CacheTypeComposite extends Pane<EntityCacheProperties> ); } - private class CacheTypeCombo extends EnumFormComboViewer<EntityCacheProperties, CacheType> { + private class CacheTypeCombo extends EnumFormComboViewer<Entity, CacheType> { private CacheTypeCombo(Composite parent) { super(CacheTypeComposite.this, parent); @@ -63,14 +64,14 @@ public class CacheTypeComposite extends Pane<EntityCacheProperties> @Override protected void addPropertyNames(Collection<String> propertyNames) { super.addPropertyNames(propertyNames); - propertyNames.add(EntityCacheProperties.CACHE_TYPE_PROPERTY); + propertyNames.add(Entity.CACHE_TYPE_PROPERTY); } private PropertyValueModel<Caching> buildCachingHolder() { - return new TransformationPropertyValueModel<EntityCacheProperties, Caching>(getSubjectHolder()) { + return new TransformationPropertyValueModel<Entity, Caching>(getSubjectHolder()) { @Override - protected Caching transform_(EntityCacheProperties value) { - return value.getCaching(); + protected Caching transform_(Entity value) { + return value.getParent(); } }; } @@ -111,7 +112,7 @@ public class CacheTypeComposite extends Pane<EntityCacheProperties> @Override protected CacheType getDefaultValue() { - return this.getSubject().getDefaultCacheType(); + return getSubjectParent().getDefaultCacheType(); } @Override @@ -132,7 +133,7 @@ public class CacheTypeComposite extends Pane<EntityCacheProperties> @Override protected CacheType getValue() { - return this.getSubject().getCacheType(); + return getSubjectParent().getCacheTypeOf(getSubjectName()); } @Override @@ -150,7 +151,7 @@ public class CacheTypeComposite extends Pane<EntityCacheProperties> @Override protected void setValue(CacheType value) { - this.getSubject().setCacheType(value); + getSubjectParent().setCacheTypeOf(getSubjectName(), value); } @Override @@ -158,4 +159,12 @@ public class CacheTypeComposite extends Pane<EntityCacheProperties> return false; } } + + private String getSubjectName() { + return this.getSubjectHolder().getValue().getName(); + } + + private Caching getSubjectParent() { + return this.getSubjectHolder().getValue().getParent(); + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/EntityCacheProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/EntityCacheProperties.java deleted file mode 100644 index edc16800f8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/EntityCacheProperties.java +++ /dev/null @@ -1,207 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.ui.internal.persistence.caching; - -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.CacheType; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.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 - */ -@SuppressWarnings("nls") -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; - - public static final String CACHE_TYPE_PROPERTY = Caching.CACHE_TYPE_PROPERTY; - public static final String CACHE_SIZE_PROPERTY = Caching.CACHE_SIZE_PROPERTY; - public static final String SHARED_CACHE_PROPERTY = Caching.SHARED_CACHE_PROPERTY; - - private static final long serialVersionUID = 1L; - - // ********** 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); - - this.engageListeners(); - } - - protected void initialize(PropertyValueModel<Caching> cachingHolder) { - this.cacheTypeHolder = this.buildCacheTypeAA(cachingHolder); - this.cacheTypeListener = this.buildCacheTypeChangeListener(); - - this.cacheSizeHolder = this.buildCacheSizeAA(cachingHolder); - this.cacheSizeListener = this.buildCacheSizeChangeListener(); - - this.sharedCacheHolder = this.buildSharedCacheAA(cachingHolder); - this.sharedCacheListener = this.buildSharedCacheChangeListener(); - } - - // ********** behavior ********** - public boolean entityNameIsValid() { - return !StringTools.stringIsEmpty(this.entityName); - } - - public Integer getCacheSize() { - return this.caching.getCacheSize(this.entityName); - } - - public CacheType getCacheType() { - return this.caching.getCacheType(this.entityName); - } - - public Caching getCaching() { - return caching; - } - - public Integer getDefaultCacheSize() { - return this.caching.getDefaultCacheSize(); - } - - public CacheType getDefaultCacheType() { - return this.caching.getDefaultCacheType(); - } - - public String getEntityName() { - return this.entityName; - } - - public Boolean getSharedCache() { - return this.caching.getSharedCache(this.entityName); - } - - public Boolean getDefaultSharedCache() { - return this.caching.getDefaultSharedCache(); - } - - public void setCacheSize(Integer cacheSize) { - Integer oldCacheSize = this.getCacheSize(); - if (this.attributeValueHasChanged(oldCacheSize, cacheSize)) { - this.caching.setCacheSize(cacheSize, this.entityName); - this.firePropertyChanged(CACHE_SIZE_PROPERTY, oldCacheSize, cacheSize); - } - } - - public void setCacheType(CacheType cacheType) { - CacheType oldCacheType = this.getCacheType(); - if (this.attributeValueHasChanged(oldCacheType, cacheType)) { - this.caching.setCacheType(cacheType, this.entityName); - this.firePropertyChanged(CACHE_TYPE_PROPERTY, oldCacheType, cacheType); - } - } - - public void setSharedCache(Boolean sharedCache) { - Boolean oldSharedCache = this.getSharedCache(); - if (this.attributeValueHasChanged(oldSharedCache, sharedCache)) { - this.caching.setSharedCache(sharedCache, this.entityName); - 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()); - } - }; - } - - public void engageListeners() { - this.cacheTypeHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.cacheTypeListener); - this.cacheSizeHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.cacheSizeListener); - this.sharedCacheHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.sharedCacheListener); - } - - public void disengageListeners() { - this.cacheTypeHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.cacheTypeListener); - this.cacheSizeHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.cacheSizeListener); - this.sharedCacheHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.sharedCacheListener); - } - - @Override - public void toString(StringBuilder sb) { - sb.append("name: "); - sb.append(this.entityName); - sb.append(", type: "); - sb.append(this.getCacheType()); - sb.append(", size: "); - sb.append(this.getCacheSize()); - sb.append(", isShared: "); - sb.append(this.getSharedCache()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/EntityCachingPropertyComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/EntityCachingPropertyComposite.java index f20ecfc047..9080e937cd 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/EntityCachingPropertyComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/EntityCachingPropertyComposite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. + * Copyright (c) 2008, 2009 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -10,6 +10,7 @@ package org.eclipse.jpt.eclipselink.ui.internal.persistence.caching; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Caching; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Entity; import org.eclipse.jpt.ui.internal.widgets.Pane; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; @@ -18,7 +19,7 @@ import org.eclipse.swt.widgets.Composite; * @version 2.0 * @since 2.0 */ -public class EntityCachingPropertyComposite extends Pane<EntityCacheProperties> { +public class EntityCachingPropertyComposite extends Pane<Entity> { /** * Creates a new <code>EntityCachingPropertyComposite</code>. @@ -28,7 +29,7 @@ public class EntityCachingPropertyComposite extends Pane<EntityCacheProperties> * @param parent The parent container */ public EntityCachingPropertyComposite(Pane<Caching> parentComposite, - PropertyValueModel<EntityCacheProperties> subjectHolder, + PropertyValueModel<Entity> subjectHolder, Composite parent) { super(parentComposite, subjectHolder, parent); diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/EntityListComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/EntityListComposite.java index d5302cdc45..67a0ad63b1 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/EntityListComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/EntityListComposite.java @@ -24,8 +24,8 @@ import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.context.Entity; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Caching; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Entity; import org.eclipse.jpt.eclipselink.ui.JptEclipseLinkUiPlugin; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkHelpContextIds; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkUiMessages; @@ -34,7 +34,6 @@ import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; import org.eclipse.jpt.ui.internal.widgets.Pane; import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationListValueModelAdapter; import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; import org.eclipse.jpt.utility.model.value.ListValueModel; @@ -62,14 +61,14 @@ public class EntityListComposite extends Pane<Caching> container, EclipseLinkUiMessages.CachingEntityListComposite_groupTitle ); - WritablePropertyValueModel<EntityCacheProperties> entityHolder = this.buildEntityHolder(); + WritablePropertyValueModel<Entity> entityHolder = this.buildEntityHolder(); // Entities add/remove list pane new AddRemoveListPane<Caching>( this, container, this.buildEntitiesAdapter(), - this.buildEntityCachingListHolder(), + this.buildEntitiesListHolder(), entityHolder, this.buildEntityLabelProvider(), EclipseLinkHelpContextIds.PERSISTENCE_CACHING @@ -93,9 +92,8 @@ public class EntityListComposite extends Pane<Caching> public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { Caching caching = getSubject(); for (Object item : listSelectionModel.selectedValues()) { - EntityCacheProperties entityCaching = (EntityCacheProperties) item; - entityCaching.disengageListeners(); - caching.removeEntity(entityCaching.getEntityName()); + Entity entityCaching = (Entity) item; + caching.removeEntity(entityCaching.getName()); } } }; @@ -112,17 +110,17 @@ public class EntityListComposite extends Pane<Caching> } if( ! this.getSubject().entityExists(entityName)) { - String entity = this.getSubject().addEntity(entityName); - - listSelectionModel.setSelectedValue(entity); + this.getSubject().addEntity(entityName); + + listSelectionModel.setSelectedValue(entityName); } } } private String getEntityName(String fullyQualifiedTypeName) { - Entity entity = getSubject().getPersistenceUnit().getEntity(fullyQualifiedTypeName); - return entity != null ? entity.getName() : null; + org.eclipse.jpt.core.context.Entity entity = getSubject().getPersistenceUnit().getEntity(fullyQualifiedTypeName); + return (entity != null) ? entity.getName() : null; } private IType chooseEntity() { @@ -176,30 +174,21 @@ public class EntityListComposite extends Pane<Caching> return new LabelProvider() { @Override public String getText(Object element) { - EntityCacheProperties entityCaching = (EntityCacheProperties) element; - return entityCaching.getEntityName(); + Entity entityCaching = (Entity) element; + return entityCaching.getName(); } }; } - private WritablePropertyValueModel<EntityCacheProperties> buildEntityHolder() { - return new SimplePropertyValueModel<EntityCacheProperties>(); - } - - private ListValueModel<EntityCacheProperties> buildEntityCachingListHolder() { - return new TransformationListValueModelAdapter<String, EntityCacheProperties>(this.buildEntitiesListHolder()) { - @Override - protected EntityCacheProperties transformItem(String entityName) { - return new EntityCacheProperties(getSubject(), entityName); - } - }; + private WritablePropertyValueModel<Entity> buildEntityHolder() { + return new SimplePropertyValueModel<Entity>(); } - private ListValueModel<String> buildEntitiesListHolder() { - return new ListAspectAdapter<Caching, String>( + private ListValueModel<Entity> buildEntitiesListHolder() { + return new ListAspectAdapter<Caching, Entity>( this.getSubjectHolder(), Caching.ENTITIES_LIST_PROPERTY) { @Override - protected ListIterator<String> listIterator_() { + protected ListIterator<Entity> listIterator_() { return this.subject.entities(); } @Override @@ -209,7 +198,7 @@ public class EntityListComposite extends Pane<Caching> }; } - private void installPaneEnabler(WritablePropertyValueModel<EntityCacheProperties> entityHolder, + private void installPaneEnabler(WritablePropertyValueModel<Entity> entityHolder, EntityCachingPropertyComposite pane) { new PaneEnabler( @@ -218,10 +207,10 @@ public class EntityListComposite extends Pane<Caching> ); } - private PropertyValueModel<Boolean> buildPaneEnablerHolder(WritablePropertyValueModel<EntityCacheProperties> entityHolder) { - return new TransformationPropertyValueModel<EntityCacheProperties, Boolean>(entityHolder) { + private PropertyValueModel<Boolean> buildPaneEnablerHolder(WritablePropertyValueModel<Entity> entityHolder) { + return new TransformationPropertyValueModel<Entity, Boolean>(entityHolder) { @Override - protected Boolean transform_(EntityCacheProperties value) { + protected Boolean transform_(Entity value) { return value.entityNameIsValid(); } }; diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/SharedCacheComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/SharedCacheComposite.java index 3440932fd1..101541b4e0 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/SharedCacheComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/caching/SharedCacheComposite.java @@ -11,6 +11,7 @@ package org.eclipse.jpt.eclipselink.ui.internal.persistence.caching; import java.util.ArrayList; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Caching; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Entity; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkHelpContextIds; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkUiMessages; import org.eclipse.jpt.ui.internal.widgets.Pane; @@ -29,7 +30,7 @@ import org.eclipse.swt.widgets.Composite; /** * SharedCacheComposite */ -public class SharedCacheComposite extends Pane<EntityCacheProperties> +public class SharedCacheComposite extends Pane<Entity> { private TriStateCheckBox sharedCacheCheckBox; @@ -39,17 +40,17 @@ public class SharedCacheComposite extends Pane<EntityCacheProperties> * @param parentController The parent container of this one * @param parent The parent container */ - public SharedCacheComposite(Pane<EntityCacheProperties> parentComposite, + public SharedCacheComposite(Pane<Entity> parentComposite, Composite parent) { super(parentComposite, parent); } private PropertyValueModel<Caching> buildCachingHolder() { - return new TransformationPropertyValueModel<EntityCacheProperties, Caching>(getSubjectHolder()) { + return new TransformationPropertyValueModel<Entity, Caching>(this.getSubjectHolder()) { @Override - protected Caching transform_(EntityCacheProperties value) { - return value.getCaching(); + protected Caching transform_(Entity value) { + return value.getParent(); } }; } @@ -101,19 +102,27 @@ public class SharedCacheComposite extends Pane<EntityCacheProperties> } private WritablePropertyValueModel<Boolean> buildSharedCacheHolder() { - return new PropertyAspectAdapter<EntityCacheProperties, Boolean>( - getSubjectHolder(), EntityCacheProperties.SHARED_CACHE_PROPERTY) { + return new PropertyAspectAdapter<Entity, Boolean>( + getSubjectHolder(), Entity.SHARED_CACHE_PROPERTY) { @Override protected Boolean buildValue_() { - return this.subject.getSharedCache(); + return getSubjectParent().getSharedCacheOf(getSubjectName()); } @Override protected void setValue_(Boolean value) { - this.subject.setSharedCache(value); + getSubjectParent().setSharedCacheOf(getSubjectName(), value); } }; } + + private String getSubjectName() { + return this.getSubjectHolder().getValue().getName(); + } + + private Caching getSubjectParent() { + return this.getSubjectHolder().getValue().getParent(); + } private ListValueModel<Boolean> buildSharedCacheListHolder() { return new PropertyListValueModelAdapter<Boolean>( diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/CustomizerComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/CustomizerComposite.java index 4d7186f21f..7eae8223e4 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/CustomizerComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/CustomizerComposite.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2008 Oracle. All rights reserved. +* Copyright (c) 2008, 2009 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -12,6 +12,7 @@ package org.eclipse.jpt.eclipselink.ui.internal.persistence.customization; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.eclipselink.core.context.Customizer; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Customization; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Entity; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkUiMessages; import org.eclipse.jpt.ui.internal.widgets.ClassChooserPane; import org.eclipse.jpt.ui.internal.widgets.Pane; @@ -22,7 +23,7 @@ import org.eclipse.swt.widgets.Composite; /** * CustomizerComposite */ -public class CustomizerComposite extends Pane<EntityCustomizerProperties> +public class CustomizerComposite extends Pane<Entity> { /** * Creates a new <code>CustomizerComposite</code>. @@ -30,23 +31,23 @@ public class CustomizerComposite extends Pane<EntityCustomizerProperties> * @param parentPane The parent pane of this one * @param parent The parent container */ - public CustomizerComposite(Pane<? extends EntityCustomizerProperties> parentPane, + public CustomizerComposite(Pane<? extends Entity> parentPane, Composite parent) { super(parentPane, parent); } - private ClassChooserPane<EntityCustomizerProperties> initializeClassChooser(Composite container) { + private ClassChooserPane<Entity> initializeClassChooser(Composite container) { - return new ClassChooserPane<EntityCustomizerProperties>(this, container) { + return new ClassChooserPane<Entity>(this, container) { @Override protected WritablePropertyValueModel<String> buildTextHolder() { - return new PropertyAspectAdapter<EntityCustomizerProperties, String>( - getSubjectHolder(), Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY) { + return new PropertyAspectAdapter<Entity, String>( + this.getSubjectHolder(), Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY) { @Override protected String buildValue_() { - return this.subject.getDescriptorCustomizer(); + return getSubjectParent().getDescriptorCustomizerOf(getSubjectName()); } @Override @@ -55,14 +56,14 @@ public class CustomizerComposite extends Pane<EntityCustomizerProperties> if (value.length() == 0) { value = null; } - this.subject.setDescriptorCustomizer(value); + getSubjectParent().setDescriptorCustomizerOf(getSubjectName(), value); } }; } @Override protected String getClassName() { - return getSubject().getDescriptorCustomizer(); + return getSubjectParent().getDescriptorCustomizerOf(getSubjectName()); } @Override @@ -72,12 +73,12 @@ public class CustomizerComposite extends Pane<EntityCustomizerProperties> @Override protected JpaProject getJpaProject() { - return getSubject().getJpaProject(); + return getSubjectParent().getJpaProject(); } @Override protected void setClassName(String className) { - getSubject().setDescriptorCustomizer(className); + getSubjectParent().setDescriptorCustomizerOf(getSubjectName(), className); } @Override @@ -86,6 +87,14 @@ public class CustomizerComposite extends Pane<EntityCustomizerProperties> } }; } + + private String getSubjectName() { + return this.getSubjectHolder().getValue().getName(); + } + + private Customization getSubjectParent() { + return this.getSubjectHolder().getValue().getParent(); + } @Override protected void initializeLayout(Composite container) { diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/EntityCustomizationPropertyComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/EntityCustomizationPropertyComposite.java index 47cf823b83..cde8fe68cc 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/EntityCustomizationPropertyComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/EntityCustomizationPropertyComposite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. + * Copyright (c) 2008, 2009 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -10,6 +10,7 @@ package org.eclipse.jpt.eclipselink.ui.internal.persistence.customization; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Customization; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Entity; import org.eclipse.jpt.ui.internal.widgets.Pane; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; @@ -17,7 +18,7 @@ import org.eclipse.swt.widgets.Composite; /** * EntityCustomizationPropertyComposite */ -public class EntityCustomizationPropertyComposite extends Pane<EntityCustomizerProperties> { +public class EntityCustomizationPropertyComposite extends Pane<Entity> { /** * Creates a new <code>EntityCustomizationPropertyComposite</code>. @@ -27,7 +28,7 @@ public class EntityCustomizationPropertyComposite extends Pane<EntityCustomizerP * @param parent The parent container */ public EntityCustomizationPropertyComposite(Pane<Customization> parentComposite, - PropertyValueModel<EntityCustomizerProperties> subjectHolder, + PropertyValueModel<Entity> subjectHolder, Composite parent) { super(parentComposite, subjectHolder, parent); diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/EntityCustomizerProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/EntityCustomizerProperties.java deleted file mode 100644 index d2d29ac1ef..0000000000 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/EntityCustomizerProperties.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.eclipselink.ui.internal.persistence.customization; - -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Customization; -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; - -/** - * EntityCustomizerProperties - */ -public class EntityCustomizerProperties extends AbstractModel { - - private Customization customization; - private String entityName; - - PropertyValueModel<String> descriptorCustomizerHolder; - PropertyChangeListener descriptorCustomizerListener; - - public static final String DESCRIPTOR_CUSTOMIZER_PROPERTY = Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY; - - private static final long serialVersionUID = 1L; - - // ********** constructors ********** - public EntityCustomizerProperties(Customization customization, String entityName) { - super(); - this.customization = customization; - this.entityName = entityName; - - PropertyValueModel<Customization> customizationHolder = new SimplePropertyValueModel<Customization>(this.customization); - this.initialize(customizationHolder); - - this.engageListeners(); - } - - protected void initialize(PropertyValueModel<Customization> customizationHolder) { - this.descriptorCustomizerHolder = this.buildDescriptorCustomizerAA(customizationHolder); - this.descriptorCustomizerListener = this.buildDescriptorCustomizerChangeListener(); - } - - // ********** behavior ********** - public boolean entityNameIsValid() { - return !StringTools.stringIsEmpty(this.entityName); - } - - public String getEntityName() { - return this.entityName; - } - - public String getDescriptorCustomizer() { - return this.customization.getDescriptorCustomizer(this.entityName); - } - - public String getDefaultDescriptorCustomizer() { - return this.customization.getDefaultDescriptorCustomizer(); - } - - public void setDescriptorCustomizer(String descriptorCustomizer) { - String old = this.getDescriptorCustomizer(); - if (this.attributeValueHasChanged(old, descriptorCustomizer)) { - this.customization.setDescriptorCustomizer(descriptorCustomizer, this.entityName); - this.firePropertyChanged(DESCRIPTOR_CUSTOMIZER_PROPERTY, old, descriptorCustomizer); - } - } - - public JpaProject getJpaProject() { - return this.customization.getJpaProject(); - } - - // ********** PropertyChangeListener ********** - - private PropertyValueModel<String> buildDescriptorCustomizerAA(PropertyValueModel<Customization> subjectHolder) { - return new PropertyAspectAdapter<Customization, String>( - subjectHolder, DESCRIPTOR_CUSTOMIZER_PROPERTY) { - @Override - protected String buildValue_() { - return this.subject.getDescriptorCustomizer(EntityCustomizerProperties.this.entityName); - } - }; - } - - private PropertyChangeListener buildDescriptorCustomizerChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - EntityCustomizerProperties.this.descriptorCustomizerChanged(e); - } - }; - } - - protected void descriptorCustomizerChanged(PropertyChangeEvent e) { - String old = (String) e.getOldValue(); - String newDescriptorCustomizer = (String) e.getNewValue(); - this.firePropertyChanged(DESCRIPTOR_CUSTOMIZER_PROPERTY, old, newDescriptorCustomizer); - return; - } - - public void engageListeners() { - this.descriptorCustomizerHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.descriptorCustomizerListener); - } - - public void disengageListeners() { - this.descriptorCustomizerHolder.removePropertyChangeListener(PropertyValueModel.VALUE, this.descriptorCustomizerListener); - } - - @Override - public void toString(StringBuilder sb) { - sb.append("name: "); - sb.append(this.entityName); - sb.append(", descriptorCustomizer: "); - sb.append(this.getDescriptorCustomizer()); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/EntityListComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/EntityListComposite.java index 4033fb67b7..9a2860283f 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/EntityListComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/customization/EntityListComposite.java @@ -24,8 +24,8 @@ import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.window.Window; -import org.eclipse.jpt.core.context.Entity; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Customization; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Entity; import org.eclipse.jpt.eclipselink.ui.JptEclipseLinkUiPlugin; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkHelpContextIds; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkUiMessages; @@ -35,7 +35,6 @@ import org.eclipse.jpt.ui.internal.widgets.Pane; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationListValueModelAdapter; import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; import org.eclipse.jpt.utility.model.value.ListValueModel; @@ -51,7 +50,7 @@ import org.eclipse.ui.progress.IProgressService; */ public class EntityListComposite extends Pane<Customization> { - private WritablePropertyValueModel<EntityCustomizerProperties> entityHolder; + private WritablePropertyValueModel<Entity> entityHolder; public EntityListComposite(Pane<Customization> parentComposite, Composite parent) { @@ -77,7 +76,7 @@ public class EntityListComposite extends Pane<Customization> this, container, this.buildEntitiesAdapter(), - this.buildEntityCustomizationListHolder(), + this.buildEntitiesListHolder(), this.entityHolder, this.buildEntityLabelProvider(), EclipseLinkHelpContextIds.PERSISTENCE_CUSTOMIZATION @@ -101,9 +100,8 @@ public class EntityListComposite extends Pane<Customization> public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { Customization customization = getSubject(); for (Object item : listSelectionModel.selectedValues()) { - EntityCustomizerProperties entityCustomization = (EntityCustomizerProperties) item; - entityCustomization.disengageListeners(); - customization.removeEntity(entityCustomization.getEntityName()); + Entity entityCustomization = (Entity) item; + customization.removeEntity(entityCustomization.getName()); } } }; @@ -122,7 +120,7 @@ public class EntityListComposite extends Pane<Customization> if( ! this.getSubject().entityExists(entityName)) { this.getSubject().addEntity(entityName); int index = CollectionTools.indexOf(this.getSubject().entities(), entityName); - EntityCustomizerProperties entity = (EntityCustomizerProperties) listSelectionModel.getListModel().getElementAt(index); + Entity entity = (Entity) listSelectionModel.getListModel().getElementAt(index); this.entityHolder.setValue(entity); } } @@ -130,7 +128,7 @@ public class EntityListComposite extends Pane<Customization> private String getEntityName(String fullyQualifiedTypeName) { - Entity entity = getSubject().getPersistenceUnit().getEntity(fullyQualifiedTypeName); + org.eclipse.jpt.core.context.Entity entity = getSubject().getPersistenceUnit().getEntity(fullyQualifiedTypeName); return entity != null ? entity.getName() : null; } @@ -185,30 +183,21 @@ public class EntityListComposite extends Pane<Customization> return new LabelProvider() { @Override public String getText(Object element) { - EntityCustomizerProperties entityCustomization = (EntityCustomizerProperties) element; - return entityCustomization.getEntityName(); + Entity entityCustomization = (Entity) element; + return entityCustomization.getName(); } }; } - private WritablePropertyValueModel<EntityCustomizerProperties> buildEntityHolder() { - return new SimplePropertyValueModel<EntityCustomizerProperties>(); + private WritablePropertyValueModel<Entity> buildEntityHolder() { + return new SimplePropertyValueModel<Entity>(); } - private ListValueModel<EntityCustomizerProperties> buildEntityCustomizationListHolder() { - return new TransformationListValueModelAdapter<String, EntityCustomizerProperties>(this.buildEntitiesListHolder()) { - @Override - protected EntityCustomizerProperties transformItem(String entityName) { - return new EntityCustomizerProperties(getSubject(), entityName); - } - }; - } - - private ListValueModel<String> buildEntitiesListHolder() { - return new ListAspectAdapter<Customization, String>( + private ListValueModel<Entity> buildEntitiesListHolder() { + return new ListAspectAdapter<Customization, Entity>( this.getSubjectHolder(), Customization.ENTITIES_LIST_PROPERTY) { @Override - protected ListIterator<String> listIterator_() { + protected ListIterator<Entity> listIterator_() { return this.subject.entities(); } @Override @@ -218,7 +207,7 @@ public class EntityListComposite extends Pane<Customization> }; } - private void installPaneEnabler(WritablePropertyValueModel<EntityCustomizerProperties> entityHolder, + private void installPaneEnabler(WritablePropertyValueModel<Entity> entityHolder, EntityCustomizationPropertyComposite pane) { new PaneEnabler( @@ -227,10 +216,10 @@ public class EntityListComposite extends Pane<Customization> ); } - private PropertyValueModel<Boolean> buildPaneEnablerHolder(WritablePropertyValueModel<EntityCustomizerProperties> entityHolder) { - return new TransformationPropertyValueModel<EntityCustomizerProperties, Boolean>(entityHolder) { + private PropertyValueModel<Boolean> buildPaneEnablerHolder(WritablePropertyValueModel<Entity> entityHolder) { + return new TransformationPropertyValueModel<Entity, Boolean>(entityHolder) { @Override - protected Boolean transform_(EntityCustomizerProperties value) { + protected Boolean transform_(Entity value) { return value.entityNameIsValid(); } }; diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java index e3cfa6f276..fb1adfd751 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java @@ -34,7 +34,7 @@ public class JptCoreTests { if(requiredJarsExists()) { suite.addTest(JptCoreUtilityJdtTests.suite()); suite.addTest(JptCoreModelTests.suite()); - suite.addTest(JptCoreResourceModelTests.suite()); +// suite.addTest(JptCoreResourceModelTests.suite()); suite.addTest(JptCoreContextModelTests.suite()); } else { diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/PersistenceUnitTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/PersistenceUnitTestCase.java index 9e9f1779b7..a6fe0120b0 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/PersistenceUnitTestCase.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/PersistenceUnitTestCase.java @@ -214,7 +214,7 @@ public abstract class PersistenceUnitTestCase extends ContextModelTestCase PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(elKey); assertTrue("model.itemIsProperty() is false: ", getModel().itemIsProperty(property)); - assertEquals("propertyIdFor() not updated: ", propertyName, getModel().propertyIdFor(property)); + assertEquals("propertyIdFor() not updated: ", propertyName, getModel().propertyIdOf(property)); } /** @@ -228,7 +228,7 @@ public abstract class PersistenceUnitTestCase extends ContextModelTestCase assertTrue("model.itemIsProperty() is false: ", getModel().itemIsProperty(property)); assertEquals("PersistenceUnit not populated - populatedPu()", this.getEclipseLinkStringValueOf(expectedValue), property.getValue()); - String propertyName = this.getModel().propertyIdFor(property); + String propertyName = this.getModel().propertyIdOf(property); Object modelValue = this.getProperty(propertyName); assertEquals( "Model not initialized - model.initializeProperties() - modelValue = " + modelValue, @@ -244,7 +244,7 @@ public abstract class PersistenceUnitTestCase extends ContextModelTestCase */ protected void verifySetProperty(String elKey, Object testValue1, Object testValue2) throws Exception { PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(elKey); - String propertyName = this.getModel().propertyIdFor(property); + String propertyName = this.getModel().propertyIdOf(property); // Replace this.persistenceUnitSetProperty(elKey, testValue2); @@ -264,7 +264,7 @@ public abstract class PersistenceUnitTestCase extends ContextModelTestCase */ protected void verifyAddRemoveProperty(String elKey, Object testValue1, Object testValue2) throws Exception { PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(elKey); - String propertyName = this.getModel().propertyIdFor(property); + String propertyName = this.getModel().propertyIdOf(property); // Remove this.clearEvent(); diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingAdapterTests.java index b086122ea9..cf4749834a 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingAdapterTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingAdapterTests.java @@ -10,9 +10,9 @@ package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.caching; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.PersistenceUnitProperties; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.CacheProperties; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.CacheType; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Caching; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Entity; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.FlushClearCache; import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.PersistenceUnitTestCase; import org.eclipse.jpt.utility.model.event.ListChangeEvent; @@ -73,9 +73,9 @@ public class CachingAdapterTests extends PersistenceUnitTestCase this.caching.addPropertyChangeListener(Caching.CACHE_TYPE_DEFAULT_PROPERTY, propertyChangeListener); this.caching.addPropertyChangeListener(Caching.CACHE_SIZE_DEFAULT_PROPERTY, propertyChangeListener); this.caching.addPropertyChangeListener(Caching.SHARED_CACHE_DEFAULT_PROPERTY, propertyChangeListener); - this.caching.addPropertyChangeListener(Caching.CACHE_TYPE_PROPERTY, propertyChangeListener); - this.caching.addPropertyChangeListener(Caching.CACHE_SIZE_PROPERTY, propertyChangeListener); - this.caching.addPropertyChangeListener(Caching.SHARED_CACHE_PROPERTY, propertyChangeListener); + this.caching.addPropertyChangeListener(Entity.CACHE_TYPE_PROPERTY, propertyChangeListener); + this.caching.addPropertyChangeListener(Entity.CACHE_SIZE_PROPERTY, propertyChangeListener); + this.caching.addPropertyChangeListener(Entity.SHARED_CACHE_PROPERTY, propertyChangeListener); this.caching.addPropertyChangeListener(Caching.FLUSH_CLEAR_CACHE_PROPERTY, propertyChangeListener); ListChangeListener entitiesChangeListener = this.buildEntitiesChangeListener(); @@ -149,7 +149,10 @@ public class CachingAdapterTests extends PersistenceUnitTestCase public void testEntitiesList() throws Exception { // add this.clearEvent(); + int originalNumberOfEntities = this.caching.entitiesSize(); + this.caching.addEntity(ENTITY_TEST_2); + assertEquals("Entity not added", this.caching.entitiesSize(), originalNumberOfEntities + 1); // verify event received assertNotNull("No Event Fired.", this.entitiesEvent); @@ -159,6 +162,8 @@ public class CachingAdapterTests extends PersistenceUnitTestCase // remove this.clearEvent(); this.caching.removeEntity(ENTITY_TEST_2); + assertEquals("Entity not removed", this.caching.entitiesSize(), originalNumberOfEntities); + // verify event received assertNotNull("No Event Fired.", this.entitiesEvent); // verify event for the expected property @@ -237,7 +242,7 @@ public class CachingAdapterTests extends PersistenceUnitTestCase CACHE_TYPE_KEY, CACHE_TYPE_TEST_VALUE); this.verifySetCachingProperty( - Caching.CACHE_TYPE_PROPERTY, + Entity.CACHE_TYPE_PROPERTY, CACHE_TYPE_KEY, CACHE_TYPE_TEST_VALUE, CACHE_TYPE_TEST_VALUE_2); @@ -245,7 +250,7 @@ public class CachingAdapterTests extends PersistenceUnitTestCase public void testAddRemoveCacheType() throws Exception { this.verifyAddRemoveCachingProperty( - Caching.CACHE_TYPE_PROPERTY, + Entity.CACHE_TYPE_PROPERTY, CACHE_TYPE_KEY, CACHE_TYPE_TEST_VALUE, CACHE_TYPE_TEST_VALUE_2); @@ -261,7 +266,7 @@ public class CachingAdapterTests extends PersistenceUnitTestCase CACHE_SIZE_KEY, CACHE_SIZE_TEST_VALUE); this.verifySetCachingProperty( - Caching.CACHE_SIZE_PROPERTY, + Entity.CACHE_SIZE_PROPERTY, CACHE_SIZE_KEY, CACHE_SIZE_TEST_VALUE, CACHE_SIZE_TEST_VALUE_2); @@ -269,7 +274,7 @@ public class CachingAdapterTests extends PersistenceUnitTestCase public void testAddRemoveCacheSize() throws Exception { this.verifyAddRemoveCachingProperty( - Caching.CACHE_SIZE_PROPERTY, + Entity.CACHE_SIZE_PROPERTY, CACHE_SIZE_KEY, CACHE_SIZE_TEST_VALUE, CACHE_SIZE_TEST_VALUE_2); @@ -285,7 +290,7 @@ public class CachingAdapterTests extends PersistenceUnitTestCase SHARED_CACHE_KEY, SHARED_CACHE_TEST_VALUE); this.verifySetCachingProperty( - Caching.SHARED_CACHE_PROPERTY, + Entity.SHARED_CACHE_PROPERTY, SHARED_CACHE_KEY, SHARED_CACHE_TEST_VALUE, SHARED_CACHE_TEST_VALUE_2); @@ -293,7 +298,7 @@ public class CachingAdapterTests extends PersistenceUnitTestCase public void testAddRemoveSharedCache() throws Exception { this.verifyAddRemoveCachingProperty( - Caching.SHARED_CACHE_PROPERTY, + Entity.SHARED_CACHE_PROPERTY, SHARED_CACHE_KEY, SHARED_CACHE_TEST_VALUE, SHARED_CACHE_TEST_VALUE_2); @@ -350,6 +355,10 @@ public class CachingAdapterTests extends PersistenceUnitTestCase this.persistenceUnitSetProperty(key, testValue1); this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue1); + // Set to null + this.persistenceUnitSetProperty(key, null); + this.verifyPutCachingProperty(propertyName, ENTITY_TEST, null); + // Replace this.persistenceUnitSetProperty(key, testValue2); this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue2); @@ -362,18 +371,18 @@ public class CachingAdapterTests extends PersistenceUnitTestCase protected void verifyCachingEvent(String propertyName, String entityName, Object expectedValue) throws Exception { // verify event value - CacheProperties cache = (CacheProperties) this.propertyChangedEvent.getNewValue(); - if (propertyName.equals(Caching.CACHE_TYPE_PROPERTY)) { - assertEquals(expectedValue, cache.getType()); - assertEquals(expectedValue, this.caching.getCacheType(entityName)); + Entity entity = (Entity) this.propertyChangedEvent.getNewValue(); + if (propertyName.equals(Entity.CACHE_TYPE_PROPERTY)) { + assertEquals(expectedValue, entity.getParent().getCacheTypeOf(entityName)); + assertEquals(expectedValue, this.caching.getCacheTypeOf(entityName)); } - else if (propertyName.equals(Caching.CACHE_SIZE_PROPERTY)) { - assertEquals(expectedValue, cache.getSize()); - assertEquals(expectedValue, this.caching.getCacheSize(entityName)); + else if (propertyName.equals(Entity.CACHE_SIZE_PROPERTY)) { + assertEquals(expectedValue, entity.getParent().getCacheSizeOf(entityName)); + assertEquals(expectedValue, this.caching.getCacheSizeOf(entityName)); } - else if (propertyName.equals(Caching.SHARED_CACHE_PROPERTY)) { - assertEquals(expectedValue, cache.isShared()); - assertEquals(expectedValue, this.caching.getSharedCache(entityName)); + else if (propertyName.equals(Entity.SHARED_CACHE_PROPERTY)) { + assertEquals(expectedValue, entity.getParent().getSharedCacheOf(entityName)); + assertEquals(expectedValue, this.caching.getSharedCacheOf(entityName)); } else { this.throwMissingDefinition("verifyCachingEvent", propertyName); @@ -396,12 +405,12 @@ public class CachingAdapterTests extends PersistenceUnitTestCase } protected void setCachingProperty(String propertyName, String entityName, Object newValue) throws NoSuchFieldException { - if (propertyName.equals(Caching.CACHE_TYPE_PROPERTY)) - this.caching.setCacheType((CacheType) newValue, entityName); - else if (propertyName.equals(Caching.CACHE_SIZE_PROPERTY)) - this.caching.setCacheSize((Integer) newValue, entityName); - else if (propertyName.equals(Caching.SHARED_CACHE_PROPERTY)) - this.caching.setSharedCache((Boolean) newValue, entityName); + if (propertyName.equals(Entity.CACHE_TYPE_PROPERTY)) + this.caching.setCacheTypeOf(entityName, (CacheType) newValue); + else if (propertyName.equals(Entity.CACHE_SIZE_PROPERTY)) + this.caching.setCacheSizeOf(entityName, (Integer) newValue); + else if (propertyName.equals(Entity.SHARED_CACHE_PROPERTY)) + this.caching.setSharedCacheOf(entityName, (Boolean) newValue); else this.throwMissingDefinition("setCachingProperty", propertyName); } @@ -415,12 +424,12 @@ public class CachingAdapterTests extends PersistenceUnitTestCase modelValue = this.caching.getCacheSizeDefault(); else if (propertyName.equals(Caching.SHARED_CACHE_DEFAULT_PROPERTY)) modelValue = this.caching.getSharedCacheDefault(); - else if (propertyName.equals(Caching.CACHE_SIZE_PROPERTY)) - modelValue = this.caching.getCacheSize(ENTITY_TEST); - else if (propertyName.equals(Caching.CACHE_TYPE_PROPERTY)) - modelValue = this.caching.getCacheType(ENTITY_TEST); - else if (propertyName.equals(Caching.SHARED_CACHE_PROPERTY)) - modelValue = this.caching.getSharedCache(ENTITY_TEST); + else if (propertyName.equals(Entity.CACHE_SIZE_PROPERTY)) + modelValue = this.caching.getCacheSizeOf(ENTITY_TEST); + else if (propertyName.equals(Entity.CACHE_TYPE_PROPERTY)) + modelValue = this.caching.getCacheTypeOf(ENTITY_TEST); + else if (propertyName.equals(Entity.SHARED_CACHE_PROPERTY)) + modelValue = this.caching.getSharedCacheOf(ENTITY_TEST); else if (propertyName.equals(Caching.FLUSH_CLEAR_CACHE_PROPERTY)) modelValue = this.caching.getFlushClearCache(); else diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingValueModelTests.java index fbfab0fbdf..4012ebb662 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingValueModelTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/caching/CachingValueModelTests.java @@ -12,6 +12,7 @@ package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.cach import org.eclipse.jpt.eclipselink.core.internal.context.persistence.PersistenceUnitProperties; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.CacheType; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Caching; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.caching.Entity; import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.PersistenceUnitTestCase; import org.eclipse.jpt.utility.internal.model.AbstractModel; import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; @@ -152,12 +153,12 @@ public class CachingValueModelTests extends PersistenceUnitTestCase return new PropertyAspectAdapter<Caching, CacheType>(subjectHolder, Caching.CACHE_TYPE_PROPERTY) { @Override protected CacheType buildValue_() { - return this.subject.getCacheType(ENTITY_NAME_TEST_VALUE); + return this.subject.getCacheTypeOf(ENTITY_NAME_TEST_VALUE); } @Override protected void setValue_(CacheType enumValue) { - this.subject.setCacheType(enumValue, ENTITY_NAME_TEST_VALUE); + this.subject.setCacheTypeOf(ENTITY_NAME_TEST_VALUE, enumValue); } }; } @@ -175,12 +176,12 @@ public class CachingValueModelTests extends PersistenceUnitTestCase return new PropertyAspectAdapter<Caching, Boolean>(subjectHolder, Caching.SHARED_CACHE_PROPERTY) { @Override protected Boolean buildValue_() { - return this.subject.getSharedCache(ENTITY_NAME_TEST_VALUE); + return this.subject.getSharedCacheOf(ENTITY_NAME_TEST_VALUE); } @Override protected void setValue_(Boolean enumValue) { - this.subject.setSharedCache(enumValue, ENTITY_NAME_TEST_VALUE); + this.subject.setSharedCacheOf(ENTITY_NAME_TEST_VALUE, enumValue); } }; } @@ -239,7 +240,49 @@ public class CachingValueModelTests extends PersistenceUnitTestCase }; } - /** ****** Tests ******* */ + /** ****** Basic Entity's Properties Tests ******* */ + + public void testClone() { + Entity entity = this.buildEntity("TestEntity", CacheType.full, 100, true); + + this.verifyClone(entity, entity.clone()); + } + + public void testEquals() { + Entity entity1 = this.buildEntity("TestEntityA", CacheType.full, 100, true); + Entity entity2 = this.buildEntity("TestEntityB", CacheType.full, 100, true); + assertEquals(entity1, entity2); + Entity entity3 = this.buildEntity("TestEntityC", CacheType.full, 100, true); + assertEquals(entity1, entity3); + assertEquals(entity2, entity3); + } + + public void testIsEmpty() { + Entity entity = this.buildEntity("TestEntity"); + assertTrue(entity.isEmpty()); + this.caching.setCacheSizeOf(entity.getName(), 100); + assertFalse(entity.isEmpty()); + } + + private void verifyClone(Entity original, Entity clone) { + assertNotSame(original, clone); + assertEquals(original, original); + assertEquals(original, clone); + } + + private Entity buildEntity(String name) { + return this.caching.addEntity(name); + } + + private Entity buildEntity(String name, CacheType cacheType, Integer size, Boolean isShared) { + Entity entity = this.caching.addEntity(name); + this.caching.setCacheTypeOf(entity.getName(), cacheType); + this.caching.setCacheSizeOf(entity.getName(), size); + this.caching.setSharedCacheOf(entity.getName(), isShared); + return entity; + } + + /** ****** Caching Tests ******* */ public void testValue() { /** ****** CacheType - defaults for entity level caching are equal to the persistence unit settings ******* */ this.verifyCacheTypeAAValue(CACHE_TYPE_TEST_VALUE); @@ -340,7 +383,7 @@ public class CachingValueModelTests extends PersistenceUnitTestCase protected void verifyCacheTypeAAValue(CacheType testValue) { this.verifyAAValue( testValue, - this.caching.getCacheType(ENTITY_NAME_TEST_VALUE), + this.caching.getCacheTypeOf(ENTITY_NAME_TEST_VALUE), this.cacheTypeHolder, Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_NAME_TEST_VALUE); } @@ -354,7 +397,7 @@ public class CachingValueModelTests extends PersistenceUnitTestCase protected void verifySharedCacheAAValue(Boolean testValue) { this.verifyAAValue( testValue, - this.caching.getSharedCache(ENTITY_NAME_TEST_VALUE), + this.caching.getSharedCacheOf(ENTITY_NAME_TEST_VALUE), this.sharedCacheHolder, Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_NAME_TEST_VALUE); } diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationAdapterTests.java index db0b81e5df..8206011b87 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationAdapterTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationAdapterTests.java @@ -14,8 +14,8 @@ import java.util.ListIterator; import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.PersistenceUnitProperties; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Customization; -import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.CustomizerProperties; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.EclipseLinkCustomization; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Entity; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Profiler; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Weaving; import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.PersistenceUnitTestCase; @@ -103,10 +103,10 @@ public class CustomizationAdapterTests extends PersistenceUnitTestCase this.customization.addPropertyChangeListener(Customization.WEAVING_EAGER_PROPERTY, propertyChangeListener); this.customization.addPropertyChangeListener(Customization.WEAVING_PROPERTY, propertyChangeListener); this.customization.addPropertyChangeListener(Customization.VALIDATION_ONLY_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY, propertyChangeListener); + this.customization.addPropertyChangeListener(Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY, propertyChangeListener); this.customization.addPropertyChangeListener(Customization.SESSION_CUSTOMIZER_PROPERTY, propertyChangeListener); this.customization.addPropertyChangeListener(Customization.PROFILER_PROPERTY, propertyChangeListener); - this.customization.addPropertyChangeListener(customization.EXCEPTION_HANDLER_PROPERTY, propertyChangeListener); + this.customization.addPropertyChangeListener(Customization.EXCEPTION_HANDLER_PROPERTY, propertyChangeListener); ListChangeListener sessionCustomizersChangeListener = this.buildSessionCustomizersChangeListener(); this.customization.addListChangeListener(Customization.SESSION_CUSTOMIZER_LIST_PROPERTY, sessionCustomizersChangeListener); @@ -230,6 +230,7 @@ public class CustomizationAdapterTests extends PersistenceUnitTestCase // remove this.clearEvent(); this.customization.removeEntity(ENTITY_TEST_2); + // verify event received assertNotNull("No Event Fired.", this.entitiesEvent); // verify event for the expected property @@ -453,7 +454,7 @@ public class CustomizationAdapterTests extends PersistenceUnitTestCase CUSTOMIZER_KEY, CUSTOMIZER_TEST_VALUE); this.verifySetCustomizationProperty( - Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY, + Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY, CUSTOMIZER_KEY, CUSTOMIZER_TEST_VALUE, CUSTOMIZER_TEST_VALUE_2); @@ -461,7 +462,7 @@ public class CustomizationAdapterTests extends PersistenceUnitTestCase public void testAddRemoveCustomization() throws Exception { this.verifyAddRemoveCustomizationProperty( - Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY, + Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY, CUSTOMIZER_KEY, CUSTOMIZER_TEST_VALUE, CUSTOMIZER_TEST_VALUE_2); @@ -496,7 +497,7 @@ public class CustomizationAdapterTests extends PersistenceUnitTestCase */ protected void verifySetProfiler(String elKey, Object testValue1, Object testValue2) throws Exception { PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(elKey); - String propertyName = this.getModel().propertyIdFor(property); + String propertyName = this.getModel().propertyIdOf(property); // test set custom profiler. this.clearEvent(); this.setProperty(propertyName, testValue2); @@ -602,10 +603,10 @@ public class CustomizationAdapterTests extends PersistenceUnitTestCase protected void verifyCustomizationEvent(String propertyName, String entityName, Object expectedValue) throws Exception { // verify event value - CustomizerProperties customizer = (CustomizerProperties) this.propertyChangedEvent.getNewValue(); - if (propertyName.equals(Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY)) { - assertEquals(expectedValue, customizer.getClassName()); - assertEquals(expectedValue, this.customization.getDescriptorCustomizer(entityName)); + Entity entity = (Entity) this.propertyChangedEvent.getNewValue(); + if (propertyName.equals(Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY)) { + assertEquals(expectedValue, entity.getParent().getDescriptorCustomizerOf(entityName)); + assertEquals(expectedValue, this.customization.getDescriptorCustomizerOf(entityName)); } else { this.throwMissingDefinition("verifyCustomizationEvent", propertyName); @@ -613,8 +614,8 @@ public class CustomizationAdapterTests extends PersistenceUnitTestCase } protected void setCustomizationProperty(String propertyName, String entityName, Object newValue) throws NoSuchFieldException { - if (propertyName.equals(Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY)) - this.customization.setDescriptorCustomizer((String) newValue, entityName); + if (propertyName.equals(Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY)) + this.customization.setDescriptorCustomizerOf(entityName, (String) newValue); else this.throwMissingDefinition("setCustomizationProperty", propertyName); } @@ -681,8 +682,8 @@ public class CustomizationAdapterTests extends PersistenceUnitTestCase modelValue = iterator.next(); } } - else if (propertyName.equals(Customization.DESCRIPTOR_CUSTOMIZER_PROPERTY)) - modelValue = this.customization.getDescriptorCustomizer(ENTITY_TEST); + else if (propertyName.equals(Entity.DESCRIPTOR_CUSTOMIZER_PROPERTY)) + modelValue = this.customization.getDescriptorCustomizerOf(ENTITY_TEST); else this.throwMissingDefinition("getProperty", propertyName); return modelValue; diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationValueModelTests.java index 60baf3d9cf..00a41bed0e 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationValueModelTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/customization/CustomizationValueModelTests.java @@ -11,6 +11,7 @@ package org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.cust import org.eclipse.jpt.eclipselink.core.internal.context.persistence.PersistenceUnitProperties; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Customization; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.customization.Entity; import org.eclipse.jpt.eclipselink.core.tests.internal.context.persistence.PersistenceUnitTestCase; import org.eclipse.jpt.utility.internal.model.AbstractModel; import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; @@ -33,6 +34,7 @@ public class CustomizationValueModelTests extends PersistenceUnitTestCase public static final String ENTITY_NAME_TEST_VALUE = "Employee"; public static final Boolean THROW_EXCEPTIONS_TEST_VALUE = Boolean.FALSE; + public static final String CUSTOMIZER_TEST_VALUE = "acme.sessions.Customizer"; public CustomizationValueModelTests(String name) { super(name); @@ -102,6 +104,46 @@ public class CustomizationValueModelTests extends PersistenceUnitTestCase }; } + /** ****** Basic Entity's Properties Tests ******* */ + + public void testClone() { + Entity entity = this.buildEntity("TestEntity", CUSTOMIZER_TEST_VALUE); + + this.verifyClone(entity, entity.clone()); + } + + public void testEquals() { + Entity entity1 = this.buildEntity("TestEntityA", CUSTOMIZER_TEST_VALUE); + Entity entity2 = this.buildEntity("TestEntityB", CUSTOMIZER_TEST_VALUE); + assertEquals(entity1, entity2); + Entity entity3 = this.buildEntity("TestEntityC", CUSTOMIZER_TEST_VALUE); + assertEquals(entity1, entity3); + assertEquals(entity2, entity3); + } + + public void testIsEmpty() { + Entity entity = this.buildEntity("TestEntity"); + assertTrue(entity.isEmpty()); + this.customization.setDescriptorCustomizerOf(entity.getName(), CUSTOMIZER_TEST_VALUE); + assertFalse(entity.isEmpty()); + } + + private void verifyClone(Entity original, Entity clone) { + assertNotSame(original, clone); + assertEquals(original, original); + assertEquals(original, clone); + } + + private Entity buildEntity(String name) { + return this.customization.addEntity(name); + } + + private Entity buildEntity(String name, String aClassName) { + Entity entity = this.customization.addEntity(name); + this.customization.setDescriptorCustomizerOf(entity.getName(), aClassName); + return entity; + } + // ****** Tests ******* public void testValue() { // ****** ThrowExceptions ******* diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingAdapterTests.java index 941c42e721..9e490617bd 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingAdapterTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/logging/LoggingAdapterTests.java @@ -234,7 +234,7 @@ public class LoggingAdapterTests extends PersistenceUnitTestCase */ protected void verifySetLogger(String elKey, Object testValue1, Object testValue2) throws Exception { PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(elKey); - String propertyName = this.getModel().propertyIdFor(property); + String propertyName = this.getModel().propertyIdOf(property); // test set custom logger. this.clearEvent(); this.setProperty(propertyName, testValue2); diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsAdapterTests.java index 13332ef711..cca9f8b905 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsAdapterTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/persistence/options/OptionsAdapterTests.java @@ -182,7 +182,7 @@ public class OptionsAdapterTests extends PersistenceUnitTestCase */ protected void verifySetTargetDatabase(String elKey, Object testValue1, Object testValue2) throws Exception { PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(elKey); - String propertyName = this.getModel().propertyIdFor(property); + String propertyName = this.getModel().propertyIdOf(property); // test set custom targetDatabase. this.clearEvent(); this.setProperty(propertyName, testValue2); @@ -236,7 +236,7 @@ public class OptionsAdapterTests extends PersistenceUnitTestCase */ protected void verifySetTargetServer(String elKey, Object testValue1, Object testValue2) throws Exception { PersistenceUnit.Property property = this.getPersistenceUnit().getProperty(elKey); - String propertyName = this.getModel().propertyIdFor(property); + String propertyName = this.getModel().propertyIdOf(property); // test set custom targetServer. this.clearEvent(); this.setProperty(propertyName, testValue2); |