Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortle2009-06-12 21:57:59 +0000
committertle2009-06-12 21:57:59 +0000
commitb9992a70fc32099778471b71a81a6238f0cbf3a4 (patch)
tree0955f1c1cd90b19638113dea75fbe985929187a6 /jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence
parenta9e4681dffb1654a7c14b42730b00ed998710b3d (diff)
downloadwebtools.dali-b9992a70fc32099778471b71a81a6238f0cbf3a4.tar.gz
webtools.dali-b9992a70fc32099778471b71a81a6238f0cbf3a4.tar.xz
webtools.dali-b9992a70fc32099778471b71a81a6238f0cbf3a4.zip
272982 - Memory leak in EntityCacheProperties
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence')
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkPersistenceUnitProperties.java19
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/PersistenceUnitProperties.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/CacheProperties.java115
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/Caching.java18
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/EclipseLinkCaching.java330
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/caching/Entity.java141
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/Customization.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/CustomizerProperties.java87
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/EclipseLinkCustomization.java253
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/customization/Entity.java105
10 files changed, 568 insertions, 510 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);
+ }
+}

Back to the top