Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortle2008-03-24 13:09:14 -0400
committertle2008-03-24 13:09:14 -0400
commit9a7304de2cc8ab1df95e62c172e290052fa532e2 (patch)
tree6a609e2317dcc5a1df15afa27a7a8e2202047098
parent4ecc932f3fd939a8568fa246d43347c77a2863ce (diff)
downloadwebtools.dali-9a7304de2cc8ab1df95e62c172e290052fa532e2.tar.gz
webtools.dali-9a7304de2cc8ab1df95e62c172e290052fa532e2.tar.xz
webtools.dali-9a7304de2cc8ab1df95e62c172e290052fa532e2.zip
Initial checkin.
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/.classpath12
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/.cvsignore3
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/.project28
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/META-INF/MANIFEST.MF19
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/build.properties5
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/plugin.properties20
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/plugin.xml12
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkFactory.java28
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkPlatform.java41
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/JptEclipseLinkCorePlugin.java59
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkJpaProperties.java135
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkPersistenceUnit.java44
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkPersistenceUnitProperties.java354
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkProperties.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/PersistenceUnitProperties.java31
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/PersistenceUnitPropertyListListener.java118
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/CacheProperties.java111
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/CacheType.java28
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/Caching.java77
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/EclipseLinkCaching.java455
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/DdlGenerationType.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/EclipseLinkSchemaGeneration.java222
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/OutputMode.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/SchemaGeneration.java59
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.classpath13
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.cvsignore5
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.project28
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF21
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/build.properties17
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/plugin.properties22
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/JptEclipseLinkCoreTests.java36
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/PersistenceUnitTestCase.java272
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java454
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingValueModelTests.java391
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/JptEclipseLinkCoreCachingTests.java33
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/JptEclipseLinkCoreSchemaGenerationTests.java35
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationAdapterTests.java248
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationBasicAdapterTests.java196
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationValueModelTests.java223
40 files changed, 3940 insertions, 0 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/.classpath b/jpa/plugins/org.eclipse.jpt.eclipselink.core/.classpath
new file mode 100644
index 0000000000..fb05e003fc
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/.classpath
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
+ <accessrules>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/core/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/utility/**"/>
+ </accessrules>
+ </classpathentry>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/.cvsignore b/jpa/plugins/org.eclipse.jpt.eclipselink.core/.cvsignore
new file mode 100644
index 0000000000..76e64421ad
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/.cvsignore
@@ -0,0 +1,3 @@
+bin
+@dot
+temp.folder
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/.project b/jpa/plugins/org.eclipse.jpt.eclipselink.core/.project
new file mode 100644
index 0000000000..7fa880fb4e
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jpt.eclipselink.core</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/.settings/org.eclipse.jdt.core.prefs b/jpa/plugins/org.eclipse.jpt.eclipselink.core/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..1b62192bf9
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Sun Feb 24 21:25:34 EST 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.eclipselink.core/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..2ec5fcae6c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/META-INF/MANIFEST.MF
@@ -0,0 +1,19 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Core Plug-in
+Bundle-SymbolicName: org.eclipse.jpt.eclipselink.core;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin
+Require-Bundle: org.eclipse.core.resources,
+ org.eclipse.core.runtime,
+ org.eclipse.emf.ecore,
+ org.eclipse.jdt.core,
+ org.eclipse.jpt.core,
+ org.eclipse.jpt.utility,
+ org.eclipse.wst.validation
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.jpt.eclipselink.core.internal;x-friends:="org.eclipse.jpt.eclipselink.ui,org.eclipse.jpt.eclipselink.core.tests",
+ org.eclipse.jpt.eclipselink.core.internal.context;x-friends:="org.eclipse.jpt.eclipselink.ui,org.eclipse.jpt.eclipselink.core.tests",
+ org.eclipse.jpt.eclipselink.core.internal.context.caching,
+ org.eclipse.jpt.eclipselink.core.internal.context.schema.generation
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/build.properties b/jpa/plugins/org.eclipse.jpt.eclipselink.core/build.properties
new file mode 100644
index 0000000000..e9863e281e
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/plugin.properties b/jpa/plugins/org.eclipse.jpt.eclipselink.core/plugin.properties
new file mode 100644
index 0000000000..a9bc4264d5
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/plugin.properties
@@ -0,0 +1,20 @@
+
+# <copyright>
+# </copyright>
+#
+# $Id: plugin.properties,v 1.1 2008/03/24 17:05:43 tle Exp $
+
+# ====================================================================
+# To code developer:
+# Do NOT change the properties between this line and the
+# "%%% END OF TRANSLATED PROPERTIES %%%" line.
+# Make a new property name, append to the end of the file and change
+# the code to use the new property.
+# ====================================================================
+
+# ====================================================================
+# %%% END OF TRANSLATED PROPERTIES %%%
+# ====================================================================
+
+pluginName = EclipseLinkJava Model
+providerName = www.example.org
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/plugin.xml b/jpa/plugins/org.eclipse.jpt.eclipselink.core/plugin.xml
new file mode 100644
index 0000000000..934e184dbf
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/plugin.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.jpt.core.jpaPlatform">
+ <jpaPlatform
+ class="org.eclipse.jpt.eclipselink.core.internal.EclipseLinkPlatform"
+ id="org.eclipse.eclipselink.platform"
+ label="EclipseLink">
+ </jpaPlatform>
+ </extension>
+</plugin>
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkFactory.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkFactory.java
new file mode 100644
index 0000000000..2f3268cfe1
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkFactory.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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;
+
+import org.eclipse.jpt.core.context.persistence.Persistence;
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.internal.platform.GenericJpaFactory;
+import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit;
+import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkPersistenceUnit;
+
+public class EclipseLinkFactory extends GenericJpaFactory
+{
+ protected EclipseLinkFactory() {
+ super();
+ }
+
+ @Override
+ public PersistenceUnit buildPersistenceUnit(Persistence parent, XmlPersistenceUnit persistenceUnit) {
+ return new EclipseLinkPersistenceUnit(parent, persistenceUnit);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkPlatform.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkPlatform.java
new file mode 100644
index 0000000000..88fc010281
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkPlatform.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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;
+
+import org.eclipse.jpt.core.JpaAnnotationProvider;
+import org.eclipse.jpt.core.JpaFactory;
+import org.eclipse.jpt.core.internal.platform.GenericJpaPlatform;
+
+public class EclipseLinkPlatform extends GenericJpaPlatform
+{
+ public static String ID = "org.eclipse.eclipselink.platform";
+
+ // ********* constructor *********
+ public EclipseLinkPlatform() {
+ super();
+ }
+
+ @Override
+ public String getId() {
+ return ID;
+ }
+
+ // ********* Model construction / updating *********
+ @Override
+ protected JpaFactory buildJpaFactory() {
+ return new EclipseLinkFactory();
+ }
+
+ // ********* java annotation support *********
+ @Override
+ public JpaAnnotationProvider annotationProvider() {
+ return super.annotationProvider();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/JptEclipseLinkCorePlugin.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/JptEclipseLinkCorePlugin.java
new file mode 100644
index 0000000000..f913fcded6
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/JptEclipseLinkCorePlugin.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class JptEclipseLinkCorePlugin extends Plugin
+{
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.jpt.eclipselink.core";
+
+ // The shared instance
+ private static JptEclipseLinkCorePlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public JptEclipseLinkCorePlugin() {}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static JptEclipseLinkCorePlugin getDefault() {
+ return plugin;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkJpaProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkJpaProperties.java
new file mode 100644
index 0000000000..87d04c2c9b
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkJpaProperties.java
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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;
+
+import java.util.ListIterator;
+
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.context.persistence.Property;
+import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching;
+import org.eclipse.jpt.eclipselink.core.internal.context.caching.EclipseLinkCaching;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.EclipseLinkSchemaGeneration;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.SchemaGeneration;
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter;
+import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.value.ListValueModel;
+import org.eclipse.jpt.utility.model.value.PropertyValueModel;
+
+/**
+ * EclipseLinkJpaProperties
+ */
+public class EclipseLinkJpaProperties extends AbstractModel
+ implements EclipseLinkProperties
+{
+ private PersistenceUnit persistenceUnit;
+
+ private SchemaGeneration schemaGeneration;
+ private Caching caching;
+
+ // private Logging logging;
+ private ListValueModel<Property> propertiesAdapter;
+ private ListValueModel<Property> propertyListAdapter;
+
+ // ********** constructors/initialization **********
+ public EclipseLinkJpaProperties(PersistenceUnit parent) {
+ super();
+ this.initialize(parent);
+ }
+
+ protected void initialize(PersistenceUnit parent) {
+ this.persistenceUnit = parent;
+ PropertyValueModel<PersistenceUnit> persistenceUnitHolder =
+ new SimplePropertyValueModel<PersistenceUnit>(this.persistenceUnit);
+
+ this.propertiesAdapter = this.buildPropertiesAdapter(persistenceUnitHolder);
+ this.propertyListAdapter = this.buildPropertyListAdapter(this.propertiesAdapter);
+
+ this.schemaGeneration = this.buildSchemaGeneration();
+ this.caching = this.buildCaching();
+ // TODO
+ // this.logging = this.buildLogging();
+ }
+
+ private ListValueModel<Property> buildPropertyListAdapter(ListValueModel<Property> propertiesAdapter) {
+ return new ItemPropertyListValueModelAdapter<Property>(propertiesAdapter, Property.VALUE_PROPERTY);
+ }
+
+ private ListValueModel<Property> buildPropertiesAdapter(PropertyValueModel<PersistenceUnit> subjectHolder) {
+ return new ListAspectAdapter<PersistenceUnit, Property>(subjectHolder, PersistenceUnit.PROPERTIES_LIST) {
+ @Override
+ protected ListIterator<Property> listIterator_() {
+ return this.subject.properties();
+ }
+
+ @Override
+ protected int size_() {
+ return this.subject.propertiesSize();
+ }
+ };
+ }
+
+ private SchemaGeneration buildSchemaGeneration() {
+ return new EclipseLinkSchemaGeneration(this.persistenceUnit(), this.propertyListAdapter());
+ }
+
+ private Caching buildCaching() {
+ return new EclipseLinkCaching(this.persistenceUnit(), this.propertyListAdapter());
+ }
+
+ // TODO
+ // private Logging buildLogging() {
+ // return new EclipseLinkLogging( this.persistenceUnit());
+ // }
+
+ // ******** Behavior *********
+ public SchemaGeneration getSchemaGeneration() {
+ return this.schemaGeneration;
+ }
+
+ public Caching getCaching() {
+ return this.caching;
+ }
+
+ // TODO
+ // public Logging getLogging() {
+ // return this.logging;
+ // }
+
+ public EclipseLinkProperties eclipseLinkProperties() {
+ return this;
+ }
+
+ public ListValueModel<Property> propertiesAdapter() {
+ return this.propertiesAdapter;
+ }
+
+ public ListValueModel<Property> propertyListAdapter() {
+ return this.propertyListAdapter;
+ }
+
+ public PersistenceUnit persistenceUnit() {
+ return this.persistenceUnit;
+ }
+
+ public boolean itemIsProperty(Property item) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void propertyChanged(PropertyChangeEvent event) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String propertyIdFor(Property property) {
+ throw new UnsupportedOperationException();
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkPersistenceUnit.java
new file mode 100644
index 0000000000..3d6de6a8f5
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkPersistenceUnit.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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;
+
+import org.eclipse.jpt.core.context.persistence.Persistence;
+import org.eclipse.jpt.core.internal.context.persistence.GenericPersistenceUnit;
+import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit;
+import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.SchemaGeneration;
+
+/**
+ * EclipseLinkPersistenceUnit
+ */
+public class EclipseLinkPersistenceUnit extends GenericPersistenceUnit
+{
+ private EclipseLinkProperties eclipseLinkProperties;
+
+ // ********** constructors/initialization **********
+ public EclipseLinkPersistenceUnit(Persistence parent, XmlPersistenceUnit persistenceUnit) {
+ super(parent, persistenceUnit);
+ }
+
+ protected void initialize(XmlPersistenceUnit xmlPersistenceUnit) {
+ super.initialize(xmlPersistenceUnit);
+ this.eclipseLinkProperties = new EclipseLinkJpaProperties(this);
+ }
+
+ // ******** Behavior *********
+ public SchemaGeneration getSchemaGeneration() {
+ return this.eclipseLinkProperties.getSchemaGeneration();
+ }
+
+ public Caching getCaching() {
+ return this.eclipseLinkProperties.getCaching();
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkPersistenceUnitProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkPersistenceUnitProperties.java
new file mode 100644
index 0000000000..6ddc558730
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkPersistenceUnitProperties.java
@@ -0,0 +1,354 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.context.persistence.Property;
+import org.eclipse.jpt.utility.internal.ClassTools;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.utility.model.value.ListValueModel;
+
+/**
+ * EclipseLinkPersistenceUnitProperties
+ *
+ * Listens to the propertyListAdapter
+ */
+public abstract class EclipseLinkPersistenceUnitProperties extends AbstractModel
+ implements PersistenceUnitProperties
+{
+ private PersistenceUnit persistenceUnit;
+
+ private PersistenceUnitPropertyListListener propertyListListener;
+
+ // key = EclipseLink property key; value = property id
+ private Map<String, String> propertyNames;
+
+ // ********** constructors / initialization **********
+ protected EclipseLinkPersistenceUnitProperties(
+ PersistenceUnit parent,
+ ListValueModel<Property> propertyListAdapter) {
+ super();
+ this.initialize(parent, propertyListAdapter);
+ }
+
+ protected void initialize(
+ PersistenceUnit parent,
+ ListValueModel<Property> propertyListAdapter) {
+ this.persistenceUnit = parent;
+
+ this.propertyListListener = new PersistenceUnitPropertyListListener(this);
+ propertyListAdapter.addListChangeListener(ListValueModel.LIST_VALUES, this.propertyListListener);
+
+ this.initializePropertyNames();
+ this.initializeProperties();
+ }
+
+ protected void initializePropertyNames() {
+ this.propertyNames = new HashMap<String, String>();
+ this.addPropertyNames(this.propertyNames);
+ }
+
+ /**
+ * Initializes properties with values from the persistence unit.
+ */
+ protected abstract void initializeProperties();
+
+ // ********** behavior **********
+ protected PersistenceUnit persistenceUnit() {
+ PersistenceUnit pu = this.persistenceUnit;
+ return pu;
+ }
+
+ public PersistenceUnitPropertyListListener propertyListListener() {
+ return this.propertyListListener;
+ }
+
+ private Map<String, String> propertyNames() {
+ return this.propertyNames;
+ }
+
+ /**
+ * Adds property names key/value pairs, used by the methods: itemIsProperty
+ * and propertyIdFor.
+ *
+ * key = EclipseLink property key; value = property id
+ */
+ protected abstract void addPropertyNames(Map<String, String> propertyNames);
+
+ /**
+ * Method used for identifying the given property.
+ */
+ public boolean itemIsProperty(Property item) {
+ return this.propertyNames().keySet().contains(item.getName());
+ }
+
+ /**
+ * Returns the property name used for change notification of the given
+ * property.
+ */
+ public String propertyIdFor(Property property) {
+ String propertyId = this.propertyNames().get(property.getName());
+ if (propertyId == null) {
+ throw new IllegalArgumentException("Illegal property: " + property.toString());
+ }
+ return propertyId;
+ }
+
+ protected String eclipseLinkKeyFor(String propertyId) {
+ for (String eclipseLinkKey : this.propertyNames().keySet()) {
+ if (this.propertyNames().get(eclipseLinkKey).equals(propertyId)) {
+ return eclipseLinkKey;
+ }
+ }
+ throw new IllegalArgumentException("Illegal property: " + propertyId);
+ }
+
+ // ****** get/set String convenience methods *******
+ /**
+ * Returns the String value of the given Property from the PersistenceXml.
+ */
+ protected String getStringValue(String elKey) {
+ return this.getStringValue(elKey, null);
+ }
+
+ protected String getStringValue(String key, String keySuffix) {
+ String elKey = (keySuffix == null) ? key : key + keySuffix;
+ if (this.persistenceUnit().containsProperty(elKey)) {
+ // TOREVIEW - handle incorrect String in persistence.xml
+ return this.persistenceUnit().getProperty(elKey).getValue();
+ }
+ return null;
+ }
+
+ /**
+ * Put the given String value into the PersistenceXml.
+ *
+ * @param key -
+ * EclipseLink Key
+ */
+ protected void putStringValue(String key, String newValue) {
+ this.putStringValue(key, null, newValue, false);
+ }
+
+ protected void putStringValue(String key, String newValue, boolean allowDuplicate) {
+ this.putStringValue(key, null, newValue, allowDuplicate);
+ }
+
+ protected void putStringValue(String key, String keySuffix, String newValue, boolean allowDuplicate) {
+ String elKey = (keySuffix == null) ? key : key + keySuffix;
+ if (newValue == null) {
+ this.persistenceUnit().removeProperty(elKey);
+ }
+ else {
+ this.persistenceUnit().putProperty(elKey, newValue, allowDuplicate);
+ }
+ }
+
+ // ****** Integer convenience methods *******
+ /**
+ * Returns the Integer value of the given Property from the PersistenceXml.
+ */
+ protected Integer getIntegerValue(String elKey) {
+ return this.getIntegerValue(elKey, null);
+ }
+
+ protected Integer getIntegerValue(String key, String keySuffix) {
+ String elKey = (keySuffix == null) ? key : key + keySuffix;
+ if (this.persistenceUnit().containsProperty(elKey)) {
+ String eclipseLinkValue = this.persistenceUnit().getProperty(elKey).getValue();
+ // TOREVIEW - handle incorrect eclipseLinkValue String in
+ // persistence.xml
+ return getIntegerValueOf(eclipseLinkValue);
+ }
+ return null;
+ }
+
+ /**
+ * Put the given Integer value into the PersistenceXml.
+ *
+ * @param key -
+ * EclipseLink Key
+ */
+ protected void putIntegerValue(String key, Integer newValue) {
+ this.putIntegerValue(key, null, newValue, false);
+ }
+
+ protected void putIntegerValue(String key, Integer newValue, boolean allowDuplicate) {
+ this.putIntegerValue(key, null, newValue, allowDuplicate);
+ }
+
+ protected void putIntegerValue(String key, String keySuffix, Integer newValue, boolean allowDuplicate) {
+ String elKey = (keySuffix == null) ? key : key + keySuffix;
+ if (newValue == null) {
+ this.persistenceUnit().removeProperty(elKey);
+ }
+ else {
+ this.persistenceUnit().putProperty(elKey, newValue.toString(), allowDuplicate);
+ }
+ }
+
+ // ****** Boolean convenience methods *******
+ /**
+ * Returns the Boolean value of the given Property from the PersistenceXml.
+ */
+ protected Boolean getBooleanValue(String elKey) {
+ return this.getBooleanValue(elKey, null);
+ }
+
+ protected Boolean getBooleanValue(String key, String keySuffix) {
+ String elKey = (keySuffix == null) ? key : key + keySuffix;
+ if (this.persistenceUnit().containsProperty(elKey)) {
+ String eclipseLinkValue = this.persistenceUnit().getProperty(elKey).getValue();
+ // TOREVIEW - handle incorrect eclipseLinkValue String in
+ // persistence.xml
+ return getBooleanValueOf(eclipseLinkValue);
+ }
+ return null;
+ }
+
+ /**
+ * Put the given Boolean value into the PersistenceXml.
+ *
+ * @param key -
+ * EclipseLink Key
+ */
+ protected void putBooleanValue(String key, Boolean newValue) {
+ this.putBooleanValue(key, null, newValue, false);
+ }
+
+ protected void putBooleanValue(String key, Boolean newValue, boolean allowDuplicate) {
+ this.putBooleanValue(key, null, newValue, allowDuplicate);
+ }
+
+ protected void putBooleanValue(String key, String keySuffix, Boolean newValue, boolean allowDuplicate) {
+ String elKey = (keySuffix == null) ? key : key + keySuffix;
+ if (newValue == null) {
+ this.persistenceUnit().removeProperty(elKey);
+ }
+ else {
+ this.persistenceUnit().putProperty(elKey, newValue.toString(), allowDuplicate);
+ }
+ }
+
+ // ****** Enum convenience methods *******
+ /**
+ * Returns the Enum value of the given Property from the PersistenceXml.
+ */
+ protected <T extends Enum<T>> T getEnumValue(String elKey, T[] enumValues) {
+ return getEnumValue(elKey, null, enumValues);
+ }
+
+ protected <T extends Enum<T>> T getEnumValue(String key, String keySuffix, T[] enumValues) {
+ String elKey = (keySuffix == null) ? key : key + keySuffix;
+ if (this.persistenceUnit().containsProperty(elKey)) {
+ String eclipseLinkValue = this.persistenceUnit().getProperty(elKey).getValue();
+ // TOREVIEW - handle incorrect eclipseLinkValue String in
+ // persistence.xml
+ return getEnumValueOf(eclipseLinkValue, enumValues);
+ }
+ return null;
+ }
+
+ /**
+ * Put the given Enum value into the PersistenceXml.
+ *
+ * @param key -
+ * EclipseLink Key
+ */
+ protected <T extends Enum<T>> void putEnumValue(String key, T newValue) {
+ this.putEnumValue(key, null, newValue, false);
+ }
+
+ protected <T extends Enum<T>> void putEnumValue(String key, T newValue, boolean allowDuplicate) {
+ this.putEnumValue(key, null, newValue, allowDuplicate);
+ }
+
+ protected <T extends Enum<T>> void putEnumValue(String key, String keySuffix, T newValue, boolean allowDuplicate) {
+ String elKey = (keySuffix == null) ? key : key + keySuffix;
+ if (newValue == null) {
+ this.persistenceUnit().removeProperty(elKey);
+ }
+ else {
+ this.persistenceUnit().putProperty(elKey, getEclipseLinkStringValue(newValue), allowDuplicate);
+ }
+ }
+
+ // ******** Convenience methods ********
+ /**
+ * Put into persistenceUnit properties.
+ *
+ * @param key -
+ * property name
+ * @param value -
+ * property value
+ */
+ protected void putProperty(String key, Object value) {
+ String elKey = this.eclipseLinkKeyFor(key);
+ if (value == null)
+ this.removeProperty(elKey);
+ else if (value.getClass().isEnum())
+ this.putEnumValue(elKey, (Enum) value);
+ else
+ throw new NoSuchMethodError("putProperty not supported yet");
+ // TODO
+ // this.putProperty_( elKey, value);
+ }
+
+ /**
+ * Removes a property with the given key.
+ */
+ protected void removeProperty(String elKey) {
+ this.persistenceUnit().removeProperty(elKey);
+ }
+
+ protected Set<Property> getPropertiesSetWithPrefix(String keyPrefix) {
+ return CollectionTools.set(this.persistenceUnit().propertiesWithPrefix(keyPrefix));
+ }
+
+ /** ****** Static methods ******* */
+ /**
+ * Returns the EclipseLink value string for the enum.
+ */
+ public static String getEclipseLinkStringValue(Enum value) {
+ return (String) ClassTools.staticFieldValue(value.getClass(), value.toString().toUpperCase());
+ }
+
+ /**
+ * Returns the enum constant of the specified enum type with the specified
+ * EclipseLink value string.
+ */
+ public static <T extends Enum<T>> T getEnumValueOf(String eclipseLinkValueString, T[] enumValues) {
+ for (T mode : enumValues) {
+ if (getEclipseLinkStringValue(mode).equals(eclipseLinkValueString)) {
+ return mode;
+ }
+ }
+ return null;
+ }
+
+ public static Boolean getBooleanValueOf(String eclipseLinkValueString) {
+ if (eclipseLinkValueString == null) {
+ return null;
+ }
+ return Boolean.valueOf(eclipseLinkValueString);
+ }
+
+ public static Integer getIntegerValueOf(String eclipseLinkValueString) {
+ if (eclipseLinkValueString == null) {
+ return null;
+ }
+ return Integer.valueOf(eclipseLinkValueString);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkProperties.java
new file mode 100644
index 0000000000..2ceebe8900
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkProperties.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+* Copyright (c) 2008 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;
+
+import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.SchemaGeneration;
+
+/**
+ * EclipseLinkProperties
+ */
+public interface EclipseLinkProperties extends PersistenceUnitProperties
+{
+ SchemaGeneration getSchemaGeneration();
+ static final String SCHEMA_GENERATION_PROPERTY = "schemaGenerationProperty";
+
+ Caching getCaching();
+ static final String CACHING_PROPERTY = "cachingProperty";
+
+//TODO
+// Logging getLogging();
+ static final String LOGGING_PROPERTY = "loggingProperty";
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/PersistenceUnitProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/PersistenceUnitProperties.java
new file mode 100644
index 0000000000..ab66c2ea97
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/PersistenceUnitProperties.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+* Copyright (c) 2007, 2008 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;
+
+import org.eclipse.jpt.core.context.persistence.Property;
+import org.eclipse.jpt.utility.model.Model;
+import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
+
+/**
+ * PersistenceUnitProperties
+ */
+public interface PersistenceUnitProperties extends Model, PropertyChangeListener
+{
+ /**
+ * Method used for identifying the given property.
+ */
+ boolean itemIsProperty( Property item);
+
+ /**
+ * Returns the property name used for change notification of the given property.
+ */
+ String propertyIdFor( Property property);
+
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/PersistenceUnitPropertyListListener.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/PersistenceUnitPropertyListListener.java
new file mode 100644
index 0000000000..e3455e703f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/PersistenceUnitPropertyListListener.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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;
+
+import java.util.Iterator;
+
+import org.eclipse.jpt.core.context.persistence.Property;
+import org.eclipse.jpt.utility.model.Model;
+import org.eclipse.jpt.utility.model.event.ListChangeEvent;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.listener.ListChangeListener;
+import org.eclipse.jpt.utility.model.value.ListValueModel;
+
+/**
+ * PersistenceUnitPropertyListListener Notifies the given parent when a change
+ * occured in JPT PersistenceUnit properties
+ */
+public class PersistenceUnitPropertyListListener implements ListChangeListener
+{
+ private PersistenceUnitProperties parent;
+
+ // ********** constructors / initialization **********
+ public PersistenceUnitPropertyListListener(PersistenceUnitProperties parent) {
+ this.parent = parent;
+ }
+
+ // ********** Behavior **********
+ protected boolean add(Property newItem, Model source) {
+ if (this.model().itemIsProperty(newItem)) {
+ String propertyName = this.model().propertyIdFor(newItem);
+ this.model().propertyChanged(
+ new PropertyChangeEvent(source, propertyName, null, newItem));
+ return true;
+ }
+ return false;
+ }
+
+ protected boolean remove(Property item, Model source) {
+ if (this.model().itemIsProperty(item)) {
+ String propertyName = this.model().propertyIdFor(item);
+ this.model().propertyChanged(
+ new PropertyChangeEvent(source, propertyName, item, null)); // oldItem is the removed property
+ return true;
+ }
+ return false;
+ }
+
+ // replace
+ protected Property set(Property newItem, Model source) {
+ if (this.model().itemIsProperty(newItem)) {
+ String propertyName = this.model().propertyIdFor(newItem);
+ this.model().propertyChanged(
+ new PropertyChangeEvent(source, propertyName, null, newItem)); // oldItem unknown
+ return newItem;
+ }
+ return null;
+ }
+
+ // ********** ListChangeListener implementation **********
+ public void itemsAdded(ListChangeEvent e) {
+ for (Iterator<Property> stream = this.items(e); stream.hasNext();) {
+ this.add(stream.next(), e.getSource());
+ }
+ }
+
+ public void itemsRemoved(ListChangeEvent e) {
+ for (Iterator<Property> stream = this.items(e); stream.hasNext();) {
+ this.remove(stream.next(), e.getSource());
+ }
+ }
+
+ public void itemsReplaced(ListChangeEvent e) {
+ // ItemAspectListValueModelAdapter(270) does not provide old value
+ for (Iterator<Property> newStream = this.items(e); newStream.hasNext();) {
+ this.set(newStream.next(), e.getSource());
+ }
+ }
+
+ public void itemsMoved(ListChangeEvent e) {
+ throw new UnsupportedOperationException("source: " + e.getSource() + " - aspect: " + e.aspectName());
+ }
+
+ public void listCleared(ListChangeEvent e) {
+ throw new UnsupportedOperationException("source: " + e.getSource() + " - aspect: " + e.aspectName());
+ }
+
+ public void listChanged(ListChangeEvent e) {
+ throw new UnsupportedOperationException("source: " + e.getSource() + " - aspect: " + e.aspectName());
+ }
+
+ // ********** standard methods **********
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName() + "( " + this.model().getClass().getSimpleName() + ")";
+ }
+
+ // ********** internal methods **********
+ private PersistenceUnitProperties model() {
+ return this.parent;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Iterator<Property> items(ListChangeEvent event) {
+ return (Iterator<Property>) event.items();
+ }
+
+ @SuppressWarnings("unchecked")
+ private ListValueModel<Property> getSource(ListChangeEvent event) {
+ return (ListValueModel<Property>) event.getSource();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/CacheProperties.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/CacheProperties.java
new file mode 100644
index 0000000000..f6c4e83155
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/CacheProperties.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.caching;
+
+import java.io.Serializable;
+
+import org.eclipse.jpt.utility.internal.StringTools;
+
+/**
+ * CacheProperties
+ */
+public class CacheProperties implements Cloneable, Serializable
+{
+ private String entityName;
+
+ 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 synchronized CacheProperties clone() {
+ try {
+ return (CacheProperties)super.clone();
+ }
+ catch (CloneNotSupportedException ex) {
+ throw new InternalError();
+ }
+ }
+
+ // ********** getter/setter **********
+ public String getEntityName() {
+ return entityName;
+ }
+
+ public CacheType getType() {
+ return type;
+ }
+
+ public void setType(CacheType cacheType) {
+ this.type = cacheType;
+ }
+
+ public Integer getSize() {
+ return size;
+ }
+
+ public void setSize(Integer cacheSize) {
+ this.size = cacheSize;
+ }
+
+ public Boolean isShared() {
+ return 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/caching/CacheType.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/CacheType.java
new file mode 100644
index 0000000000..48afaaec72
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/CacheType.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+* Copyright (c) 2008 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.caching;
+
+/**
+ * CacheType
+ */
+public enum CacheType {
+ full,
+ hard_weak,
+ none,
+ soft_weak,
+ weak;
+
+ // EclipseLink value string
+ public static final String FULL = "Full";
+ public static final String HARD_WEAK = "HardWeak";
+ public static final String NONE = "NONE";
+ public static final String SOFT_WEAK = "SoftWeak";
+ public static final String WEAK = "Weak";
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/Caching.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/Caching.java
new file mode 100644
index 0000000000..d2f370e1b3
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/Caching.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+* Copyright (c) 2008 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.caching;
+
+import java.util.ListIterator;
+
+import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties;
+
+/**
+ * Caching
+ */
+public interface Caching extends PersistenceUnitProperties
+{
+ CacheType getDefaultCacheTypeDefault();
+ CacheType getCacheTypeDefault();
+ void setCacheTypeDefault(CacheType cacheTypeDefault);
+ static final String CACHE_TYPE_DEFAULT_PROPERTY = "cacheTypeDefaultProperty";
+ // EclipseLink key string
+ static final String ECLIPSELINK_CACHE_TYPE_DEFAULT = "eclipselink.cache.type.default";
+ static final CacheType DEFAULT_CACHE_TYPE_DEFAULT = CacheType.soft_weak;
+
+ Integer getDefaultCacheSizeDefault();
+ Integer getCacheSizeDefault();
+ void setCacheSizeDefault(Integer cacheSizeDefault);
+ static final String CACHE_SIZE_DEFAULT_PROPERTY = "cacheSizeDefaultProperty";
+ // EclipseLink key string
+ static final String ECLIPSELINK_CACHE_SIZE_DEFAULT = "eclipselink.cache.size.default";
+ static final Integer DEFAULT_CACHE_SIZE_DEFAULT = 100;
+
+ Boolean getDefaultSharedCacheDefault();
+ Boolean getSharedCacheDefault();
+ void setSharedCacheDefault(Boolean sharedCacheDefault);
+ static final String SHARED_CACHE_DEFAULT_PROPERTY = "sharedCacheDefaultProperty";
+ // EclipseLink key string
+ static final String ECLIPSELINK_CACHE_SHARED_DEFAULT = "eclipselink.cache.shared.default";
+ static final Boolean DEFAULT_SHARED_CACHE_DEFAULT = Boolean.TRUE;
+
+
+ CacheType getDefaultCacheType();
+ CacheType getCacheType(String entityName);
+ void setCacheType(CacheType cacheType, String entityName);
+ static final String CACHE_TYPE_PROPERTY = "cacheTypeProperty";
+ // EclipseLink key string
+ static final String ECLIPSELINK_CACHE_TYPE = "eclipselink.cache.type.";
+ static final CacheType DEFAULT_CACHE_TYPE = CacheType.soft_weak;
+
+ Integer getDefaultCacheSize();
+ Integer getCacheSize(String entityName);
+ void setCacheSize(Integer cacheSize, String entityName);
+ static final String CACHE_SIZE_PROPERTY = "cacheSizeProperty";
+ // EclipseLink key string
+ static final String ECLIPSELINK_CACHE_SIZE = "eclipselink.cache.size.";
+ static final Integer DEFAULT_CACHE_SIZE = 1000;
+
+ Boolean getDefaultSharedCache();
+ Boolean getSharedCache(String entityName);
+ void setSharedCache(Boolean sharedCache, String entityName);
+ static final String SHARED_CACHE_PROPERTY = "sharedCacheProperty";
+ // EclipseLink key string
+ static final String ECLIPSELINK_SHARED_CACHE = "eclipselink.cache.shared.";
+ static final Boolean DEFAULT_SHARED_CACHE = true;
+
+
+ ListIterator<String> entities();
+ int entitiesSize();
+ String addEntity(String entity);
+ void removeEntity(String entity);
+ String ENTITIES_LIST_PROPERTY = "entitiesList";
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/EclipseLinkCaching.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/EclipseLinkCaching.java
new file mode 100644
index 0000000000..ab3802bd71
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/caching/EclipseLinkCaching.java
@@ -0,0 +1,455 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.caching;
+
+import java.util.HashMap;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.context.persistence.Property;
+import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkPersistenceUnitProperties;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.value.ListValueModel;
+
+/**
+ * EclipseLinkCaching encapsulates EclipseLink Caching properties.
+ */
+public class EclipseLinkCaching extends EclipseLinkPersistenceUnitProperties
+ implements Caching
+{
+ // ********** EclipseLink properties **********
+ private CacheType cacheTypeDefault;
+ private Integer cacheSizeDefault;
+ private Boolean sharedCacheDefault;
+
+ // key = Entity name ; value = Cache
+ private Map<String, CacheProperties> entitiesCache;
+
+ // ********** constructors **********
+ public EclipseLinkCaching(PersistenceUnit parent, ListValueModel<Property> propertyListAdapter) {
+ super(parent, propertyListAdapter);
+ }
+
+ // ********** initialization **********
+ /**
+ * Initializes properties with values from the persistence unit.
+ */
+ @Override
+ protected void initializeProperties() {
+ // TOREVIEW - handle incorrect String in persistence.xml
+ this.entitiesCache =
+ new HashMap<String, CacheProperties>();
+ this.cacheTypeDefault =
+ this.getEnumValue(ECLIPSELINK_CACHE_TYPE_DEFAULT, CacheType.values());
+ this.cacheSizeDefault =
+ this.getIntegerValue(ECLIPSELINK_CACHE_SIZE_DEFAULT);
+ this.sharedCacheDefault =
+ this.getBooleanValue(ECLIPSELINK_CACHE_SHARED_DEFAULT);
+ Set<Property> propertiesCacheType =
+ this.getPropertiesSetWithPrefix(ECLIPSELINK_CACHE_TYPE);
+ Set<Property> propertiesCacheSize =
+ this.getPropertiesSetWithPrefix(ECLIPSELINK_CACHE_SIZE);
+ Set<Property> propertiesSharedCache =
+ this.getPropertiesSetWithPrefix(ECLIPSELINK_SHARED_CACHE);
+
+ this.initializeEntitiesCacheType(propertiesCacheType);
+ this.initializeEntitiesCacheSize(propertiesCacheSize);
+ this.initializeEntitiesSharedCache(propertiesSharedCache);
+ }
+
+ private void initializeEntitiesCacheType(Set<Property> propertiesCacheType) {
+ for (Property property : propertiesCacheType) {
+ String entityName = this.entityName(property);
+ CacheType cacheType = getEnumValueOf(property.getValue(), CacheType.values());
+ setCacheType_(cacheType, entityName);
+ }
+ }
+
+ private void initializeEntitiesCacheSize(Set<Property> propertiesCacheSize) {
+ for (Property property : propertiesCacheSize) {
+ String entityName = this.entityName(property);
+ setCacheSize_(property, entityName);
+ }
+ }
+
+ private void initializeEntitiesSharedCache(Set<Property> propertiesSharedCache) {
+ for (Property property : propertiesSharedCache) {
+ String entityName = this.entityName(property);
+ setSharedCache_(property, entityName);
+ }
+ }
+
+ // ********** behavior **********
+ /**
+ * Adds property names key/value pairs, where: key = EclipseLink property
+ * key; value = property id
+ */
+ @Override
+ protected void addPropertyNames(Map<String, String> propertyNames) {
+ propertyNames.put(
+ ECLIPSELINK_CACHE_TYPE_DEFAULT,
+ CACHE_TYPE_DEFAULT_PROPERTY);
+ propertyNames.put(
+ ECLIPSELINK_CACHE_SIZE_DEFAULT,
+ CACHE_SIZE_DEFAULT_PROPERTY);
+ propertyNames.put(
+ ECLIPSELINK_CACHE_SHARED_DEFAULT,
+ SHARED_CACHE_DEFAULT_PROPERTY);
+
+ // Don't need to initialize propertyNames for:
+ // cacheType, sharedCache, cacheSize
+ }
+
+ /**
+ * Method used for identifying the given property.
+ */
+ @Override
+ public boolean itemIsProperty(Property item) {
+ boolean isProperty = super.itemIsProperty(item);
+
+ if (isProperty) {
+ return true;
+ }
+ else if (item.getName().startsWith(ECLIPSELINK_CACHE_TYPE) ||
+ item.getName().startsWith(ECLIPSELINK_CACHE_SIZE) ||
+ item.getName().startsWith(ECLIPSELINK_SHARED_CACHE)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns the property name used for change notification of the given
+ * property.
+ */
+ @Override
+ public String propertyIdFor(Property property) {
+ try {
+ return super.propertyIdFor(property);
+ }
+ catch (IllegalArgumentException e) {
+ if (property.getName().startsWith(ECLIPSELINK_CACHE_TYPE)) {
+ return CACHE_TYPE_PROPERTY;
+ }
+ else if (property.getName().startsWith(ECLIPSELINK_CACHE_SIZE)) {
+ return CACHE_SIZE_PROPERTY;
+ }
+ else if (property.getName().startsWith(ECLIPSELINK_SHARED_CACHE)) {
+ return SHARED_CACHE_PROPERTY;
+ }
+ }
+ throw new IllegalArgumentException("Illegal property: " + property.toString());
+ }
+
+ public void propertyChanged(PropertyChangeEvent event) {
+ String aspectName = event.aspectName();
+ if (aspectName.equals(CACHE_TYPE_DEFAULT_PROPERTY)) {
+ this.cacheTypeDefaultChanged(event);
+ }
+ else if (aspectName.equals(CACHE_SIZE_DEFAULT_PROPERTY)) {
+ this.cacheSizeDefaultChanged(event);
+ }
+ else if (aspectName.equals(SHARED_CACHE_DEFAULT_PROPERTY)) {
+ this.sharedCacheDefaultChanged(event);
+ }
+ else if (aspectName.equals(CACHE_TYPE_PROPERTY)) {
+ this.cacheTypeChanged(event);
+ }
+ else if (aspectName.equals(CACHE_SIZE_PROPERTY)) {
+ this.cacheSizeChanged(event);
+ }
+ else if (aspectName.equals(SHARED_CACHE_PROPERTY)) {
+ this.sharedCacheChanged(event);
+ }
+ else {
+ throw new IllegalArgumentException("Illegal event received - property not applicable: " + aspectName);
+ }
+ return;
+ }
+
+ // ********** CacheType **********
+ public CacheType getCacheType(String entityName) {
+ CacheProperties cache = this.cachePropertiesOf(entityName);
+ return (cache == null) ? null : cache.getType();
+ }
+
+ public void setCacheType(CacheType newCacheType, String entityName) {
+ CacheProperties old = this.setCacheType_(newCacheType, entityName);
+ this.firePropertyChanged(CACHE_TYPE_PROPERTY, old, this.cachePropertiesOf(entityName));
+ this.putEnumValue(ECLIPSELINK_CACHE_TYPE, entityName, newCacheType, false);
+ }
+
+ private void cacheTypeChanged(PropertyChangeEvent event) {
+ Property property = (Property) event.newValue();
+ // property == null when removed
+ String entityName = (property == null) ? this.entityName((Property) event.oldValue()) : this.entityName(property);
+ CacheProperties old = this.setCacheType_(property, entityName);
+ this.firePropertyChanged(event.aspectName(), old, this.cachePropertiesOf(entityName));
+ }
+
+ public CacheType getDefaultCacheType() {
+ return DEFAULT_CACHE_TYPE;
+ }
+
+ // ********** CacheSize **********
+ public Integer getCacheSize(String entityName) {
+ CacheProperties cache = this.cachePropertiesOf(entityName);
+ return (cache == null) ? null : cache.getSize();
+ }
+
+ public void setCacheSize(Integer newCacheSize, String entityName) {
+ CacheProperties old = this.setCacheSize_(newCacheSize, entityName);
+ this.firePropertyChanged(CACHE_SIZE_PROPERTY, old, this.cachePropertiesOf(entityName));
+ this.putIntegerValue(ECLIPSELINK_CACHE_SIZE + entityName, newCacheSize);
+ }
+
+ private void cacheSizeChanged(PropertyChangeEvent event) {
+ Property property = (Property) event.newValue();
+ // property == null when removed
+ String entityName = (property == null) ? this.entityName((Property) event.oldValue()) : this.entityName(property);
+ CacheProperties old = this.setCacheSize_(property, entityName);
+ this.firePropertyChanged(event.aspectName(), old, this.cachePropertiesOf(entityName));
+ }
+
+ public Integer getDefaultCacheSize() {
+ return DEFAULT_CACHE_SIZE;
+ }
+
+ // ********** SharedCache **********
+ public Boolean getSharedCache(String entityName) {
+ CacheProperties cache = this.cachePropertiesOf(entityName);
+ return (cache == null) ? null : cache.isShared();
+ }
+
+ public void setSharedCache(Boolean newSharedCache, String entityName) {
+ CacheProperties old = this.setSharedCache_(newSharedCache, entityName);
+ this.firePropertyChanged(SHARED_CACHE_PROPERTY, old, this.cachePropertiesOf(entityName));
+ this.putBooleanValue(ECLIPSELINK_SHARED_CACHE + entityName, newSharedCache);
+ }
+
+ private void sharedCacheChanged(PropertyChangeEvent event) {
+ String entityName;
+ Property newProperty = (Property) event.newValue();
+ // property == null when removed
+ entityName = (newProperty == null) ? this.entityName((Property) event.oldValue()) : this.entityName(newProperty);
+ CacheProperties old = this.setSharedCache_(newProperty, entityName);
+ this.firePropertyChanged(event.aspectName(), old, this.cachePropertiesOf(entityName));
+ }
+
+ public Boolean getDefaultSharedCache() {
+ return DEFAULT_SHARED_CACHE;
+ }
+
+ // ********** CacheTypeDefault **********
+ public CacheType getCacheTypeDefault() {
+ return this.cacheTypeDefault;
+ }
+
+ public void setCacheTypeDefault(CacheType newCacheTypeDefault) {
+ CacheType old = this.cacheTypeDefault;
+ this.cacheTypeDefault = newCacheTypeDefault;
+ this.firePropertyChanged(CACHE_TYPE_DEFAULT_PROPERTY, old, newCacheTypeDefault);
+ this.putProperty(CACHE_TYPE_DEFAULT_PROPERTY, newCacheTypeDefault);
+ }
+
+ private void cacheTypeDefaultChanged(PropertyChangeEvent event) {
+ String stringValue = (event.newValue() == null) ? null : ((Property) event.newValue()).getValue();
+ CacheType newValue = getEnumValueOf(stringValue, CacheType.values());
+ CacheType old = this.cacheTypeDefault;
+ this.cacheTypeDefault = newValue;
+ this.firePropertyChanged(event.aspectName(), old, newValue);
+ }
+
+ public CacheType getDefaultCacheTypeDefault() {
+ return DEFAULT_CACHE_TYPE_DEFAULT;
+ }
+
+ // ********** CacheSizeDefault **********
+ public Integer getCacheSizeDefault() {
+ return this.cacheSizeDefault;
+ }
+
+ public void setCacheSizeDefault(Integer newCacheSizeDefault) {
+ Integer old = this.cacheSizeDefault;
+ this.cacheSizeDefault = newCacheSizeDefault;
+ this.firePropertyChanged(CACHE_SIZE_DEFAULT_PROPERTY, old, newCacheSizeDefault);
+ // TODO - use putProperty( String key, Object value) instead
+ this.putIntegerValue(ECLIPSELINK_CACHE_SIZE_DEFAULT, newCacheSizeDefault);
+ }
+
+ private void cacheSizeDefaultChanged(PropertyChangeEvent event) {
+ String stringValue = (event.newValue() == null) ? null : ((Property) event.newValue()).getValue();
+ Integer newValue = getIntegerValueOf(stringValue);
+ Integer old = this.cacheSizeDefault;
+ this.cacheSizeDefault = newValue;
+ this.firePropertyChanged(event.aspectName(), old, newValue);
+ }
+
+ public Integer getDefaultCacheSizeDefault() {
+ return DEFAULT_CACHE_SIZE_DEFAULT;
+ }
+
+ // ********** SharedCacheDefault **********
+ public Boolean getSharedCacheDefault() {
+ return this.sharedCacheDefault;
+ }
+
+ public void setSharedCacheDefault(Boolean newSharedCacheDefault) {
+ Boolean old = this.sharedCacheDefault;
+ this.sharedCacheDefault = newSharedCacheDefault;
+ this.firePropertyChanged(SHARED_CACHE_DEFAULT_PROPERTY, old, newSharedCacheDefault);
+ // TODO - use putProperty( String key, Object value) instead
+ this.putBooleanValue(ECLIPSELINK_CACHE_SHARED_DEFAULT, newSharedCacheDefault);
+ }
+
+ private void sharedCacheDefaultChanged(PropertyChangeEvent event) {
+ String stringValue = (event.newValue() == null) ? null : ((Property) event.newValue()).getValue();
+ Boolean newValue = getBooleanValueOf(stringValue);
+ Boolean old = this.sharedCacheDefault;
+ this.sharedCacheDefault = newValue;
+ this.firePropertyChanged(event.aspectName(), old, newValue);
+ }
+
+ public Boolean getDefaultSharedCacheDefault() {
+ return DEFAULT_SHARED_CACHE_DEFAULT;
+ }
+
+ /** ****** CacheProperties ******* */
+ /**
+ * Convinience method to update the CacheType in entitiesCache map. Returns
+ * the old value of CacheProperties
+ */
+ private CacheProperties setCacheType_(Property newProperty, String entityName) {
+ String stringValue = (newProperty == null) ? null : newProperty.getValue();
+ CacheType newValue = getEnumValueOf(stringValue, CacheType.values());
+ return this.setCacheType_(newValue, entityName);
+ }
+
+ private CacheProperties setCacheType_(CacheType newValue, String entityName) {
+ CacheProperties cache = this.cachePropertiesOf(entityName);
+ CacheProperties old = cache.clone();
+ cache.setType(newValue);
+ this.putEntitiesCache(entityName, cache);
+ return old;
+ }
+
+ /**
+ * Convinience method to update the CacheSize in entitiesCache map. Returns
+ * the old value of CacheProperties
+ */
+ private CacheProperties setCacheSize_(Property newProperty, String entityName) {
+ String stringValue = (newProperty == null) ? null : newProperty.getValue();
+ Integer newValue = getIntegerValueOf(stringValue);
+ return this.setCacheSize_(newValue, entityName);
+ }
+
+ private CacheProperties setCacheSize_(Integer newValue, String entityName) {
+ CacheProperties cache = this.cachePropertiesOf(entityName);
+ CacheProperties old = cache.clone();
+ cache.setSize(newValue);
+ this.putEntitiesCache(entityName, cache);
+ return old;
+ }
+
+ /**
+ * Convinience method to update the SharedCache in entitiesCache map.
+ * Returns the old value of CacheProperties
+ */
+ private CacheProperties setSharedCache_(Property newProperty, String entityName) {
+ String newValue = (newProperty == null) ? null : newProperty.getValue();
+ return this.setSharedCache_(newValue, entityName);
+ }
+
+ private CacheProperties setSharedCache_(String newString, String entityName) {
+ Boolean newValue = getBooleanValueOf(newString);
+ return setSharedCache_(newValue, entityName);
+ }
+
+ private CacheProperties setSharedCache_(Boolean newValue, String entityName) {
+ CacheProperties cache = this.cachePropertiesOf(entityName);
+ CacheProperties old = cache.clone();
+ cache.setShared(newValue);
+ this.putEntitiesCache(entityName, cache);
+ return old;
+ }
+
+ /**
+ * Returns the CacheProperties of the Entity with the given name.
+ */
+ private CacheProperties cachePropertiesOf(String entityName) {
+ CacheProperties entityCache = this.entitiesCache.get(entityName);
+ if (entityCache == null) {
+ entityCache = new CacheProperties(entityName);
+ }
+ return entityCache;
+ }
+
+ // ****** convenience methods *******
+ private void putEntitiesCache(String entityName, CacheProperties cache) {
+ this.addOrReplaceEntity(entityName, cache);
+ }
+
+ /**
+ * Return the entityName of the specified property name. If the file name
+ * has no extension, return null.
+ */
+ private String entityName(Property property) {
+ return entityName(property.getName());
+ }
+
+ private String entityName(String propertyName) {
+ int index = propertyName.lastIndexOf('.');
+ if (index == -1) {
+ return "";
+ }
+ return propertyName.substring(index + 1);
+ }
+
+ /** ****** entities list ******* */
+ public ListIterator<String> entities() {
+ return CollectionTools.list(this.entitiesCache.keySet()).listIterator();
+ }
+
+ public int entitiesSize() {
+ return this.entitiesCache.size();
+ }
+
+ public String addEntity(String entity) {
+ return this.addOrReplaceEntity(entity, new CacheProperties(entity));
+ }
+
+ private String addOrReplaceEntity(String entity, CacheProperties cache) {
+ if (this.entitiesCache.containsKey(entity)) {
+ this.replaceEntity_(entity, cache);
+ return null;
+ }
+ this.entitiesCache.put(entity, cache);
+ this.fireListChanged(ENTITIES_LIST_PROPERTY);
+ return entity;
+ }
+
+ private CacheProperties replaceEntity_(String entity, CacheProperties cache) {
+ CacheProperties old = this.entitiesCache.get(entity);
+ this.entitiesCache.put(entity, cache);
+ // fire change ?
+ return old;
+ }
+
+ public void removeEntity(String entity) {
+ if (!this.entitiesCache.containsKey(entity)) {
+ return;
+ }
+ this.entitiesCache.remove(entity);
+ this.fireListChanged(ENTITIES_LIST_PROPERTY);
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/DdlGenerationType.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/DdlGenerationType.java
new file mode 100644
index 0000000000..14af9050e5
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/DdlGenerationType.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+* Copyright (c) 2008 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.schema.generation;
+
+/**
+ * DdlGenerationType
+ */
+public enum DdlGenerationType {
+ none,
+ create_tables,
+ drop_and_create_tables;
+
+ // EclipseLink value string
+ static final String NONE = "none";
+ static final String CREATE_TABLES = "create-tables";
+ static final String DROP_AND_CREATE_TABLES = "drop-and-create-tables";
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/EclipseLinkSchemaGeneration.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/EclipseLinkSchemaGeneration.java
new file mode 100644
index 0000000000..316ea87c75
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/EclipseLinkSchemaGeneration.java
@@ -0,0 +1,222 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.schema.generation;
+
+import java.util.Map;
+
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.context.persistence.Property;
+import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkPersistenceUnitProperties;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.value.ListValueModel;
+
+/**
+ * EclipseLinkSchemaGeneration encapsulates EclipseLink SchemaGeneration
+ * properties.
+ */
+public class EclipseLinkSchemaGeneration
+ extends EclipseLinkPersistenceUnitProperties implements SchemaGeneration
+{
+ // ********** EclipseLink properties **********
+
+ private OutputMode outputMode;
+ private DdlGenerationType ddlGenerationType;
+ private String createFileName;
+ private String dropFileName;
+ private String applicationLocation;
+
+ // ********** constructors/initialization **********
+
+ public EclipseLinkSchemaGeneration(PersistenceUnit parent, ListValueModel<Property> propertyListAdapter) {
+ super(parent, propertyListAdapter);
+ }
+
+ /**
+ * Initializes properties with values from the persistence unit.
+ */
+ @Override
+ protected void initializeProperties() {
+ this.outputMode =
+ this.getEnumValue(ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE, OutputMode.values());
+ this.ddlGenerationType =
+ this.getEnumValue(ECLIPSELINK_DDL_GENERATION_TYPE, DdlGenerationType.values());
+ this.createFileName =
+ this.getStringValue(ECLIPSELINK_CREATE_FILE_NAME);
+ this.dropFileName =
+ this.getStringValue(ECLIPSELINK_DROP_FILE_NAME);
+ this.applicationLocation =
+ this.getStringValue(ECLIPSELINK_APPLICATION_LOCATION);
+ }
+
+ /**
+ * Adds property names key/value pairs, where: key = EclipseLink property
+ * key; value = property id
+ */
+ @Override
+ protected void addPropertyNames(Map<String, String> propertyNames) {
+ propertyNames.put(
+ ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE,
+ OUTPUT_MODE_PROPERTY);
+ propertyNames.put(
+ ECLIPSELINK_DDL_GENERATION_TYPE,
+ DDL_GENERATION_TYPE_PROPERTY);
+ propertyNames.put(
+ ECLIPSELINK_CREATE_FILE_NAME,
+ CREATE_FILE_NAME_PROPERTY);
+ propertyNames.put(
+ ECLIPSELINK_DROP_FILE_NAME,
+ DROP_FILE_NAME_PROPERTY);
+ propertyNames.put(
+ ECLIPSELINK_APPLICATION_LOCATION,
+ APPLICATION_LOCATION_PROPERTY);
+ }
+
+ // ********** behavior **********
+ public void propertyChanged(PropertyChangeEvent event) {
+ String aspectName = event.aspectName();
+
+ if (aspectName.equals(OUTPUT_MODE_PROPERTY)) {
+ this.outputModeChanged(event);
+ }
+ else if (aspectName.equals(DDL_GENERATION_TYPE_PROPERTY)) {
+ this.ddlGenerationTypeChanged(event);
+ }
+ else if (aspectName.equals(CREATE_FILE_NAME_PROPERTY)) {
+ this.createFileNameChanged(event);
+ }
+ else if (aspectName.equals(DROP_FILE_NAME_PROPERTY)) {
+ this.dropFileNameChanged(event);
+ }
+ else if (aspectName.equals(APPLICATION_LOCATION_PROPERTY)) {
+ this.applicationLocationChanged(event);
+ }
+ else {
+ throw new IllegalArgumentException("Illegal event received - property not applicable: " + aspectName);
+ }
+ return;
+ }
+
+ // ********** DdlGenerationType **********
+ public DdlGenerationType getDdlGenerationType() {
+ return this.ddlGenerationType;
+ }
+
+ public void setDdlGenerationType(DdlGenerationType newDdlGenType) {
+ DdlGenerationType old = this.ddlGenerationType;
+ this.ddlGenerationType = newDdlGenType;
+ this.firePropertyChanged(DDL_GENERATION_TYPE_PROPERTY, old, newDdlGenType);
+ this.putEnumValue(ECLIPSELINK_DDL_GENERATION_TYPE, newDdlGenType);
+ }
+
+ private void ddlGenerationTypeChanged(PropertyChangeEvent event) {
+ String stringValue = (event.newValue() == null) ? null : ((Property) event.newValue()).getValue();
+ DdlGenerationType newValue = getEnumValueOf(stringValue, DdlGenerationType.values());
+ DdlGenerationType old = this.ddlGenerationType;
+ this.ddlGenerationType = newValue;
+ this.firePropertyChanged(event.aspectName(), old, newValue);
+ }
+
+ public DdlGenerationType getDefaultDdlGenerationType() {
+ return DEFAULT_SCHEMA_GENERATION_DDL_GENERATION_TYPE;
+ }
+
+ // ********** OutputMode **********
+ public OutputMode getOutputMode() {
+ return this.outputMode;
+ }
+
+ public void setOutputMode(OutputMode newOutputMode) {
+ OutputMode old = this.outputMode;
+ this.outputMode = newOutputMode;
+ this.firePropertyChanged(OUTPUT_MODE_PROPERTY, old, newOutputMode);
+ this.putEnumValue(ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE, newOutputMode);
+ }
+
+ private void outputModeChanged(PropertyChangeEvent event) {
+ String stringValue = (event.newValue() == null) ? null : ((Property) event.newValue()).getValue();
+ OutputMode newValue = getEnumValueOf(stringValue, OutputMode.values());
+ OutputMode old = this.outputMode;
+ this.outputMode = newValue;
+ this.firePropertyChanged(event.aspectName(), old, newValue);
+ }
+
+ public OutputMode getDefaultOutputMode() {
+ return DEFAULT_SCHEMA_GENERATION_OUTPUT_MODE;
+ }
+
+ // ********** CreateFileName **********
+ public String getCreateFileName() {
+ return this.createFileName;
+ }
+
+ public void setCreateFileName(String newCreateFileName) {
+ String old = this.createFileName;
+ this.createFileName = newCreateFileName;
+ this.firePropertyChanged(CREATE_FILE_NAME_PROPERTY, old, newCreateFileName);
+ this.putStringValue(ECLIPSELINK_CREATE_FILE_NAME, newCreateFileName);
+ }
+
+ private void createFileNameChanged(PropertyChangeEvent event) {
+ String newValue = (event.newValue() == null) ? null : ((Property) event.newValue()).getValue();
+ String old = this.createFileName;
+ this.createFileName = newValue;
+ this.firePropertyChanged(event.aspectName(), old, newValue);
+ }
+
+ public String getDefaultCreateFileName() {
+ return DEFAULT_SCHEMA_GENERATION_CREATE_FILE_NAME;
+ }
+
+ // ********** dropFileName **********
+ public String getDropFileName() {
+ return this.dropFileName;
+ }
+
+ public void setDropFileName(String newDropFileName) {
+ String old = this.dropFileName;
+ this.dropFileName = newDropFileName;
+ this.firePropertyChanged(DROP_FILE_NAME_PROPERTY, old, newDropFileName);
+ this.putStringValue(ECLIPSELINK_DROP_FILE_NAME, newDropFileName);
+ }
+
+ private void dropFileNameChanged(PropertyChangeEvent event) {
+ String newValue = (event.newValue() == null) ? null : ((Property) event.newValue()).getValue();
+ String old = this.dropFileName;
+ this.dropFileName = newValue;
+ this.firePropertyChanged(event.aspectName(), old, newValue);
+ }
+
+ public String getDefaultDropFileName() {
+ return DEFAULT_SCHEMA_GENERATION_DROP_FILE_NAME;
+ }
+
+ // ********** applicationLocation **********
+ public String getApplicationLocation() {
+ return this.applicationLocation;
+ }
+
+ public void setApplicationLocation(String newApplicationLocation) {
+ String old = this.applicationLocation;
+ this.applicationLocation = newApplicationLocation;
+ this.firePropertyChanged(APPLICATION_LOCATION_PROPERTY, old, newApplicationLocation);
+ this.putStringValue(ECLIPSELINK_APPLICATION_LOCATION, newApplicationLocation);
+ }
+
+ private void applicationLocationChanged(PropertyChangeEvent event) {
+ String newValue = (event.newValue() == null) ? null : ((Property) event.newValue()).getValue();
+ String old = this.applicationLocation;
+ this.applicationLocation = newValue;
+ this.firePropertyChanged(event.aspectName(), old, newValue);
+ }
+
+ public String getDefaultApplicationLocation() {
+ return DEFAULT_SCHEMA_GENERATION_APPLICATION_LOCATION;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/OutputMode.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/OutputMode.java
new file mode 100644
index 0000000000..cdbc763ff0
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/OutputMode.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+* Copyright (c) 2008 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.schema.generation;
+
+/**
+ * OutputMode
+ */
+public enum OutputMode {
+ both,
+ sql_script,
+ database;
+
+ // EclipseLink value string
+ static final String BOTH = "both";
+ static final String DATABASE = "database";
+ static final String SQL_SCRIPT = "sql-script";
+}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/SchemaGeneration.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/SchemaGeneration.java
new file mode 100644
index 0000000000..ca99995b4c
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/schema/generation/SchemaGeneration.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+* Copyright (c) 2008 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.schema.generation;
+
+import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties;
+
+/**
+ * SchemaGeneration
+ */
+public interface SchemaGeneration extends PersistenceUnitProperties
+{
+ DdlGenerationType getDefaultDdlGenerationType();
+ DdlGenerationType getDdlGenerationType();
+ void setDdlGenerationType(DdlGenerationType ddlGenerationType);
+ static final String DDL_GENERATION_TYPE_PROPERTY = "ddlGenerationTypeProperty";
+ // EclipseLink key string
+ static final String ECLIPSELINK_DDL_GENERATION_TYPE = "eclipselink.ddl-generation";
+ static final DdlGenerationType DEFAULT_SCHEMA_GENERATION_DDL_GENERATION_TYPE = null; // No Default
+
+ OutputMode getDefaultOutputMode();
+ OutputMode getOutputMode();
+ void setOutputMode(OutputMode outputMode); // put
+ static final String OUTPUT_MODE_PROPERTY = "outputModeProperty";
+ // EclipseLink key string
+ static final String ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE = "eclipselink.ddl-generation.output-mode";
+ static final OutputMode DEFAULT_SCHEMA_GENERATION_OUTPUT_MODE = null; // No Default
+
+ String getDefaultCreateFileName();
+ String getCreateFileName();
+ void setCreateFileName(String createFileName);
+ static final String CREATE_FILE_NAME_PROPERTY = "createFileNameProperty";
+ // EclipseLink key string
+ static final String ECLIPSELINK_CREATE_FILE_NAME = "eclipselink.create-ddl-jdbc-file-name";
+ static final String DEFAULT_SCHEMA_GENERATION_CREATE_FILE_NAME = "createDDL.jdbc";
+
+ String getDefaultDropFileName();
+ String getDropFileName();
+ void setDropFileName(String dropFileName);
+ static final String DROP_FILE_NAME_PROPERTY = "dropFileNameProperty";
+ // EclipseLink key string
+ static final String ECLIPSELINK_DROP_FILE_NAME = "eclipselink.drop-ddl-jdbc-file-name";
+ static final String DEFAULT_SCHEMA_GENERATION_DROP_FILE_NAME = "dropDDL.jdbc";
+
+ String getDefaultApplicationLocation();
+ String getApplicationLocation();
+ void setApplicationLocation(String applicationLocation);
+ static final String APPLICATION_LOCATION_PROPERTY = "applicationLocationProperty";
+ // EclipseLink key string
+ static final String ECLIPSELINK_APPLICATION_LOCATION = "eclipselink.application-location";
+ static final String DEFAULT_SCHEMA_GENERATION_APPLICATION_LOCATION = null; // No Default
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.classpath b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.classpath
new file mode 100644
index 0000000000..db34e47716
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.classpath
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
+ <accessrules>
+ <accessrule kind="accessible" pattern="org/eclipse/wst/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/jst/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/**"/>
+ </accessrules>
+ </classpathentry>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.cvsignore b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.cvsignore
new file mode 100644
index 0000000000..c4ba612bad
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.cvsignore
@@ -0,0 +1,5 @@
+bin
+@dot
+temp.folder
+build.xml
+javaCompiler...args \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.project b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.project
new file mode 100644
index 0000000000..26141a5bbf
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jpt.eclipselink.core.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..8e23514bf6
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-Vendor: %providerName
+Bundle-SymbolicName: org.eclipse.jpt.eclipselink.core.tests
+Bundle-Version: 1.1.0
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.core.resources,
+ org.eclipse.core.runtime,
+ org.eclipse.jdt.core,
+ org.eclipse.jem,
+ org.eclipse.jpt.core,
+ org.eclipse.jpt.core.tests,
+ org.eclipse.jpt.utility,
+ org.eclipse.wst.common.frameworks,
+ org.eclipse.wst.common.modulecore,
+ org.eclipse.wst.common.project.facet.core,
+ org.junit,
+ org.eclipse.jpt.eclipselink.core
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: org.eclipse.jpt.utility.tests.internal
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/build.properties b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/build.properties
new file mode 100644
index 0000000000..bf0049751c
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/build.properties
@@ -0,0 +1,17 @@
+###############################################################################
+# Copyright (c) 2006, 2007 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
+###############################################################################
+javacSource = 1.5
+javacTarget = 1.5
+bin.includes = .,\
+ META-INF/,\
+ plugin.properties
+source.. = src/
+output.. = bin/
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/plugin.properties b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/plugin.properties
new file mode 100644
index 0000000000..b7c25079b4
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/plugin.properties
@@ -0,0 +1,22 @@
+###############################################################################
+# Copyright (c) 2006, 2007 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
+###############################################################################
+# ====================================================================
+# To code developer:
+# Do NOT change the properties between this line and the
+# "%%% END OF TRANSLATED PROPERTIES %%%" line.
+# Make a new property name, append to the end of the file and change
+# the code to use the new property.
+# ====================================================================
+
+# ====================================================================
+# %%% END OF TRANSLATED PROPERTIES %%%
+# ====================================================================
+
+pluginName=EclipseLink Core Tests
+providerName=Eclipse.org
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/JptEclipseLinkCoreTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/JptEclipseLinkCoreTests.java
new file mode 100644
index 0000000000..30e18b9439
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/JptEclipseLinkCoreTests.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.jpt.eclipselink.core.tests.internal.caching.JptEclipseLinkCoreCachingTests;
+import org.eclipse.jpt.eclipselink.core.tests.internal.schema.generation.JptEclipseLinkCoreSchemaGenerationTests;
+
+/**
+ * decentralize test creation code
+ */
+public class JptEclipseLinkCoreTests
+{
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JptEclipseLinkCoreTests.class.getPackage().getName());
+
+ suite.addTest(JptEclipseLinkCoreCachingTests.suite());
+ suite.addTest(JptEclipseLinkCoreSchemaGenerationTests.suite());
+
+ return suite;
+ }
+
+ private JptEclipseLinkCoreTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/PersistenceUnitTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/PersistenceUnitTestCase.java
new file mode 100644
index 0000000000..c65523d45b
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/PersistenceUnitTestCase.java
@@ -0,0 +1,272 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal;
+
+import java.util.ListIterator;
+
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.context.persistence.Property;
+import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase;
+import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkJpaProperties;
+import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkPersistenceUnitProperties;
+import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkProperties;
+import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties;
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.model.event.ListChangeEvent;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.value.ListValueModel;
+import org.eclipse.jpt.utility.model.value.PropertyValueModel;
+
+/**
+ * PersistenceUnitTestCase
+ */
+public abstract class PersistenceUnitTestCase extends ContextModelTestCase
+{
+ protected PersistenceUnit subject;
+
+ protected PropertyValueModel<PersistenceUnit> subjectHolder;
+
+ protected EclipseLinkProperties persistenceUnitProperties;
+
+ protected PropertyChangeEvent propertyChangedEvent;
+
+ protected int propertyChangedEventCount;
+
+ protected int propertiesTotal;
+
+ protected int modelPropertiesSizeOriginal;
+
+ protected int modelPropertiesSize;
+
+ protected PersistenceUnitTestCase(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.subject = (PersistenceUnit) this.persistenceUnit();
+ this.subjectHolder = new SimplePropertyValueModel<PersistenceUnit>(this.subject);
+ this.persistenceUnitProperties = new EclipseLinkJpaProperties(this.subject);
+ this.populatePu();
+ }
+
+ private ListValueModel<Property> buildPropertiesAspectAdapter(PropertyValueModel<PersistenceUnit> subjectHolder) {
+ return new ListAspectAdapter<PersistenceUnit, Property>(subjectHolder, PersistenceUnit.PROPERTIES_LIST) {
+ @Override
+ protected ListIterator<Property> listIterator_() {
+ return this.subject.properties();
+ }
+
+ @Override
+ protected int size_() {
+ return this.subject.propertiesSize();
+ }
+ };
+ }
+
+ protected String getEclipseLinkValueString(Enum value) {
+ return EclipseLinkPersistenceUnitProperties.getEclipseLinkStringValue(value);
+ }
+
+ /** ****** convenience test methods ******* */
+ protected void clearEvent() {
+ this.propertyChangedEvent = null;
+ this.propertyChangedEventCount = 0;
+ }
+
+ /**
+ * Put into persistenceUnit properties.
+ *
+ * @param key -
+ * EclipseLink Key
+ * @param value -
+ * property value
+ */
+ // TODO to rename to persistenceUnitPut
+ @SuppressWarnings("unchecked")
+ protected void putProperty(String key, Object value) {
+ if (value == null)
+ this.putNullProperty(key);
+ else if (value.getClass().isEnum())
+ this.putEnumProperty(key, (Enum) value);
+ else
+ this.putProperty_(key, value);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void putEnumProperty(String key, Enum value) {
+ this.clearEvent();
+ this.persistenceUnit().putProperty(key, this.getEclipseLinkValueString(value), false);
+ }
+
+ private void putProperty_(String key, Object value) {
+ this.clearEvent();
+ this.persistenceUnit().putProperty(key, value.toString(), false);
+ }
+
+ protected void putNullProperty(String key) {
+ this.clearEvent();
+ this.persistenceUnit().putProperty(key, null, false);
+ }
+
+ /** ****** verify methods ******* */
+ protected abstract PersistenceUnitProperties model();
+
+ /**
+ * Initializes directly the PU properties before testing. Cannot use
+ * Property Holder to initialize because it is not created yet
+ */
+ protected abstract void populatePu();
+
+ // TODO make abstract
+ protected void setProperty(String propertyName, Object newValue) throws Exception {
+ throw new IllegalStateException("Missing Implementation for setting: " + propertyName);
+ }
+
+ // TODO make abstract
+ protected void verifyPutProperty(String propertyName, Object expectedValue) throws Exception {
+ throw new IllegalStateException("Missing Implementation for verifying: " + propertyName);
+ }
+
+ protected void throwMissingDefinition(String methodName, String propertyName) throws NoSuchFieldException {
+ throw new NoSuchFieldException("Missing Definition for: " + methodName + "( " + propertyName + ")");
+ }
+
+ protected void throwUnsupportedOperationException(ListChangeEvent e) {
+ throw new UnsupportedOperationException(e.aspectName());
+ }
+
+ protected void verifyAAValue(Boolean testValue, Boolean subjectValue, PropertyValueModel<Boolean> aa, String persistenceXmlKey) {
+ assertEquals(testValue, subjectValue);
+ assertEquals(testValue, aa.value());
+ if (testValue != null) {
+ assertEquals(testValue.toString(), this.persistenceUnit().getProperty(persistenceXmlKey).getValue());
+ }
+ }
+
+ protected <T extends Enum<T>> void verifyAAValue(T testValue, T subjectValue, PropertyValueModel<? extends Enum<T>> aa, String persistenceXmlKey) {
+ assertEquals(testValue, subjectValue);
+ assertEquals(testValue, aa.value());
+ if (testValue != null) {
+ assertEquals(this.getEclipseLinkValueString(testValue), this.persistenceUnit().getProperty(persistenceXmlKey).getValue());
+ }
+ }
+
+ protected void verifyInitialState(String propertyName, String key, ListValueModel<Property> propertyListAdapter) throws Exception {
+ assertEquals("Total not updated in populatePu(): ", propertyListAdapter.size(), this.propertiesTotal);
+ this.verifyPuHasProperty(key, "Property not added to populatePu()");
+ this.verifyHasListeners(propertyListAdapter);
+ this.verifyHasListeners(this.model(), propertyName);
+
+ Property property = this.persistenceUnit().getProperty(key);
+ assertTrue("itemIsProperty() not updated: ", model().itemIsProperty(property));
+ assertEquals("propertyIdFor() not updated: ", propertyName, model().propertyIdFor(property));
+ }
+
+ /**
+ * Verify that the tested Property model is initialized with the value from
+ * the persistence unit.
+ */
+ protected void verifyModelInitialized(Object modelValue, Object expectedValue) {
+ assertEquals("Property not populatedPu() or not model.initializeProperties()", expectedValue, modelValue);
+ }
+
+ protected void verifySetProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception {
+ ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter();
+
+ // Basic
+ this.verifyInitialState(propertyName, key, propertyListAdapter);
+
+ // Replace
+ this.putProperty(key, testValue2);
+ assertEquals(this.propertiesTotal, propertyListAdapter.size());
+ this.verifyPutProperty(propertyName, testValue2);
+
+ // Replace by setting model object
+ this.clearEvent();
+ this.setProperty(propertyName, testValue1);
+ assertEquals(this.propertiesTotal, propertyListAdapter.size());
+ this.verifyPutProperty(propertyName, testValue1);
+ }
+
+ protected void verifyAddRemoveProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception {
+ ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter();
+
+ // Remove
+ this.clearEvent();
+ --this.propertiesTotal;
+ --this.modelPropertiesSize;
+ assertTrue("persistenceUnit.properties doesn't contains: " + key, this.persistenceUnit().containsProperty(key));
+ this.persistenceUnit().removeProperty(key);
+ assertFalse(this.persistenceUnit().containsProperty(key));
+ assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1);
+ assertEquals(this.propertiesTotal, propertyListAdapter.size());
+ this.verifyPutProperty(propertyName, null);
+
+ // Add original CacheTypeDefault
+ ++this.propertiesTotal;
+ ++this.modelPropertiesSize;
+ this.putProperty(key, testValue1);
+ assertEquals(this.propertiesTotal, propertyListAdapter.size());
+ this.verifyPutProperty(propertyName, testValue1);
+
+ // Replace
+ this.putProperty(key, testValue2);
+ assertEquals(this.propertiesTotal, propertyListAdapter.size());
+ this.verifyPutProperty(propertyName, testValue2);
+ }
+
+ protected void verifyPutProperty(String propertyName, Object value, Object expectedValue) {
+ this.verifyEvent(propertyName);
+ this.verifyEventValue(value, expectedValue);
+ }
+
+ protected void verifyEventValue(Object value, Object expectedValue) {
+ // verify event value
+ assertEquals(expectedValue, this.propertyChangedEvent.newValue());
+ assertEquals(expectedValue, value);
+ }
+
+ protected void verifyEvent(String propertyName) {
+ // verify event received
+ assertNotNull("No Event Fired.", this.propertyChangedEvent);
+ // verify event for the expected property
+ assertEquals("Wrong Event.", this.propertyChangedEvent.aspectName(), propertyName);
+ // verify event occurence
+ assertEquals("Multiple Event Received.", 1, this.propertyChangedEventCount);
+ }
+
+ protected void verifyHasNoListeners(ListValueModel listValueModel) throws Exception {
+ assertTrue(((AbstractModel) listValueModel).hasNoListChangeListeners(ListValueModel.LIST_VALUES));
+ }
+
+ protected void verifyHasListeners(ListValueModel listValueModel) throws Exception {
+ assertTrue(((AbstractModel) listValueModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+ }
+
+ protected void verifyHasListeners(PersistenceUnitProperties model, String propertyName) throws Exception {
+ assertTrue("Listener not added in setUp() - " + propertyName, ((AbstractModel) model).hasAnyPropertyChangeListeners(propertyName));
+ }
+
+ protected void verifyHasListeners(PropertyValueModel pvm, String propertyName) throws Exception {
+ assertTrue(((AbstractModel) pvm).hasAnyPropertyChangeListeners(propertyName));
+ }
+
+ protected void verifyPuHasProperty(String eclipseLinkPropertyName, String msg) {
+ assertNotNull(msg + " - " + eclipseLinkPropertyName, this.persistenceUnit().getProperty(eclipseLinkPropertyName));
+ }
+
+ protected void verifyPuHasNotProperty(String eclipseLinkPropertyName, String msg) {
+ assertNull(msg + " - " + eclipseLinkPropertyName, this.persistenceUnit().getProperty(eclipseLinkPropertyName));
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java
new file mode 100644
index 0000000000..bc8ebc7f2b
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingAdapterTests.java
@@ -0,0 +1,454 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.tests.internal.caching;
+
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.context.persistence.Property;
+import org.eclipse.jpt.core.internal.context.persistence.GenericProperty;
+import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkJpaProperties;
+import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties;
+import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitPropertyListListener;
+import org.eclipse.jpt.eclipselink.core.internal.context.caching.CacheProperties;
+import org.eclipse.jpt.eclipselink.core.internal.context.caching.CacheType;
+import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching;
+import org.eclipse.jpt.eclipselink.core.internal.context.caching.EclipseLinkCaching;
+import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase;
+import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter;
+import org.eclipse.jpt.utility.model.event.ListChangeEvent;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.listener.ListChangeListener;
+import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.model.value.ListValueModel;
+
+/**
+ * Tests the update of model objects by the Caching adapter when the
+ * PersistenceUnit changes.
+ */
+public class CachingAdapterTests extends PersistenceUnitTestCase
+{
+ private Caching caching;
+ private ListChangeEvent entitiesEvent;
+
+ public static final String ENTITY_TEST = "Employee";
+ public static final String ENTITY_TEST_2 = "Address";
+
+ public static final String CACHE_TYPE_DEFAULT_KEY = Caching.ECLIPSELINK_CACHE_TYPE_DEFAULT;
+ public static final CacheType CACHE_TYPE_DEFAULT_TEST_VALUE = CacheType.soft_weak;
+ public static final CacheType CACHE_TYPE_DEFAULT_TEST_VALUE_2 = CacheType.full;
+
+ public static final String CACHE_SIZE_DEFAULT_KEY = Caching.ECLIPSELINK_CACHE_SIZE_DEFAULT;
+ public static final Integer CACHE_SIZE_DEFAULT_TEST_VALUE = 12345;
+ public static final Integer CACHE_SIZE_DEFAULT_TEST_VALUE_2 = 67890;
+
+ public static final String SHARED_CACHE_DEFAULT_KEY = Caching.ECLIPSELINK_CACHE_SHARED_DEFAULT;
+ public static final Boolean SHARED_CACHE_DEFAULT_TEST_VALUE = false;
+ public static final Boolean SHARED_CACHE_DEFAULT_TEST_VALUE_2 = true;
+
+ public static final String CACHE_TYPE_KEY = Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_TEST;
+ public static final CacheType CACHE_TYPE_TEST_VALUE = CacheType.soft_weak;
+ public static final CacheType CACHE_TYPE_TEST_VALUE_2 = CacheType.full;
+
+ public static final String SHARED_CACHE_KEY = Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_TEST;
+ public static final Boolean SHARED_CACHE_TEST_VALUE = false;
+ public static final Boolean SHARED_CACHE_TEST_VALUE_2 = true;
+
+ public static final String CACHE_SIZE_KEY = Caching.ECLIPSELINK_CACHE_SIZE + ENTITY_TEST;
+ public static final Integer CACHE_SIZE_TEST_VALUE = 12345;
+ public static final Integer CACHE_SIZE_TEST_VALUE_2 = 67890;
+
+ public CachingAdapterTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.caching = this.persistenceUnitProperties.getCaching();
+ PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener();
+
+ 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);
+
+ ListChangeListener entitiesChangeListener = this.buildEntitiesChangeListener();
+ this.caching.addListChangeListener(Caching.ENTITIES_LIST_PROPERTY, entitiesChangeListener);
+ this.clearEvent();
+ }
+
+ /**
+ * Initializes directly the PU properties before testing. Cannot use
+ * Property Holder to initialize because it is not created yet
+ */
+ @Override
+ protected void populatePu() {
+ this.modelPropertiesSizeOriginal = 6;
+ this.propertiesTotal = this.modelPropertiesSizeOriginal + 4; // 4 misc properties
+ this.modelPropertiesSize = this.modelPropertiesSizeOriginal;
+
+ this.persistenceUnit().putProperty("misc.property.1", "value.1", false);
+ this.persistenceUnit().putProperty(CACHE_TYPE_DEFAULT_KEY, this.getEclipseLinkValueString(CACHE_TYPE_DEFAULT_TEST_VALUE), false);
+ this.persistenceUnit().putProperty("misc.property.2", "value.2", false);
+ this.persistenceUnit().putProperty(CACHE_SIZE_DEFAULT_KEY, CACHE_SIZE_DEFAULT_TEST_VALUE.toString(), false);
+ this.persistenceUnit().putProperty(SHARED_CACHE_DEFAULT_KEY, SHARED_CACHE_DEFAULT_TEST_VALUE.toString(), false);
+ this.persistenceUnit().putProperty("misc.property.3", "value.3", false);
+ this.persistenceUnit().putProperty("misc.property.4", "value.4", false);
+ this.persistenceUnit().putProperty(CACHE_SIZE_KEY, CACHE_SIZE_TEST_VALUE.toString(), false);
+ this.persistenceUnit().putProperty(CACHE_TYPE_KEY, this.getEclipseLinkValueString(CACHE_TYPE_TEST_VALUE), false);
+ this.persistenceUnit().putProperty(SHARED_CACHE_KEY, SHARED_CACHE_TEST_VALUE.toString(), false);
+ return;
+ }
+
+ // ********** Listeners **********
+ private ListChangeListener buildEntitiesChangeListener() {
+ return new ListChangeListener() {
+ public void itemsAdded(ListChangeEvent e) {
+ CachingAdapterTests.this.throwUnsupportedOperationException(e);
+ }
+
+ public void itemsRemoved(ListChangeEvent e) {
+ CachingAdapterTests.this.throwUnsupportedOperationException(e);
+ }
+
+ public void itemsReplaced(ListChangeEvent e) {
+ CachingAdapterTests.this.throwUnsupportedOperationException(e);
+ }
+
+ public void itemsMoved(ListChangeEvent e) {
+ CachingAdapterTests.this.throwUnsupportedOperationException(e);
+ }
+
+ public void listCleared(ListChangeEvent e) {
+ CachingAdapterTests.this.throwUnsupportedOperationException(e);
+ }
+
+ public void listChanged(ListChangeEvent e) {
+ CachingAdapterTests.this.entityChanged(e);
+ }
+ };
+ }
+
+ private PropertyChangeListener buildPropertyChangeListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent event) {
+ CachingAdapterTests.this.propertyChangedEvent = event;
+ CachingAdapterTests.this.propertyChangedEventCount++;
+ }
+
+ @Override
+ public String toString() {
+ return "Caching listener";
+ }
+ };
+ }
+
+ @Override
+ protected void clearEvent() {
+ super.clearEvent();
+ this.entitiesEvent = null;
+ }
+
+ void entityChanged(ListChangeEvent e) {
+ this.entitiesEvent = e;
+ }
+
+ // ********** entities list **********
+ public void testEntitiesList() throws Exception {
+ // add
+ this.clearEvent();
+ this.caching.addEntity(ENTITY_TEST_2);
+
+ // verify event received
+ assertNotNull("No Event Fired.", this.entitiesEvent);
+ // verify event for the expected property
+ assertEquals("Wrong Event.", this.entitiesEvent.aspectName(), Caching.ENTITIES_LIST_PROPERTY);
+
+ // try to add it again
+ this.clearEvent();
+ this.caching.addEntity(ENTITY_TEST_2);
+ // verify event received
+ assertNull("Event was Fired.", this.entitiesEvent);
+
+ // remove
+ this.clearEvent();
+ this.caching.removeEntity(ENTITY_TEST_2);
+ // verify event received
+ assertNotNull("No Event Fired.", this.entitiesEvent);
+ // verify event for the expected property
+ assertEquals("Wrong Event.", this.entitiesEvent.aspectName(), Caching.ENTITIES_LIST_PROPERTY);
+ }
+
+ // ********** Listeners tests **********
+ public void testHasListeners() throws Exception {
+ // new
+ ListAspectAdapter<PersistenceUnit, Property> propertiesAdapter =
+ (ListAspectAdapter<PersistenceUnit, Property>) ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertiesAdapter();
+ GenericProperty ctdProperty = (GenericProperty) this.persistenceUnit().getProperty(CACHE_TYPE_DEFAULT_KEY);
+ ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter();
+
+ assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+ assertTrue(ctdProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY));
+ this.verifyHasListeners(this.caching, Caching.CACHE_TYPE_DEFAULT_PROPERTY);
+ this.verifyHasListeners(propertyListAdapter);
+
+ EclipseLinkCaching elCaching = (EclipseLinkCaching) this.caching;
+ PersistenceUnitPropertyListListener propertyListListener = elCaching.propertyListListener();
+ propertyListAdapter.removeListChangeListener(ListValueModel.LIST_VALUES, propertyListListener);
+ assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); // other properties are still listening
+ this.verifyHasListeners(this.caching, Caching.CACHE_TYPE_DEFAULT_PROPERTY);
+ }
+
+ // ********** CacheTypeDefault **********
+ /**
+ * Tests the update of CacheTypeDefault property by the Caching adapter when
+ * the PU or the model changes.
+ */
+ public void testSetCacheTypeDefault() throws Exception {
+ this.verifyModelInitialized(
+ this.caching.getCacheTypeDefault(),
+ CACHE_TYPE_DEFAULT_TEST_VALUE);
+ this.verifySetProperty(
+ Caching.CACHE_TYPE_DEFAULT_PROPERTY,
+ CACHE_TYPE_DEFAULT_KEY,
+ CACHE_TYPE_DEFAULT_TEST_VALUE,
+ CACHE_TYPE_DEFAULT_TEST_VALUE_2);
+ }
+
+ public void testAddRemoveCacheTypeDefault() throws Exception {
+ this.verifyAddRemoveProperty(
+ Caching.CACHE_TYPE_DEFAULT_PROPERTY,
+ CACHE_TYPE_DEFAULT_KEY,
+ CACHE_TYPE_DEFAULT_TEST_VALUE,
+ CACHE_TYPE_DEFAULT_TEST_VALUE_2);
+ }
+
+ // ********** CacheSizeDefault **********
+ /**
+ * Tests the update of CacheSizeDefault property by the Caching adapter when
+ * the PU or the model changes.
+ */
+ public void testSetCacheSizeDefault() throws Exception {
+ this.verifyModelInitialized(
+ this.caching.getCacheSizeDefault(),
+ CACHE_SIZE_DEFAULT_TEST_VALUE);
+ this.verifySetProperty(
+ Caching.CACHE_SIZE_DEFAULT_PROPERTY,
+ CACHE_SIZE_DEFAULT_KEY,
+ CACHE_SIZE_DEFAULT_TEST_VALUE,
+ CACHE_SIZE_DEFAULT_TEST_VALUE_2);
+ }
+
+ public void testAddRemoveCacheSizeDefault() throws Exception {
+ this.verifyAddRemoveProperty(
+ Caching.CACHE_SIZE_DEFAULT_PROPERTY,
+ CACHE_SIZE_DEFAULT_KEY,
+ CACHE_SIZE_DEFAULT_TEST_VALUE,
+ CACHE_SIZE_DEFAULT_TEST_VALUE_2);
+ }
+
+ // ********** SharedCacheDefault **********
+ public void testSetSharedCacheDefault() throws Exception {
+ this.verifyModelInitialized(
+ this.caching.getSharedCacheDefault(),
+ SHARED_CACHE_DEFAULT_TEST_VALUE);
+ this.verifySetProperty(Caching.SHARED_CACHE_DEFAULT_PROPERTY,
+ SHARED_CACHE_DEFAULT_KEY,
+ SHARED_CACHE_DEFAULT_TEST_VALUE,
+ SHARED_CACHE_DEFAULT_TEST_VALUE_2);
+ }
+
+ public void testAddRemoveSharedCacheDefault() throws Exception {
+ this.verifyAddRemoveProperty(
+ Caching.SHARED_CACHE_DEFAULT_PROPERTY,
+ SHARED_CACHE_DEFAULT_KEY,
+ SHARED_CACHE_DEFAULT_TEST_VALUE,
+ SHARED_CACHE_DEFAULT_TEST_VALUE_2);
+ }
+
+ // ********** CacheType **********
+ /**
+ * Tests the update of CacheType property by the Caching adapter when the PU
+ * or the model changes.
+ */
+ public void testSetCacheType() throws Exception {
+ this.verifyModelInitialized(
+ this.caching.getCacheType(ENTITY_TEST),
+ CACHE_TYPE_TEST_VALUE);
+ this.verifySetCachingProperty(
+ Caching.CACHE_TYPE_PROPERTY,
+ CACHE_TYPE_KEY,
+ CACHE_TYPE_TEST_VALUE,
+ CACHE_TYPE_TEST_VALUE_2);
+ }
+
+ public void testAddRemoveCacheType() throws Exception {
+ this.verifyAddRemoveCachingProperty(
+ Caching.CACHE_TYPE_PROPERTY,
+ CACHE_TYPE_KEY,
+ CACHE_TYPE_TEST_VALUE,
+ CACHE_TYPE_TEST_VALUE_2);
+ }
+
+ // ********** CacheSize **********
+ /**
+ * Tests the update of CacheSize property by the Caching adapter when the PU
+ * or the model changes.
+ */
+ public void testSetCacheSize() throws Exception {
+ this.verifyModelInitialized(
+ this.caching.getCacheSize(ENTITY_TEST),
+ CACHE_SIZE_TEST_VALUE);
+ this.verifySetCachingProperty(
+ Caching.CACHE_SIZE_PROPERTY,
+ CACHE_SIZE_KEY,
+ CACHE_SIZE_TEST_VALUE,
+ CACHE_SIZE_TEST_VALUE_2);
+ }
+
+ public void testAddRemoveCacheSize() throws Exception {
+ this.verifyAddRemoveCachingProperty(
+ Caching.CACHE_SIZE_PROPERTY,
+ CACHE_SIZE_KEY,
+ CACHE_SIZE_TEST_VALUE,
+ CACHE_SIZE_TEST_VALUE_2);
+ }
+
+ // ********** SharedCache **********
+ /**
+ * Tests the update of SharedCache property by the Caching adapter when the
+ * PU or the model changes.
+ */
+ public void testSetSharedCache() throws Exception {
+ this.verifyModelInitialized(
+ this.caching.getSharedCache(ENTITY_TEST),
+ SHARED_CACHE_TEST_VALUE);
+ this.verifySetCachingProperty(
+ Caching.SHARED_CACHE_PROPERTY,
+ SHARED_CACHE_KEY,
+ SHARED_CACHE_TEST_VALUE,
+ SHARED_CACHE_TEST_VALUE_2);
+ }
+
+ public void testAddRemoveSharedCache() throws Exception {
+ this.verifyAddRemoveCachingProperty(
+ Caching.SHARED_CACHE_PROPERTY,
+ SHARED_CACHE_KEY,
+ SHARED_CACHE_TEST_VALUE,
+ SHARED_CACHE_TEST_VALUE_2);
+ }
+
+ // ****** convenience methods *******
+ protected PersistenceUnitProperties model() {
+ return this.caching;
+ }
+
+ protected void verifySetCachingProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception {
+ ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter();
+ // Basic
+ this.verifyInitialState(propertyName, key, propertyListAdapter);
+
+ // Replace
+ this.putProperty(key, testValue2);
+ assertEquals(this.propertiesTotal, propertyListAdapter.size());
+ this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue2);
+
+ // Replace by setting model object
+ this.clearEvent();
+ this.setCachingProperty(propertyName, ENTITY_TEST, testValue1);
+ assertEquals(this.propertiesTotal, propertyListAdapter.size());
+ this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue1);
+ }
+
+ protected void verifyAddRemoveCachingProperty(String propertyName, String key, Object testValue1, Object testValue2) throws Exception {
+ ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter();
+ // Remove
+ this.clearEvent();
+ --this.propertiesTotal;
+ --this.modelPropertiesSize;
+ this.persistenceUnit().removeProperty(key);
+ assertFalse(this.persistenceUnit().containsProperty(key));
+ assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1);
+ this.verifyPutCachingProperty(propertyName, ENTITY_TEST, null);
+ assertEquals(this.propertiesTotal, propertyListAdapter.size());
+
+ // Add original Property
+ ++this.propertiesTotal;
+ ++this.modelPropertiesSize;
+ this.putProperty(key, testValue1);
+ this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue1);
+ assertEquals(this.propertiesTotal, propertyListAdapter.size());
+
+ // Replace
+ this.putProperty(key, testValue2);
+ this.verifyPutCachingProperty(propertyName, ENTITY_TEST, testValue2);
+ }
+
+ protected void verifyPutCachingProperty(String propertyName, String entityName, Object expectedValue) throws Exception {
+ this.verifyEvent(propertyName);
+ this.verifyCachingEvent(propertyName, entityName, expectedValue);
+ }
+
+ protected void verifyCachingEvent(String propertyName, String entityName, Object expectedValue) throws Exception {
+ // verify event value
+ CacheProperties cache = (CacheProperties) this.propertyChangedEvent.newValue();
+ if (propertyName.equals(Caching.CACHE_TYPE_PROPERTY)) {
+ assertEquals(expectedValue, cache.getType());
+ assertEquals(expectedValue, this.caching.getCacheType(entityName));
+ }
+ else if (propertyName.equals(Caching.CACHE_SIZE_PROPERTY)) {
+ assertEquals(expectedValue, cache.getSize());
+ assertEquals(expectedValue, this.caching.getCacheSize(entityName));
+ }
+ else if (propertyName.equals(Caching.SHARED_CACHE_PROPERTY)) {
+ assertEquals(expectedValue, cache.isShared());
+ assertEquals(expectedValue, this.caching.getSharedCache(entityName));
+ }
+ else {
+ this.throwMissingDefinition("verifyCachingEvent", propertyName);
+ }
+ }
+
+ @Override
+ protected void setProperty(String propertyName, Object newValue) throws Exception {
+ if (propertyName.equals(Caching.CACHE_TYPE_DEFAULT_PROPERTY))
+ this.caching.setCacheTypeDefault((CacheType) newValue);
+ else if (propertyName.equals(Caching.CACHE_SIZE_DEFAULT_PROPERTY))
+ this.caching.setCacheSizeDefault((Integer) newValue);
+ else if (propertyName.equals(Caching.SHARED_CACHE_DEFAULT_PROPERTY))
+ this.caching.setSharedCacheDefault((Boolean) newValue);
+ else
+ this.throwMissingDefinition("setProperty", propertyName);
+ }
+
+ 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);
+ else
+ this.throwMissingDefinition("setCachingProperty", propertyName);
+ }
+
+ @Override
+ protected void verifyPutProperty(String propertyName, Object expectedValue) throws NoSuchFieldException {
+ if (propertyName.equals(Caching.CACHE_TYPE_DEFAULT_PROPERTY))
+ this.verifyPutProperty(propertyName, this.caching.getCacheTypeDefault(), expectedValue);
+ else if (propertyName.equals(Caching.CACHE_SIZE_DEFAULT_PROPERTY))
+ this.verifyPutProperty(propertyName, this.caching.getCacheSizeDefault(), expectedValue);
+ else if (propertyName.equals(Caching.SHARED_CACHE_DEFAULT_PROPERTY))
+ this.verifyPutProperty(propertyName, this.caching.getSharedCacheDefault(), expectedValue);
+ else
+ this.throwMissingDefinition("verifyPutProperty", propertyName);
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingValueModelTests.java
new file mode 100644
index 0000000000..dbde642cdd
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/CachingValueModelTests.java
@@ -0,0 +1,391 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal.caching;
+
+import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties;
+import org.eclipse.jpt.eclipselink.core.internal.context.caching.CacheType;
+import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching;
+import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase;
+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;
+import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
+
+/**
+ * CachingValueModelTests
+ */
+public class CachingValueModelTests extends PersistenceUnitTestCase
+{
+ private Caching caching;
+ private PropertyValueModel<Caching> cachingHolder;
+
+ private WritablePropertyValueModel<CacheType> cacheTypeHolder;
+ private PropertyChangeListener cacheTypeListener;
+ private PropertyChangeEvent cacheTypeEvent;
+
+ private WritablePropertyValueModel<Boolean> sharedCacheHolder;
+ private PropertyChangeListener sharedCacheListener;
+ private PropertyChangeEvent sharedCacheEvent;
+
+ private WritablePropertyValueModel<CacheType> cacheTypeDefaultHolder;
+ private PropertyChangeListener cacheTypeDefaultListener;
+ private PropertyChangeEvent cacheTypeDefaultEvent;
+
+ private WritablePropertyValueModel<Boolean> sharedCacheDefaultHolder;
+ private PropertyChangeListener sharedCacheDefaultListener;
+ private PropertyChangeEvent sharedCacheDefaultEvent;
+
+ public static final String ENTITY_NAME_TEST_VALUE = "Employee";
+ public static final CacheType CACHE_TYPE_TEST_VALUE = CacheType.hard_weak;
+ public static final Boolean SHARED_CACHE_TEST_VALUE = Boolean.FALSE;
+ public static final CacheType CACHE_TYPE_DEFAULT_TEST_VALUE = CacheType.weak;
+ public static final Boolean SHARED_CACHE_DEFAULT_TEST_VALUE = Boolean.FALSE;
+
+ public CachingValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.caching = this.persistenceUnitProperties.getCaching(); // Subject
+ this.cachingHolder = new SimplePropertyValueModel<Caching>(this.caching);
+
+ this.cacheTypeHolder = this.buildCacheTypeAA(this.cachingHolder);
+ this.cacheTypeListener = this.buildCacheTypeChangeListener();
+ this.cacheTypeHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.cacheTypeListener);
+ this.cacheTypeEvent = null;
+
+ this.sharedCacheHolder = this.buildSharedCacheAA(this.cachingHolder);
+ this.sharedCacheListener = this.buildSharedCacheChangeListener();
+ this.sharedCacheHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.sharedCacheListener);
+ this.sharedCacheEvent = null;
+
+ this.cacheTypeDefaultHolder = this.buildCacheTypeDefaultAA(this.cachingHolder);
+ this.cacheTypeDefaultListener = this.buildCacheTypeDefaultChangeListener();
+ this.cacheTypeDefaultHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.cacheTypeDefaultListener);
+ this.cacheTypeDefaultEvent = null;
+
+ this.sharedCacheDefaultHolder = this.buildSharedCacheDefaultAA(this.cachingHolder);
+ this.sharedCacheDefaultListener = this.buildSharedCacheDefaultChangeListener();
+ this.sharedCacheDefaultHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.sharedCacheDefaultListener);
+ this.sharedCacheDefaultEvent = null;
+ }
+
+ public void testHasListeners() {
+ AbstractModel subjectCaching = (AbstractModel) this.caching; // Subject
+ PropertyAspectAdapter<Caching, CacheType> cacheTypeAA =
+ (PropertyAspectAdapter<Caching, CacheType>) this.cacheTypeHolder;
+ assertTrue(cacheTypeAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(subjectCaching.hasAnyPropertyChangeListeners(Caching.CACHE_TYPE_PROPERTY));
+
+ cacheTypeAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.cacheTypeListener);
+ assertFalse(subjectCaching.hasAnyPropertyChangeListeners(Caching.CACHE_TYPE_PROPERTY));
+ assertFalse(cacheTypeAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ PropertyAspectAdapter<Caching, Boolean> sharedCacheAA =
+ (PropertyAspectAdapter<Caching, Boolean>) this.sharedCacheHolder;
+ assertTrue(sharedCacheAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(subjectCaching.hasAnyPropertyChangeListeners(Caching.SHARED_CACHE_PROPERTY));
+
+ sharedCacheAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.sharedCacheListener);
+ assertFalse(subjectCaching.hasAnyPropertyChangeListeners(Caching.SHARED_CACHE_PROPERTY));
+ assertFalse(sharedCacheAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ PropertyAspectAdapter<Caching, CacheType> cacheTypeDefaultAA =
+ (PropertyAspectAdapter<Caching, CacheType>) this.cacheTypeDefaultHolder;
+ assertTrue(cacheTypeDefaultAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(subjectCaching.hasAnyPropertyChangeListeners(Caching.CACHE_TYPE_DEFAULT_PROPERTY));
+
+ cacheTypeDefaultAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.cacheTypeDefaultListener);
+ assertFalse(subjectCaching.hasAnyPropertyChangeListeners(Caching.CACHE_TYPE_DEFAULT_PROPERTY));
+ assertFalse(cacheTypeDefaultAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ PropertyAspectAdapter<Caching, Boolean> sharedCacheDefaultAA =
+ (PropertyAspectAdapter<Caching, Boolean>) this.sharedCacheDefaultHolder;
+ assertTrue(sharedCacheDefaultAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ assertTrue(subjectCaching.hasAnyPropertyChangeListeners(Caching.SHARED_CACHE_DEFAULT_PROPERTY));
+
+ sharedCacheDefaultAA.removePropertyChangeListener(PropertyValueModel.VALUE, this.sharedCacheDefaultListener);
+ assertFalse(subjectCaching.hasAnyPropertyChangeListeners(Caching.SHARED_CACHE_DEFAULT_PROPERTY));
+ assertFalse(sharedCacheDefaultAA.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ /**
+ * Initializes directly the PU properties before testing. Cannot use
+ * Property Holder to initialize because it is not created yet
+ */
+ protected void populatePu() {
+ this.persistenceUnit().putProperty(
+ Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_NAME_TEST_VALUE,
+ this.getEclipseLinkValueString(CACHE_TYPE_TEST_VALUE),
+ false);
+ this.persistenceUnit().putProperty(
+ Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_NAME_TEST_VALUE,
+ SHARED_CACHE_TEST_VALUE.toString(),
+ false);
+ this.persistenceUnit().putProperty(
+ Caching.ECLIPSELINK_CACHE_TYPE_DEFAULT,
+ this.getEclipseLinkValueString(CACHE_TYPE_DEFAULT_TEST_VALUE),
+ false);
+ this.persistenceUnit().putProperty(
+ Caching.ECLIPSELINK_CACHE_SHARED_DEFAULT,
+ SHARED_CACHE_DEFAULT_TEST_VALUE.toString(),
+ false);
+ return;
+ }
+
+ protected PersistenceUnitProperties model() {
+ return this.caching;
+ }
+
+ /** ****** CacheType ******* */
+ private WritablePropertyValueModel<CacheType> buildCacheTypeAA(PropertyValueModel<Caching> subjectHolder) {
+ return new PropertyAspectAdapter<Caching, CacheType>(subjectHolder, Caching.CACHE_TYPE_PROPERTY) {
+ @Override
+ protected CacheType buildValue_() {
+ return this.subject.getCacheType(ENTITY_NAME_TEST_VALUE);
+ }
+
+ @Override
+ protected void setValue_(CacheType enumValue) {
+ this.subject.setCacheType(enumValue, ENTITY_NAME_TEST_VALUE);
+ }
+ };
+ }
+
+ private PropertyChangeListener buildCacheTypeChangeListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ CachingValueModelTests.this.cacheTypeEvent = e;
+ }
+ };
+ }
+
+ /** ****** SharedCache ******* */
+ private WritablePropertyValueModel<Boolean> buildSharedCacheAA(PropertyValueModel<Caching> subjectHolder) {
+ return new PropertyAspectAdapter<Caching, Boolean>(subjectHolder, Caching.SHARED_CACHE_PROPERTY) {
+ @Override
+ protected Boolean buildValue_() {
+ return this.subject.getSharedCache(ENTITY_NAME_TEST_VALUE);
+ }
+
+ @Override
+ protected void setValue_(Boolean enumValue) {
+ this.subject.setSharedCache(enumValue, ENTITY_NAME_TEST_VALUE);
+ }
+ };
+ }
+
+ private PropertyChangeListener buildSharedCacheChangeListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ CachingValueModelTests.this.sharedCacheEvent = e;
+ }
+ };
+ }
+
+ /** ****** CacheTypeDefault ******* */
+ private WritablePropertyValueModel<CacheType> buildCacheTypeDefaultAA(PropertyValueModel<Caching> subjectHolder) {
+ return new PropertyAspectAdapter<Caching, CacheType>(subjectHolder, Caching.CACHE_TYPE_DEFAULT_PROPERTY) {
+ @Override
+ protected CacheType buildValue_() {
+ return this.subject.getCacheTypeDefault();
+ }
+
+ @Override
+ protected void setValue_(CacheType enumValue) {
+ this.subject.setCacheTypeDefault(enumValue);
+ }
+ };
+ }
+
+ private PropertyChangeListener buildCacheTypeDefaultChangeListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ CachingValueModelTests.this.cacheTypeDefaultEvent = e;
+ }
+ };
+ }
+
+ /** ****** SharedCacheDefault ******* */
+ private WritablePropertyValueModel<Boolean> buildSharedCacheDefaultAA(PropertyValueModel<Caching> subjectHolder) {
+ return new PropertyAspectAdapter<Caching, Boolean>(subjectHolder, Caching.SHARED_CACHE_DEFAULT_PROPERTY) {
+ @Override
+ protected Boolean buildValue_() {
+ return this.subject.getSharedCacheDefault();
+ }
+
+ @Override
+ protected void setValue_(Boolean enumValue) {
+ this.subject.setSharedCacheDefault(enumValue);
+ }
+ };
+ }
+
+ private PropertyChangeListener buildSharedCacheDefaultChangeListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ CachingValueModelTests.this.sharedCacheDefaultEvent = e;
+ }
+ };
+ }
+
+ /** ****** Tests ******* */
+ public void testValue() {
+ /** ****** CacheType ******* */
+ this.verifyCacheTypeAAValue(CACHE_TYPE_TEST_VALUE);
+ assertEquals(Caching.DEFAULT_CACHE_TYPE, this.caching.getDefaultCacheType());
+ /** ****** SharedCache ******* */
+ this.verifySharedCacheAAValue(SHARED_CACHE_TEST_VALUE);
+ assertEquals(Caching.DEFAULT_SHARED_CACHE, this.caching.getDefaultSharedCache());
+ /** ****** CacheTypeDefault ******* */
+ this.verifyCacheTypeDefaultAAValue(CACHE_TYPE_DEFAULT_TEST_VALUE);
+ assertEquals(Caching.DEFAULT_CACHE_TYPE_DEFAULT, this.caching.getDefaultCacheTypeDefault());
+ /** ****** SharedCacheDefault ******* */
+ this.verifySharedCacheDefaultAAValue(SHARED_CACHE_DEFAULT_TEST_VALUE);
+ assertEquals(Caching.DEFAULT_SHARED_CACHE_DEFAULT, this.caching.getDefaultSharedCacheDefault());
+ }
+
+ public void testSetValue() throws Exception {
+ /** ****** CacheType ******* */
+ this.cacheTypeEvent = null;
+ this.verifyHasListeners(this.cacheTypeHolder, PropertyValueModel.VALUE);
+ CacheType newCacheType = CacheType.full;
+ // Modify the property holder
+ this.cacheTypeHolder.setValue(newCacheType);
+ this.verifyCacheTypeAAValue(newCacheType);
+ assertNotNull(this.cacheTypeEvent);
+ /** ****** SharedCache ******* */
+ this.sharedCacheEvent = null;
+ this.verifyHasListeners(this.sharedCacheHolder, PropertyValueModel.VALUE);
+ Boolean newSharedCache = !SHARED_CACHE_TEST_VALUE;
+ // Modify the property holder
+ this.sharedCacheHolder.setValue(newSharedCache);
+ this.verifySharedCacheAAValue(newSharedCache);
+ assertNotNull(this.sharedCacheEvent);
+ /** ****** CacheTypeDefault ******* */
+ this.cacheTypeDefaultEvent = null;
+ this.verifyHasListeners(this.cacheTypeDefaultHolder, PropertyValueModel.VALUE);
+ CacheType newCacheTypeDefault = CacheType.none;
+ // Modify the property holder
+ this.cacheTypeDefaultHolder.setValue(newCacheTypeDefault);
+ this.verifyCacheTypeDefaultAAValue(newCacheTypeDefault);
+ assertNotNull(this.cacheTypeDefaultEvent);
+ /** ****** SharedCacheDefault ******* */
+ this.sharedCacheDefaultEvent = null;
+ this.verifyHasListeners(this.sharedCacheDefaultHolder, PropertyValueModel.VALUE);
+ Boolean newSharedCacheDefault = !SHARED_CACHE_DEFAULT_TEST_VALUE;
+ // Modify the property holder
+ this.sharedCacheDefaultHolder.setValue(newSharedCacheDefault);
+ this.verifySharedCacheDefaultAAValue(newSharedCacheDefault);
+ assertNotNull(this.sharedCacheDefaultEvent);
+ }
+
+ public void testSetNullValue() {
+ String notDeleted = "Property not deleted";
+ /** ****** CacheType ******* */
+ this.cacheTypeEvent = null;
+ // Setting the property holder
+ this.cacheTypeHolder.setValue(null);
+ // testing Holder
+ this.verifyCacheTypeAAValue(null);
+ assertNotNull(this.cacheTypeEvent);
+ // testing PU properties
+ this.verifyPuHasNotProperty(Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_NAME_TEST_VALUE, notDeleted);
+ /** ****** SharedCache ******* */
+ this.sharedCacheEvent = null;
+ // Setting the property holder
+ this.sharedCacheHolder.setValue(null);
+ // testing Holder
+ this.verifySharedCacheAAValue(null);
+ assertNotNull(this.sharedCacheEvent);
+ // testing PU properties
+ this.verifyPuHasNotProperty(Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_NAME_TEST_VALUE, notDeleted);
+ /** ****** CacheTypeDefault ******* */
+ this.cacheTypeDefaultEvent = null;
+ // Setting the property holder
+ this.cacheTypeDefaultHolder.setValue(null);
+ // testing Holder
+ this.verifyCacheTypeDefaultAAValue(null);
+ assertNotNull(this.cacheTypeDefaultEvent);
+ // testing PU properties
+ this.verifyPuHasNotProperty(Caching.ECLIPSELINK_CACHE_TYPE_DEFAULT, notDeleted);
+ /** ****** SharedCacheDefault ******* */
+ this.sharedCacheDefaultEvent = null;
+ // Setting the property holder
+ this.sharedCacheDefaultHolder.setValue(null);
+ // testing Holder
+ this.verifySharedCacheDefaultAAValue(null);
+ assertNotNull(this.sharedCacheDefaultEvent);
+ // testing PU properties
+ this.verifyPuHasNotProperty(Caching.ECLIPSELINK_CACHE_SHARED_DEFAULT, notDeleted);
+ }
+
+ /** ****** convenience methods ******* */
+ /**
+ * Performs three value tests:<br>
+ * 1. subject value<br>
+ * 2. aspect adapter value<br>
+ * 3. persistenceUnit property value<br>
+ */
+ protected void verifyCacheTypeAAValue(CacheType testValue) {
+ this.verifyAAValue(
+ testValue,
+ this.caching.getCacheType(ENTITY_NAME_TEST_VALUE),
+ this.cacheTypeHolder,
+ Caching.ECLIPSELINK_CACHE_TYPE + ENTITY_NAME_TEST_VALUE);
+ }
+
+ /**
+ * Performs three value tests:<br>
+ * 1. subject value<br>
+ * 2. aspect adapter value<br>
+ * 3. persistenceUnit property value<br>
+ */
+ protected void verifySharedCacheAAValue(Boolean testValue) {
+ this.verifyAAValue(
+ testValue,
+ this.caching.getSharedCache(ENTITY_NAME_TEST_VALUE),
+ this.sharedCacheHolder,
+ Caching.ECLIPSELINK_SHARED_CACHE + ENTITY_NAME_TEST_VALUE);
+ }
+
+ /**
+ * Performs three value tests:<br>
+ * 1. subject value<br>
+ * 2. aspect adapter value<br>
+ * 3. persistenceUnit property value<br>
+ */
+ protected void verifyCacheTypeDefaultAAValue(CacheType testValue) {
+ this.verifyAAValue(
+ testValue,
+ this.caching.getCacheTypeDefault(),
+ this.cacheTypeDefaultHolder,
+ Caching.ECLIPSELINK_CACHE_TYPE_DEFAULT);
+ }
+
+ /**
+ * Performs three value tests:<br>
+ * 1. subject value<br>
+ * 2. aspect adapter value<br>
+ * 3. persistenceUnit property value<br>
+ */
+ protected void verifySharedCacheDefaultAAValue(Boolean testValue) {
+ this.verifyAAValue(
+ testValue,
+ this.caching.getSharedCacheDefault(),
+ this.sharedCacheDefaultHolder,
+ Caching.ECLIPSELINK_CACHE_SHARED_DEFAULT);
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/JptEclipseLinkCoreCachingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/JptEclipseLinkCoreCachingTests.java
new file mode 100644
index 0000000000..5f6d62b720
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/caching/JptEclipseLinkCoreCachingTests.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal.caching;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * decentralize test creation code
+ */
+public class JptEclipseLinkCoreCachingTests
+{
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JptEclipseLinkCoreCachingTests.class.getPackage().getName());
+
+ suite.addTestSuite(CachingValueModelTests.class);
+ suite.addTestSuite(CachingAdapterTests.class);
+
+ return suite;
+ }
+
+ private JptEclipseLinkCoreCachingTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/JptEclipseLinkCoreSchemaGenerationTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/JptEclipseLinkCoreSchemaGenerationTests.java
new file mode 100644
index 0000000000..c475f9f512
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/JptEclipseLinkCoreSchemaGenerationTests.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal.schema.generation;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * decentralize test creation code
+ */
+public class JptEclipseLinkCoreSchemaGenerationTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JptEclipseLinkCoreSchemaGenerationTests.class.getPackage().getName());
+
+ suite.addTestSuite(SchemaGenerationValueModelTests.class);
+ suite.addTestSuite(SchemaGenerationBasicAdapterTests.class);
+ suite.addTestSuite(SchemaGenerationAdapterTests.class);
+
+ return suite;
+ }
+
+ private JptEclipseLinkCoreSchemaGenerationTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationAdapterTests.java
new file mode 100644
index 0000000000..13fd07545d
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationAdapterTests.java
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal.schema.generation;
+
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.context.persistence.Property;
+import org.eclipse.jpt.core.internal.context.persistence.GenericProperty;
+import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkJpaProperties;
+import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties;
+import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitPropertyListListener;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.DdlGenerationType;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.EclipseLinkSchemaGeneration;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.OutputMode;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.SchemaGeneration;
+import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase;
+import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.model.value.ListValueModel;
+
+/**
+ * Tests the update of OutputMode model object by the SchemaGeneration adapter
+ * when the PersistenceUnit changes.
+ */
+public class SchemaGenerationAdapterTests extends PersistenceUnitTestCase
+{
+ private SchemaGeneration schemaGeneration;
+
+ public static final String DDL_GENERATION_TYPE_KEY = SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE;
+ public static final DdlGenerationType DDL_GENERATION_TYPE_TEST_VALUE = DdlGenerationType.drop_and_create_tables;
+ public static final DdlGenerationType DDL_GENERATION_TYPE_TEST_VALUE_2 = DdlGenerationType.none;
+
+ public static final String OUTPUT_MODE_KEY = SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE;
+ public static final OutputMode OUTPUT_MODE_TEST_VALUE = OutputMode.sql_script;
+ public static final OutputMode OUTPUT_MODE_TEST_VALUE_2 = OutputMode.database;
+
+ private static final String CREATE_FILE_NAME_KEY = SchemaGeneration.ECLIPSELINK_CREATE_FILE_NAME;
+ private static final String CREATE_FILE_NAME_TEST_VALUE = "create-file-name.test";
+ private static final String CREATE_FILE_NAME_TEST_VALUE_2 = "create-file-name-2.test";
+
+ private static final String DROP_FILE_NAME_KEY = SchemaGeneration.ECLIPSELINK_DROP_FILE_NAME;
+ private static final String DROP_FILE_NAME_TEST_VALUE = "drop-file-name.test";
+ private static final String DROP_FILE_NAME_TEST_VALUE_2 = "drop-file-name-2.test";
+
+ private static final String APPLICATION_LOCATION_KEY = SchemaGeneration.ECLIPSELINK_APPLICATION_LOCATION;
+ private static final String APPLICATION_LOCATION_TEST_VALUE = "C:/temp";
+ private static final String APPLICATION_LOCATION_TEST_VALUE_2 = "C:/tmp";
+
+ public SchemaGenerationAdapterTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.schemaGeneration = this.persistenceUnitProperties.getSchemaGeneration();
+
+ PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener();
+ this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.OUTPUT_MODE_PROPERTY, propertyChangeListener);
+ this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY, propertyChangeListener);
+ this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.CREATE_FILE_NAME_PROPERTY, propertyChangeListener);
+ this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.DROP_FILE_NAME_PROPERTY, propertyChangeListener);
+ this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.APPLICATION_LOCATION_PROPERTY, propertyChangeListener);
+ this.clearEvent();
+ }
+
+ private PropertyChangeListener buildPropertyChangeListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent event) {
+ SchemaGenerationAdapterTests.this.propertyChangedEvent = event;
+ SchemaGenerationAdapterTests.this.propertyChangedEventCount++;
+ }
+
+ @Override
+ public String toString() {
+ return "SchemaGeneration listener";
+ }
+ };
+ }
+
+ /**
+ * Initializes directly the PU properties before testing. Cannot use
+ * Property Holder to initialize because it is not created yet
+ */
+ @Override
+ protected void populatePu() {
+ this.propertiesTotal = 9;
+ this.modelPropertiesSizeOriginal = 5;
+ this.modelPropertiesSize = this.modelPropertiesSizeOriginal;
+
+ this.persistenceUnit().putProperty("property.0", "value.0", false);
+ this.persistenceUnit().putProperty(OUTPUT_MODE_KEY, this.getEclipseLinkValueString(OUTPUT_MODE_TEST_VALUE), false);
+ this.persistenceUnit().putProperty("property.2", "value.2", false);
+ this.persistenceUnit().putProperty("property.3", "value.3", false);
+ this.persistenceUnit().putProperty("property.4", "value.4", false);
+ this.persistenceUnit().putProperty(DDL_GENERATION_TYPE_KEY, this.getEclipseLinkValueString(DDL_GENERATION_TYPE_TEST_VALUE), false);
+ this.persistenceUnit().putProperty(CREATE_FILE_NAME_KEY, CREATE_FILE_NAME_TEST_VALUE, false);
+ this.persistenceUnit().putProperty(DROP_FILE_NAME_KEY, DROP_FILE_NAME_TEST_VALUE, false);
+ this.persistenceUnit().putProperty(APPLICATION_LOCATION_KEY, APPLICATION_LOCATION_TEST_VALUE, false);
+ return;
+ }
+
+ public void testHasListeners() throws Exception {
+ ListAspectAdapter<PersistenceUnit, Property> propertiesAdapter = (ListAspectAdapter<PersistenceUnit, Property>) ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertiesAdapter();
+ GenericProperty outputModeProperty = (GenericProperty) this.persistenceUnit().getProperty(OUTPUT_MODE_KEY);
+ GenericProperty ddlGenTypeProperty = (GenericProperty) this.persistenceUnit().getProperty(DDL_GENERATION_TYPE_KEY);
+ ListValueModel<Property> propertyListAdapter = ((EclipseLinkJpaProperties) this.persistenceUnitProperties).propertyListAdapter();
+
+ assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+ assertTrue(outputModeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY));
+ assertTrue(ddlGenTypeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY));
+ this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.OUTPUT_MODE_PROPERTY);
+ this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY);
+ this.verifyHasListeners(propertyListAdapter);
+
+ EclipseLinkSchemaGeneration schemaGen = (EclipseLinkSchemaGeneration) this.schemaGeneration;
+ PersistenceUnitPropertyListListener propertyListListener = schemaGen.propertyListListener();
+ propertyListAdapter.removeListChangeListener(ListValueModel.LIST_VALUES, propertyListListener);
+ this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.OUTPUT_MODE_PROPERTY);
+ this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY);
+ }
+
+ // ********** CreateFileName **********
+ /**
+ * Tests the update of CreateFileName property by the SchemaGeneration
+ * adapter when the PU or the model changes.
+ */
+ public void testSetCreateFileName() throws Exception {
+ this.verifyModelInitialized(
+ this.schemaGeneration.getCreateFileName(),
+ CREATE_FILE_NAME_TEST_VALUE);
+ this.verifySetProperty(
+ SchemaGeneration.CREATE_FILE_NAME_PROPERTY,
+ CREATE_FILE_NAME_KEY,
+ CREATE_FILE_NAME_TEST_VALUE,
+ CREATE_FILE_NAME_TEST_VALUE_2);
+ }
+
+ public void testAddRemoveCreateFileName() throws Exception {
+ this.verifyAddRemoveProperty(
+ SchemaGeneration.CREATE_FILE_NAME_PROPERTY,
+ CREATE_FILE_NAME_KEY,
+ CREATE_FILE_NAME_TEST_VALUE,
+ CREATE_FILE_NAME_TEST_VALUE_2);
+ }
+
+ // ********** DropFileName **********
+ /**
+ * Tests the update of DropFileName property by the SchemaGeneration adapter
+ * when the PU or the model changes.
+ */
+ public void testSetDropFileName() throws Exception {
+ this.verifyModelInitialized(this.schemaGeneration.getDropFileName(), DROP_FILE_NAME_TEST_VALUE);
+ this.verifySetProperty(SchemaGeneration.DROP_FILE_NAME_PROPERTY, DROP_FILE_NAME_KEY, DROP_FILE_NAME_TEST_VALUE, DROP_FILE_NAME_TEST_VALUE_2);
+ }
+
+ public void testAddRemoveDropFileName() throws Exception {
+ this.verifyAddRemoveProperty(SchemaGeneration.DROP_FILE_NAME_PROPERTY, DROP_FILE_NAME_KEY, DROP_FILE_NAME_TEST_VALUE, DROP_FILE_NAME_TEST_VALUE_2);
+ }
+
+ // ********** ApplicationLocation **********
+ /**
+ * Tests the update of ApplicationLocation property by the SchemaGeneration
+ * adapter when the PU or the model changes.
+ */
+ public void testSetApplicationLocation() throws Exception {
+ this.verifyModelInitialized(this.schemaGeneration.getApplicationLocation(), APPLICATION_LOCATION_TEST_VALUE);
+ this.verifySetProperty(SchemaGeneration.APPLICATION_LOCATION_PROPERTY, APPLICATION_LOCATION_KEY, APPLICATION_LOCATION_TEST_VALUE, APPLICATION_LOCATION_TEST_VALUE_2);
+ }
+
+ public void testAddRemoveApplicationLocation() throws Exception {
+ this.verifyAddRemoveProperty(SchemaGeneration.APPLICATION_LOCATION_PROPERTY, APPLICATION_LOCATION_KEY, APPLICATION_LOCATION_TEST_VALUE, APPLICATION_LOCATION_TEST_VALUE_2);
+ }
+
+ // ********** OutputMode **********
+ /**
+ * Tests the update of OutputMode property by the SchemaGeneration adapter
+ * when the PU or the model changes.
+ */
+ public void testSetOutputMode() throws Exception {
+ this.verifyModelInitialized(this.schemaGeneration.getOutputMode(), OUTPUT_MODE_TEST_VALUE);
+ this.verifySetProperty(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_KEY, OUTPUT_MODE_TEST_VALUE, OUTPUT_MODE_TEST_VALUE_2);
+ }
+
+ public void testAddRemoveOutputMode() throws Exception {
+ this.verifyAddRemoveProperty(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_KEY, OUTPUT_MODE_TEST_VALUE, OUTPUT_MODE_TEST_VALUE_2);
+ }
+
+ // ********** DdlGenerationType **********
+ /**
+ * Tests the update of DdlGenerationType property by the SchemaGeneration
+ * adapter when the PU or the model changes.
+ */
+ public void testSetDdlGenerationType() throws Exception {
+ this.verifyModelInitialized(this.schemaGeneration.getDdlGenerationType(), DDL_GENERATION_TYPE_TEST_VALUE);
+ this.verifySetProperty(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY, DDL_GENERATION_TYPE_KEY, DDL_GENERATION_TYPE_TEST_VALUE, DDL_GENERATION_TYPE_TEST_VALUE_2);
+ }
+
+ public void testAddRemoveDdlGenerationType() throws Exception {
+ this.verifyAddRemoveProperty(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY, DDL_GENERATION_TYPE_KEY, DDL_GENERATION_TYPE_TEST_VALUE, DDL_GENERATION_TYPE_TEST_VALUE_2);
+ }
+
+ // ****** convenience methods *******
+ @Override
+ protected void setProperty(String propertyName, Object newValue) throws NoSuchFieldException {
+ if (propertyName.equals(SchemaGeneration.OUTPUT_MODE_PROPERTY))
+ this.schemaGeneration.setOutputMode((OutputMode) newValue);
+ // else if( propertyName.equals( Caching.CACHE_SIZE_PROPERTY))
+ // TODO
+ else if (propertyName.equals(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY))
+ this.schemaGeneration.setDdlGenerationType((DdlGenerationType) newValue);
+ else if (propertyName.equals(SchemaGeneration.APPLICATION_LOCATION_PROPERTY))
+ this.schemaGeneration.setApplicationLocation((String) newValue);
+ else if (propertyName.equals(SchemaGeneration.CREATE_FILE_NAME_PROPERTY))
+ this.schemaGeneration.setCreateFileName((String) newValue);
+ else if (propertyName.equals(SchemaGeneration.DROP_FILE_NAME_PROPERTY))
+ this.schemaGeneration.setDropFileName((String) newValue);
+ else
+ this.throwMissingDefinition("setProperty", propertyName);
+ }
+
+ @Override
+ protected void verifyPutProperty(String propertyName, Object expectedValue) throws NoSuchFieldException {
+ if (propertyName.equals(SchemaGeneration.OUTPUT_MODE_PROPERTY))
+ this.verifyPutProperty(propertyName, this.schemaGeneration.getOutputMode(), expectedValue);
+ else if (propertyName.equals(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY))
+ this.verifyPutProperty(propertyName, this.schemaGeneration.getDdlGenerationType(), expectedValue);
+ else if (propertyName.equals(SchemaGeneration.APPLICATION_LOCATION_PROPERTY))
+ this.verifyPutProperty(propertyName, this.schemaGeneration.getApplicationLocation(), expectedValue);
+ else if (propertyName.equals(SchemaGeneration.CREATE_FILE_NAME_PROPERTY))
+ this.verifyPutProperty(propertyName, this.schemaGeneration.getCreateFileName(), expectedValue);
+ else if (propertyName.equals(SchemaGeneration.DROP_FILE_NAME_PROPERTY))
+ this.verifyPutProperty(propertyName, this.schemaGeneration.getDropFileName(), expectedValue);
+ else
+ this.throwMissingDefinition("verifyPutProperty", propertyName);
+ }
+
+ protected PersistenceUnitProperties model() {
+ return this.schemaGeneration;
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationBasicAdapterTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationBasicAdapterTests.java
new file mode 100644
index 0000000000..a6f5fc0a92
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationBasicAdapterTests.java
@@ -0,0 +1,196 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal.schema.generation;
+
+import java.util.ListIterator;
+
+import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.context.persistence.Property;
+import org.eclipse.jpt.core.internal.context.persistence.GenericProperty;
+import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties;
+import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitPropertyListListener;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.DdlGenerationType;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.EclipseLinkSchemaGeneration;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.OutputMode;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.SchemaGeneration;
+import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase;
+import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter;
+import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.model.value.ListValueModel;
+import org.eclipse.jpt.utility.model.value.PropertyValueModel;
+
+/**
+ * Tests the update of OutputMode model object by the SchemaGeneration adapter
+ * when the PersistenceUnit changes.
+ */
+public class SchemaGenerationBasicAdapterTests extends PersistenceUnitTestCase
+{
+ private SchemaGeneration schemaGeneration;
+
+ public static final String outputModeKey = SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE;
+ public static final String ddlGenTypeKey = SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE;
+
+ public static final OutputMode OUTPUT_MODE_TEST_VALUE = OutputMode.sql_script;
+ public static final OutputMode OUTPUT_MODE_TEST_VALUE_2 = OutputMode.database;
+
+ public static final DdlGenerationType DDL_GENERATION_TYPE_TEST_VALUE = DdlGenerationType.drop_and_create_tables;
+ public static final DdlGenerationType DDL_GENERATION_TYPE_TEST_VALUE_2 = DdlGenerationType.none;
+
+ public SchemaGenerationBasicAdapterTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.schemaGeneration = this.persistenceUnitProperties.getSchemaGeneration();
+ PropertyChangeListener propertyChangeListener = this.buildPropertyChangeListener();
+ this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.OUTPUT_MODE_PROPERTY, propertyChangeListener);
+ this.schemaGeneration.addPropertyChangeListener(SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY, propertyChangeListener);
+ this.clearEvent();
+ }
+
+ private PropertyChangeListener buildPropertyChangeListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent event) {
+ SchemaGenerationBasicAdapterTests.this.propertyChangedEvent = event;
+ SchemaGenerationBasicAdapterTests.this.propertyChangedEventCount++;
+ }
+
+ @Override
+ public String toString() {
+ return "outputMode listener";
+ }
+ };
+ }
+
+ /**
+ * Initializes directly the PU properties before testing. Cannot use
+ * Property Holder to initialize because it is not created yet
+ */
+ @Override
+ protected void populatePu() {
+ this.propertiesTotal = 6;
+ this.modelPropertiesSizeOriginal = 2;
+ this.modelPropertiesSize = this.modelPropertiesSizeOriginal;
+
+ this.persistenceUnit().putProperty("property.0", "value.0", false);
+ this.persistenceUnit().putProperty(outputModeKey, this.getEclipseLinkValueString(OUTPUT_MODE_TEST_VALUE), false);
+ this.persistenceUnit().putProperty("property.2", "value.2", false);
+ this.persistenceUnit().putProperty("property.3", "value.3", false);
+ this.persistenceUnit().putProperty("property.4", "value.4", false);
+ this.persistenceUnit().putProperty(ddlGenTypeKey, this.getEclipseLinkValueString(DDL_GENERATION_TYPE_TEST_VALUE), false);
+ return;
+ }
+
+ /** ****** test methods ******* */
+ public void testHasListeners() throws Exception {
+ ListAspectAdapter<PersistenceUnit, Property> propertiesAdapter =
+ (ListAspectAdapter<PersistenceUnit, Property>) this.buildPropertiesAdapter(this.subjectHolder);
+ assertFalse(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+ GenericProperty outputModeProperty = (GenericProperty) this.persistenceUnit().getProperty(outputModeKey);
+ GenericProperty ddlGenTypeProperty = (GenericProperty) this.persistenceUnit().getProperty(ddlGenTypeKey);
+ assertTrue(outputModeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY));
+
+ ListValueModel<Property> propertyListAdapter =
+ new ItemPropertyListValueModelAdapter<Property>(propertiesAdapter, Property.VALUE_PROPERTY, Property.NAME_PROPERTY);
+ assertFalse(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+ assertTrue(outputModeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY));
+ assertTrue(ddlGenTypeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY));
+ this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.OUTPUT_MODE_PROPERTY);
+ this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY);
+ this.verifyHasNoListeners(propertyListAdapter);
+
+ PersistenceUnitPropertyListListener propertyListListener =
+ new PersistenceUnitPropertyListListener(this.schemaGeneration);
+ propertyListAdapter.addListChangeListener(ListValueModel.LIST_VALUES, propertyListListener);
+ assertTrue(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+ assertTrue(outputModeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY));
+ assertTrue(ddlGenTypeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY));
+ this.verifyHasListeners(propertyListAdapter);
+
+ propertyListAdapter.removeListChangeListener(ListValueModel.LIST_VALUES, propertyListListener);
+ assertFalse(propertiesAdapter.hasAnyListChangeListeners(ListValueModel.LIST_VALUES));
+ assertTrue(outputModeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY));
+ assertTrue(ddlGenTypeProperty.hasAnyPropertyChangeListeners(Property.VALUE_PROPERTY));
+ this.verifyHasNoListeners(propertyListAdapter);
+ }
+
+ /**
+ * Tests the update of OutputMode property by the SchemaGeneration adapter
+ * when the PU changes.
+ */
+ public void testOutputModeUpdate() throws Exception {
+ ListValueModel<Property> propertiesAdapter = this.buildPropertiesAdapter(this.subjectHolder);
+ ListValueModel<Property> propertyListAdapter = new ItemPropertyListValueModelAdapter<Property>(propertiesAdapter, Property.VALUE_PROPERTY);
+ PersistenceUnitPropertyListListener propertyListListener = ((EclipseLinkSchemaGeneration) this.schemaGeneration).propertyListListener();
+ propertyListAdapter.addListChangeListener(ListValueModel.LIST_VALUES, propertyListListener);
+
+ this.verifyHasListeners(propertyListAdapter);
+ this.verifyHasListeners(this.schemaGeneration, SchemaGeneration.OUTPUT_MODE_PROPERTY);
+
+ // Basic
+ assertEquals(this.propertiesTotal, propertyListAdapter.size());
+ assertTrue(schemaGeneration.itemIsProperty(this.persistenceUnit().getProperty(outputModeKey)));
+ assertEquals(OUTPUT_MODE_TEST_VALUE, this.schemaGeneration.getOutputMode());
+
+ // Replace
+ this.putEnumProperty(outputModeKey, OUTPUT_MODE_TEST_VALUE_2);
+ this.verifyPutProperty(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE_2, this.schemaGeneration.getOutputMode());
+
+ // Remove
+ this.clearEvent();
+ --this.propertiesTotal;
+ --this.modelPropertiesSize;
+ this.persistenceUnit().removeProperty(outputModeKey);
+ assertFalse(this.persistenceUnit().containsProperty(outputModeKey));
+ assertEquals(this.propertiesTotal, propertyListAdapter.size());
+ assertEquals(this.modelPropertiesSize, this.modelPropertiesSizeOriginal - 1);
+ assertNotNull(this.propertyChangedEvent);
+ assertNull(this.propertyChangedEvent.newValue());
+
+ // Add original OutputMode
+ ++this.propertiesTotal;
+ ++this.modelPropertiesSize;
+ this.putEnumProperty(outputModeKey, OUTPUT_MODE_TEST_VALUE);
+ this.verifyPutProperty(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE, this.schemaGeneration.getOutputMode());
+
+ // Replace again
+ this.putEnumProperty(outputModeKey, OUTPUT_MODE_TEST_VALUE_2);
+ this.verifyPutProperty(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE_2, this.schemaGeneration.getOutputMode());
+
+ // Replace by setting model object
+ this.clearEvent();
+ this.schemaGeneration.setOutputMode(OUTPUT_MODE_TEST_VALUE);
+ this.verifyPutProperty(SchemaGeneration.OUTPUT_MODE_PROPERTY, OUTPUT_MODE_TEST_VALUE, this.schemaGeneration.getOutputMode());
+ }
+
+ // ****** convenience methods *******
+ protected PersistenceUnitProperties model() {
+ return this.schemaGeneration;
+ }
+
+ private ListValueModel<Property> buildPropertiesAdapter(PropertyValueModel<PersistenceUnit> subjectHolder) {
+ return new ListAspectAdapter<PersistenceUnit, Property>(subjectHolder, PersistenceUnit.PROPERTIES_LIST) {
+ @Override
+ protected ListIterator<Property> listIterator_() {
+ return this.subject.properties();
+ }
+
+ @Override
+ protected int size_() {
+ return this.subject.propertiesSize();
+ }
+ };
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationValueModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationValueModelTests.java
new file mode 100644
index 0000000000..e41439469e
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/schema/generation/SchemaGenerationValueModelTests.java
@@ -0,0 +1,223 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tests.internal.schema.generation;
+
+import org.eclipse.jpt.eclipselink.core.internal.context.PersistenceUnitProperties;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.DdlGenerationType;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.OutputMode;
+import org.eclipse.jpt.eclipselink.core.internal.context.schema.generation.SchemaGeneration;
+import org.eclipse.jpt.eclipselink.core.tests.internal.PersistenceUnitTestCase;
+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;
+import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
+
+/**
+ * SchemaGenerationValueModelTests
+ *
+ * Tests the PropertyValueModel of SchemaGeneration model and the update of the
+ * PersistenceUnit.
+ */
+public class SchemaGenerationValueModelTests extends PersistenceUnitTestCase
+{
+ private SchemaGeneration schemaGen;
+ private PropertyValueModel<SchemaGeneration> schemaGenHolder;
+
+ private WritablePropertyValueModel<DdlGenerationType> ddlGenerationTypeHolder;
+ private PropertyChangeEvent ddlGenerationTypeEvent;
+
+ private WritablePropertyValueModel<OutputMode> outputModeHolder;
+ private PropertyChangeEvent outputModeEvent;
+
+ public static final DdlGenerationType DDL_GENERATION_TYPE_TEST_VALUE = DdlGenerationType.drop_and_create_tables;
+ public static final OutputMode OUTPUT_MODE_TEST_VALUE = OutputMode.sql_script;
+
+ public SchemaGenerationValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.schemaGen = this.persistenceUnitProperties.getSchemaGeneration(); // Subject
+ this.schemaGenHolder = new SimplePropertyValueModel<SchemaGeneration>(this.schemaGen);
+
+ this.ddlGenerationTypeHolder = this.buildDdlGenerationTypeAA(this.schemaGenHolder);
+ PropertyChangeListener ddlGenerationTypeListener = this.buildDdlGenerationTypeChangeListener();
+ this.ddlGenerationTypeHolder.addPropertyChangeListener(PropertyValueModel.VALUE, ddlGenerationTypeListener);
+ this.ddlGenerationTypeEvent = null;
+
+ this.outputModeHolder = this.buildOutputModeAA(this.schemaGenHolder);
+ PropertyChangeListener outputModeListener = this.buildOutputModeChangeListener();
+ this.outputModeHolder.addPropertyChangeListener(PropertyValueModel.VALUE, outputModeListener);
+ this.outputModeEvent = null;
+ }
+
+ /**
+ * Initializes directly the PU properties before testing. Cannot use
+ * Property Holder to initialize because it is not created yet
+ */
+ @Override
+ protected void populatePu() {
+ this.persistenceUnit().putProperty(
+ SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE,
+ this.getEclipseLinkValueString(DDL_GENERATION_TYPE_TEST_VALUE),
+ false);
+ this.persistenceUnit().putProperty(
+ SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE,
+ this.getEclipseLinkValueString(OUTPUT_MODE_TEST_VALUE),
+ false);
+ return;
+ }
+
+ protected PersistenceUnitProperties model() {
+ return this.schemaGen;
+ }
+
+ /** ****** DdlGenerationType ******* */
+ private WritablePropertyValueModel<DdlGenerationType> buildDdlGenerationTypeAA(PropertyValueModel<SchemaGeneration> subjectHolder) {
+ return new PropertyAspectAdapter<SchemaGeneration, DdlGenerationType>(subjectHolder, SchemaGeneration.DDL_GENERATION_TYPE_PROPERTY) {
+ @Override
+ protected DdlGenerationType buildValue_() {
+ return this.subject.getDdlGenerationType();
+ }
+
+ @Override
+ protected void setValue_(DdlGenerationType enumValue) {
+ this.subject.setDdlGenerationType(enumValue);
+ }
+ };
+ }
+
+ private PropertyChangeListener buildDdlGenerationTypeChangeListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ SchemaGenerationValueModelTests.this.ddlGenerationTypeEvent = e;
+ }
+ };
+ }
+
+ /** ****** OutputMode ******* */
+ private WritablePropertyValueModel<OutputMode> buildOutputModeAA(PropertyValueModel<SchemaGeneration> subjectHolder) {
+ return new PropertyAspectAdapter<SchemaGeneration, OutputMode>(subjectHolder, SchemaGeneration.OUTPUT_MODE_PROPERTY) {
+ @Override
+ protected OutputMode buildValue_() {
+ return this.subject.getOutputMode();
+ }
+
+ @Override
+ protected void setValue_(OutputMode enumValue) {
+ this.subject.setOutputMode(enumValue);
+ }
+ };
+ }
+
+ private PropertyChangeListener buildOutputModeChangeListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ SchemaGenerationValueModelTests.this.outputModeEvent = e;
+ }
+ };
+ }
+
+ public void testValue() {
+ /** ****** DdlGenerationType ******* */
+ this.verifyDdlGenerationTypeAAValue(DDL_GENERATION_TYPE_TEST_VALUE);
+ assertEquals(
+ SchemaGeneration.DEFAULT_SCHEMA_GENERATION_DDL_GENERATION_TYPE,
+ this.schemaGen.getDefaultDdlGenerationType());
+ /** ****** OutputMode ******* */
+ this.verifyOutputModeAAValue(OUTPUT_MODE_TEST_VALUE);
+ assertEquals(
+ SchemaGeneration.DEFAULT_SCHEMA_GENERATION_OUTPUT_MODE,
+ this.schemaGen.getDefaultOutputMode());
+ }
+
+ public void testSetValue() throws Exception {
+ /** ****** DdlGenerationType ******* */
+ this.ddlGenerationTypeEvent = null;
+ this.verifyHasListeners(this.ddlGenerationTypeHolder, PropertyValueModel.VALUE);
+ DdlGenerationType newDdlGenerationType = DdlGenerationType.create_tables;
+ // Modify the persistenceUnit directly
+ this.subject.putProperty(
+ SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE,
+ this.getEclipseLinkValueString(newDdlGenerationType),
+ false);
+ this.verifyDdlGenerationTypeAAValue(newDdlGenerationType);
+ assertNotNull(this.ddlGenerationTypeEvent);
+
+ /** ****** OutputMode ******* */
+ this.outputModeEvent = null;
+ this.verifyHasListeners(this.outputModeHolder, PropertyValueModel.VALUE);
+ OutputMode newOutputMode = OutputMode.database;
+ // Modify the property holder
+ this.outputModeHolder.setValue(newOutputMode);
+ this.verifyOutputModeAAValue(newOutputMode);
+ assertNotNull(this.outputModeEvent);
+ }
+
+ public void testSetNullValue() {
+ /** ****** DdlGenerationType ******* */
+ this.ddlGenerationTypeEvent = null;
+ // Setting the persistenceUnit directly
+ this.subject.putProperty(SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE, null, false);
+ this.ddlGenerationTypeHolder.setValue(null);
+ // testing Holder
+ this.verifyDdlGenerationTypeAAValue(null);
+ assertNotNull(this.ddlGenerationTypeEvent);
+ // testing PU properties
+ boolean containsDdlGenerationTypeProperty =
+ this.persistenceUnit().containsProperty(SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE);
+ assertFalse(containsDdlGenerationTypeProperty);
+
+ /** ****** OutputMode ******* */
+ this.outputModeEvent = null;
+ // Setting the property holder
+ this.outputModeHolder.setValue(null);
+ // testing Holder
+ this.verifyOutputModeAAValue(null);
+ assertNotNull(this.outputModeEvent);
+ // testing PU properties
+ boolean containsOutputModeProperty =
+ this.persistenceUnit().containsProperty(SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE);
+ assertFalse(containsOutputModeProperty);
+ }
+
+ /** ****** convenience methods ******* */
+ /**
+ * Performs three value tests:<br>
+ * 1. subject value<br>
+ * 2. aspect adapter value<br>
+ * 3. persistenceUnit property value<br>
+ */
+ protected void verifyDdlGenerationTypeAAValue(DdlGenerationType testValue) {
+ this.verifyAAValue(
+ testValue,
+ this.schemaGen.getDdlGenerationType(),
+ this.ddlGenerationTypeHolder,
+ SchemaGeneration.ECLIPSELINK_DDL_GENERATION_TYPE);
+ }
+
+ /**
+ * Performs three value tests:<br>
+ * 1. subject value<br>
+ * 2. aspect adapter value<br>
+ * 3. persistenceUnit property value<br>
+ */
+ protected void verifyOutputModeAAValue(OutputMode testValue) {
+ this.verifyAAValue(
+ testValue,
+ this.schemaGen.getOutputMode(),
+ this.outputModeHolder,
+ SchemaGeneration.ECLIPSELINK_DDL_GENERATION_OUTPUT_MODE);
+ }
+}

Back to the top