added tests for recursive cdm entity loading and updated corresponding code
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 11 Nov 2014 17:58:25 +0000 (17:58 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 11 Nov 2014 17:58:25 +0000 (17:58 +0000)
16 files changed:
.gitattributes
eu.etaxonomy.taxeditor.remoting/.classpath
eu.etaxonomy.taxeditor.remoting/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.remoting/build.properties
eu.etaxonomy.taxeditor.remoting/pom.xml
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CachedCommonServiceImpl.java
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmEntityCacheKey.java
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelCacher.java
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelFieldPropertyFromClass.java [moved from eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelGetMethodFromClass.java with 59% similarity]
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmTransientEntityCacher.java
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/taxeditor/remoting/CdmRemotingException.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/taxeditor/remoting/session/CdmEntitySessionManager.java
eu.etaxonomy.taxeditor.remoting/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
eu.etaxonomy.taxeditor.remoting/src/test/java/eu/etaxonomy/cdm/api/cache/CdmClientCachingTest.java
eu.etaxonomy.taxeditor.remoting/src/test/java/eu/etaxonomy/cdm/api/cache/CdmModelGetMethodCacherTest.java
eu.etaxonomy.taxeditor.remoting/src/test/resources/eu/etaxonomy/cdm/api/cache/CdmClientCachingTest.xml

index 11cd07e37d072e62c4ee7ab701262b281895b293..d661362f97c2145fc189d4944556d3425d615970 100644 (file)
@@ -1018,7 +1018,7 @@ eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmClie
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmEntityCacheKey.java -text
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmEntityCachingUtils.java -text
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelCacher.java -text
-eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelGetMethodFromClass.java -text
+eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelFieldPropertyFromClass.java -text
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmRemoteCacheManager.java -text
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java -text
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmTransientEntityCacher.java -text
@@ -1028,6 +1028,7 @@ eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteS
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSourceBase.java -text
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSourceException.java -text
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/remote/ICdmRemoteSource.java -text
+eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/taxeditor/remoting/CdmRemotingException.java -text
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/taxeditor/remoting/RemotingTestPluginActivator.java -text
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/taxeditor/remoting/session/CdmClientSessionException.java -text
 eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/taxeditor/remoting/session/CdmEntitySession.java -text
index 5ece8b2eff46dfd9df19384f87130723c43ecb6d..cfd2ac5d0fac03c8ec56d333c86917971a9542ae 100644 (file)
@@ -1,42 +1,19 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
        <classpathentry including="**/*.java" kind="src" path="src/main/java"/>
        <classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
        <classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
        <classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
-       <classpathentry exported="true" kind="lib" path="lib/opencsv-2.4.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/dbunit-2.4.9.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-persistence-3.3.8-SNAPSHOT.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/org.springframework.aop-3.2.2.RELEASE.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/org.springframework.aspects-3.2.2.RELEASE.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/org.springframework.beans-3.2.2.RELEASE.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/org.springframework.core-3.2.2.RELEASE.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/org.springframework.expression-3.2.2.RELEASE.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/org.springframework.jdbc-3.2.2.RELEASE.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/org.springframework.orm-3.2.2.RELEASE.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/org.springframework.transaction-3.2.2.RELEASE.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/org.springframework.web-3.2.2.RELEASE.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/org.springframework.context-3.2.2.RELEASE.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/hibernate-commons-annotations-4.0.1.Final.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/hibernate-core-4.1.10.Final.jar" sourcepath="/home/cmathew/Temp/hibernate-core-4.1.10.Final-sources.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/hibernate-entitymanager-4.1.10.Final.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/hibernate-envers-4.1.10.Final.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/hibernate-search-engine-4.2.0.Final.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
-       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
        <classpathentry exported="true" kind="lib" path="lib/aspectjrt-1.7.1.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/c3p0-0.9.2.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-commons-3.3.8-SNAPSHOT.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-ext-3.3.8-SNAPSHOT.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-model-3.3.8-SNAPSHOT.jar" sourcepath="/home/cmathew/Development/EDIT/taxeditor/eu.etaxonomy.taxeditor.cdmlib/lib/cdmlib-model-3.3.8-SNAPSHOT-sources.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/cdmlib-services-3.3.8-SNAPSHOT.jar" sourcepath="/home/cmathew/.m2/repository/eu/etaxonomy/cdmlib-services/3.3.8-SNAPSHOT/cdmlib-services-3.3.8-SNAPSHOT-sources.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/ehcache-core-2.4.3.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/hamcrest-core-1.3.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/jboss-logging-3.1.3.GA.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/jboss-transaction-api_1.1_spec-1.0.0.Final.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/jdom-1.1.3.jar"/>
-       <classpathentry exported="true" kind="lib" path="lib/junit-4.11.jar" sourcepath="/home/cmathew/Downloads/junit-4.11-sources.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/junit-4.11.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/log4j-1.2.17.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/spring-security-config-3.1.3.RELEASE.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/spring-security-core-3.1.3.RELEASE.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/unitils-dbmaintainer-3.4.2.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/h2-1.4.181.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/unitils-dbunit-3.4.2.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/hibernate-commons-annotations-4.0.1.Final.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/hibernate-core-4.1.10.Final.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/hibernate-entitymanager-4.1.10.Final.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/hibernate-envers-4.1.10.Final.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/hibernate-search-engine-4.2.0.Final.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.context-3.2.2.RELEASE.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.aop-3.2.2.RELEASE.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.aspects-3.2.2.RELEASE.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.beans-3.2.2.RELEASE.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.core-3.2.2.RELEASE.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.expression-3.2.2.RELEASE.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.jdbc-3.2.2.RELEASE.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.orm-3.2.2.RELEASE.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.transaction-3.2.2.RELEASE.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.web-3.2.2.RELEASE.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/dbunit-2.4.9.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/opencsv-2.4.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/dom4j-1.6.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-commons-3.4.0-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-ext-3.4.0-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-model-3.4.0-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-services-3.4.0-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/usertype.jodatime-2.0.1.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/usertype.spi-2.0.1.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/cdmlib-persistence-3.4.0-SNAPSHOT.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/wsdl4j-1.6.3.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/validation-api-1.1.0.Final.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.context.support-3.2.2.RELEASE.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/org.springframework.test-3.2.2.RELEASE.jar"/>
        <classpathentry kind="output" path="target/classes"/>
 </classpath>
index 2824f5434d48b3c4c1fa8c7318f3a5afea105035..0ce27249c12a3c4bb4f320bb02c87196b60cfe31 100644 (file)
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: UI Test Bundle
 Bundle-SymbolicName: eu.etaxonomy.taxeditor.remoting;singleton:=true
-Bundle-Version: 3.3.8.qualifier
+Bundle-Version: 3.4.0.qualifier
 Bundle-Activator: eu.etaxonomy.taxeditor.remoting.RemotingTestPluginActivator
 Bundle-Vendor: EDIT
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
@@ -14,10 +14,6 @@ Export-Package: eu.etaxonomy.cdm.api.application,
  org.hibernate.proxy
 Bundle-ClassPath: lib/aspectjrt-1.7.1.jar,
  lib/c3p0-0.9.2.jar,
- lib/cdmlib-commons-3.3.8-SNAPSHOT.jar,
- lib/cdmlib-ext-3.3.8-SNAPSHOT.jar,
- lib/cdmlib-model-3.3.8-SNAPSHOT.jar,
- lib/cdmlib-services-3.3.8-SNAPSHOT.jar,
  lib/ehcache-core-2.4.3.jar,
  lib/hamcrest-core-1.3.jar,
  lib/jboss-logging-3.1.3.GA.jar,
@@ -63,7 +59,19 @@ Bundle-ClassPath: lib/aspectjrt-1.7.1.jar,
  lib/org.springframework.web-3.2.2.RELEASE.jar,
  lib/cdmlib-persistence-3.3.8-SNAPSHOT.jar,
  lib/dbunit-2.4.9.jar,
- lib/opencsv-2.4.jar
+ lib/opencsv-2.4.jar,
+ lib/dom4j-1.6.jar,
+ lib/cdmlib-commons-3.4.0-SNAPSHOT.jar,
+ lib/cdmlib-ext-3.4.0-SNAPSHOT.jar,
+ lib/cdmlib-model-3.4.0-SNAPSHOT.jar,
+ lib/cdmlib-services-3.4.0-SNAPSHOT.jar,
+ lib/usertype.jodatime-2.0.1.jar,
+ lib/usertype.spi-2.0.1.jar,
+ lib/cdmlib-persistence-3.4.0-SNAPSHOT.jar,
+ lib/wsdl4j-1.6.3.jar,
+ lib/validation-api-1.1.0.Final.jar,
+ lib/org.springframework.context.support-3.2.2.RELEASE.jar,
+ lib/org.springframework.test-3.2.2.RELEASE.jar
 Import-Package: org.osgi.framework
 Require-Bundle: org.eclipse.osgi
 
index 5eaf7be3f4c8ff98ccdab97b08e8ea8e57c1fb01..be9b4390e74b11f33810b4f2c99bb900e629da0b 100644 (file)
@@ -2,10 +2,6 @@ output.. = target/classes/
 bin.includes = META-INF/,\
                lib/aspectjrt-1.7.1.jar,\
                lib/c3p0-0.9.2.jar,\
-               lib/cdmlib-commons-3.3.8-SNAPSHOT.jar,\
-               lib/cdmlib-ext-3.3.8-SNAPSHOT.jar,\
-               lib/cdmlib-model-3.3.8-SNAPSHOT.jar,\
-               lib/cdmlib-services-3.3.8-SNAPSHOT.jar,\
                lib/ehcache-core-2.4.3.jar,\
                lib/hamcrest-core-1.3.jar,\
                lib/jboss-logging-3.1.3.GA.jar,\
@@ -55,5 +51,20 @@ bin.includes = META-INF/,\
                lib/dbunit-2.4.9.jar,\
                lib/opencsv-2.4.jar,\
                src/test/resources/h2/,\
-               src/test/resources/log4j.properties
+               src/test/resources/log4j.properties,\
+               lib/dom4j-1.6.jar,\
+               lib/cdmlib-commons-3.4.0-SNAPSHOT.jar,\
+               lib/cdmlib-ext-3.4.0-SNAPSHOT.jar,\
+               lib/cdmlib-model-3.4.0-SNAPSHOT.jar,\
+               lib/cdmlib-services-3.4.0-SNAPSHOT.jar,\
+               lib/usertype.jodatime-2.0.1.jar,\
+               lib/usertype.spi-2.0.1.jar,\
+               lib/cdmlib-persistence-3.4.0-SNAPSHOT.jar,\
+               lib/wsdl4j-1.6.3.jar,\
+               lib/validation-api-1.1.0.Final.jar,\
+               src/main/resources/eu/etaxonomy/cdmlib/,\
+               lib/org.springframework.context.support-3.2.2.RELEASE.jar,\
+               src/main/resources/cdmlib-ehcache.xml,\
+               src/test/resources/cdmlib-ehcache.xml,\
+               lib/org.springframework.test-3.2.2.RELEASE.jar
 bin.excludes = src/test/
index 6df07fe2672c6409cc78a89a54c813d40c5c45c5..80d66e075eba820e1bc1d5c15b879db722c2171c 100644 (file)
 <?xml version="1.0" encoding="UTF-8"?>
 <project>
 
-  <parent>
-    <groupId>eu.etaxonomy</groupId>
-    <artifactId>taxeditor-parent</artifactId>
-    <version>3.3.8-SNAPSHOT</version>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <artifactId>eu.etaxonomy.taxeditor.remoting</artifactId>
-  <packaging>eclipse-plugin</packaging>
-  <name>Remoting Bundle</name>
-  <description>Remoting Plugin Taxonomic Editor</description>
+       <parent>
+               <groupId>eu.etaxonomy</groupId>
+               <artifactId>taxeditor-parent</artifactId>
+               <version>3.4.0-SNAPSHOT</version>
+       </parent>
+       <modelVersion>4.0.0</modelVersion>
+       <artifactId>eu.etaxonomy.taxeditor.remoting</artifactId>
+       <packaging>eclipse-plugin</packaging>
+       <name>Remoting Bundle</name>
+       <description>Remoting Plugin Taxonomic Editor</description>
 
-  <build>
-    <pluginManagement>
-      <plugins>
-        <plugin>
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-surefire-plugin</artifactId>
-          <version>2.7</version>
-        </plugin>
-      </plugins>
-    </pluginManagement>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-dependency-plugin</artifactId>
-        <version>2.4</version>
-        <executions>
-          <execution>
-            <id>copy-dependencies</id>
-            <phase>validate</phase>
-            <goals>
-              <goal>copy-dependencies</goal>
-            </goals>
-            <configuration>
-              <excludeArtifactIds>
-                cdmlib-remote-webapp
-              </excludeArtifactIds>
-              <includeArtifactIds>
-                cdmlib-services,cdmlib-commons,cdmlib-persistence,cdmlib-ext,cdmlib-model
-              </includeArtifactIds>
-              <outputDirectory>${basedir}/lib</outputDirectory>
-              <overWriteReleases>true</overWriteReleases>
-              <overWriteSnapshots>true</overWriteSnapshots>
-              <excludeTransitive>true</excludeTransitive>
-            </configuration>
-          </execution>
-          <execution>
-            <id>copy-dependency-war</id>
-            <phase>validate</phase>
-            <goals>
-              <goal>copy-dependencies</goal>
-            </goals>
-            <configuration>
-              <includeArtifactIds>
-                cdmlib-remote-webapp
-              </includeArtifactIds>
-              <outputDirectory>
-                ${basedir}/src/main/resources/etc/jetty
-              </outputDirectory>
-              <overWriteReleases>true</overWriteReleases>
-              <overWriteSnapshots>true</overWriteSnapshots>
-              <excludeTransitive>true</excludeTransitive>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-antrun-plugin</artifactId>
-        <version>1.7</version>
-        <executions>
-          <execution>
-            <id>update-snapshot-jar-names</id>
-            <phase>validate</phase>
-            <goals>
-              <goal>run</goal>
-            </goals>
-            <configuration>
-              <target>
-                <echo>Anonymizing war</echo>
-                <move todir="./src/main/resources/etc/jetty">
-                  <fileset dir="./src/main/resources/etc/jetty" />
-                  <mapper type="regexp"
-                    from="(^cdmlib\-.*)\-[0-9]\.[0-9]\.[0-9]\-SNAPSHOT(\.war)"
-                    to="\1\2" />
-                </move>
-                <move todir="./src/main/resources/etc/jetty">
-                  <fileset dir="./src/main/resources/etc/jetty" />
-                  <mapper type="regexp"
-                    from="(^cdmlib\-.*)\-[0-9]\.[0-9]\.[0-9]\-[0-9.-]+(\.war)"
-                    to="\1\2" />
-                </move>
-                <echo>Update cdmlib jars to SNAPSHOT when build with
-                  timestamp
-                </echo>
-                <move todir="./lib">
-                  <fileset dir="./lib" />
-                  <mapper type="regexp"
-                    from="(^cdmlib\-.*\-[0-9]\.[0-9]\.[0-9]\-)[0-9.-]+(\.jar)"
-                    to="\1SNAPSHOT\2" />
-                </move>
-                <move todir="./lib">
-                  <fileset dir="./lib" />
-                  <mapper type="regexp"
-                    from="(^cdmlib\-.*\-[0-9]\.[0-9]\.[0-9]\-)[0-9.-]+(\-sources\.jar)"
-                    to="\1SNAPSHOT\2" />
-                </move>
-              </target>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-  <profiles>
-    <profile>
-      <id>cleanCdmlibJars</id>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-clean-plugin</artifactId>
-            <version>2.3</version>
-            <configuration>
-              <filesets>
-                <fileset>
-                  <directory>${basedir}/lib</directory>
-                  <includes>
-                    <include>cdmlib-*</include>
-                  </includes>
-                  <followSymlinks>false</followSymlinks>
-                </fileset>
-              </filesets>
-            </configuration>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>cleanAllJars</id>
-      <build>
-        <plugins>
-          <plugin>
-            <artifactId>maven-clean-plugin</artifactId>
-            <version>2.3</version>
-            <configuration>
-              <filesets>
-                <fileset>
-                  <directory>${basedir}/lib</directory>
-                  <includes>
-                    <include>*</include>
-                  </includes>
-                  <followSymlinks>false</followSymlinks>
-                </fileset>
-              </filesets>
-            </configuration>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-    <profile>
-      <id>copyAllJars</id>
-      <build>
-        <plugins>
-          <plugin>
-            <groupId>org.apache.maven.plugins</groupId>
-            <artifactId>maven-dependency-plugin</artifactId>
-            <version>2.4</version>
-            <executions>
-              <execution>
-                <id>copy-all-dependencies</id>
-                <phase>validate</phase>
-                <goals>
-                  <goal>copy-dependencies</goal>
-                </goals>
-                <configuration>
-                  <excludeArtifactIds>
-                    cdmlib-remote-webapp
-                  </excludeArtifactIds>
-                  <outputDirectory>${basedir}/lib</outputDirectory>
-                  <overWriteReleases>true</overWriteReleases>
-                  <overWriteSnapshots>true</overWriteSnapshots>
-                  <excludeTransitive>true</excludeTransitive>
-                </configuration>
-              </execution>
-            </executions>
-          </plugin>
-        </plugins>
-      </build>
-    </profile>
-  </profiles>
-  <repositories>
-    <repository>
-      <id>SpringSource Enterprise Bundle Repository - External Bundle
-        Milestones</id>
-      <url>http://repository.springsource.com/maven/bundles/milestone
-      </url>
-    </repository>
-    <repository>
-      <id>SpringSource Enterprise Bundle Repository - SpringSource
-        Bundle Releases</id>
-      <url>http://repository.springsource.com/maven/bundles/release
-      </url>
-    </repository>
-    <repository>
-      <id>SpringSource Enterprise Bundle Repository - External Bundle
-        Releases</id>
-      <url>http://repository.springsource.com/maven/bundles/external
-      </url>
-    </repository>
-  </repositories>
-  <dependencies>
-    <dependency>
-      <groupId>eu.etaxonomy</groupId>
-      <artifactId>cdmlib-remote-webapp</artifactId>
-      <version>${cdmlib.version}</version>
-      <type>war</type>
-    </dependency>
-    <dependency>
-      <groupId>eu.etaxonomy</groupId>
-      <artifactId>cdmlib-services</artifactId>
-      <version>${cdmlib.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>eu.etaxonomy</groupId>
-      <artifactId>cdmlib-commons</artifactId>
-      <version>${cdmlib.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>eu.etaxonomy</groupId>
-      <artifactId>cdmlib-persistence</artifactId>
-      <version>${cdmlib.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>eu.etaxonomy</groupId>
-      <artifactId>cdmlib-ext</artifactId>
-      <version>${cdmlib.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>eu.etaxonomy</groupId>
-      <artifactId>cdmlib-model</artifactId>
-      <version>${cdmlib.version}</version>
-    </dependency>
+       <build>
+               <pluginManagement>
+                       <plugins>
+                               <plugin>
+                                       <groupId>org.apache.maven.plugins</groupId>
+                                       <artifactId>maven-surefire-plugin</artifactId>
+                                       <version>2.7</version>
+                               </plugin>
+                       </plugins>
+               </pluginManagement>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-dependency-plugin</artifactId>
+                               <version>2.4</version>
+                               <executions>
+                                       <execution>
+                                               <id>copy-dependencies</id>
+                                               <phase>validate</phase>
+                                               <goals>
+                                                       <goal>copy-dependencies</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <excludeArtifactIds>
+                                                               cdmlib-remote-webapp
+                                                       </excludeArtifactIds>
+                                                       <includeArtifactIds>
+                                                               cdmlib-services,cdmlib-commons,cdmlib-persistence,cdmlib-ext,cdmlib-model
+                                                       </includeArtifactIds>
+                                                       <outputDirectory>${basedir}/lib</outputDirectory>
+                                                       <overWriteReleases>true</overWriteReleases>
+                                                       <overWriteSnapshots>true</overWriteSnapshots>
+                                                       <excludeTransitive>true</excludeTransitive>
+                                               </configuration>
+                                       </execution>
+                                       <execution>
+                                               <id>copy-dependency-war</id>
+                                               <phase>validate</phase>
+                                               <goals>
+                                                       <goal>copy-dependencies</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <includeArtifactIds>
+                                                               cdmlib-remote-webapp
+                                                       </includeArtifactIds>
+                                                       <outputDirectory>
+                                                               ${basedir}/src/main/resources/etc/jetty
+                                                       </outputDirectory>
+                                                       <overWriteReleases>true</overWriteReleases>
+                                                       <overWriteSnapshots>true</overWriteSnapshots>
+                                                       <excludeTransitive>true</excludeTransitive>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-antrun-plugin</artifactId>
+                               <version>1.7</version>
+                               <executions>
+                                       <execution>
+                                               <id>update-snapshot-jar-names</id>
+                                               <phase>validate</phase>
+                                               <goals>
+                                                       <goal>run</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <target>
+                                                               <echo>Anonymizing war</echo>
+                                                               <move todir="./src/main/resources/etc/jetty">
+                                                                       <fileset dir="./src/main/resources/etc/jetty" />
+                                                                       <mapper type="regexp"
+                                                                               from="(^cdmlib\-.*)\-[0-9]\.[0-9]\.[0-9]\-SNAPSHOT(\.war)" to="\1\2" />
+                                                               </move>
+                                                               <move todir="./src/main/resources/etc/jetty">
+                                                                       <fileset dir="./src/main/resources/etc/jetty" />
+                                                                       <mapper type="regexp"
+                                                                               from="(^cdmlib\-.*)\-[0-9]\.[0-9]\.[0-9]\-[0-9.-]+(\.war)" to="\1\2" />
+                                                               </move>
+                                                               <echo>Update cdmlib jars to SNAPSHOT when build with
+                                                                       timestamp
+                                                               </echo>
+                                                               <move todir="./lib">
+                                                                       <fileset dir="./lib" />
+                                                                       <mapper type="regexp"
+                                                                               from="(^cdmlib\-.*\-[0-9]\.[0-9]\.[0-9]\-)[0-9.-]+(\.jar)" to="\1SNAPSHOT\2" />
+                                                               </move>
+                                                               <move todir="./lib">
+                                                                       <fileset dir="./lib" />
+                                                                       <mapper type="regexp"
+                                                                               from="(^cdmlib\-.*\-[0-9]\.[0-9]\.[0-9]\-)[0-9.-]+(\-sources\.jar)"
+                                                                               to="\1SNAPSHOT\2" />
+                                                               </move>
+                                                       </target>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
+               </plugins>
+       </build>
+       <profiles>
+               <profile>
+                       <id>cleanCdmlibJars</id>
+                       <build>
+                               <plugins>
+                                       <plugin>
+                                               <artifactId>maven-clean-plugin</artifactId>
+                                               <version>2.3</version>
+                                               <configuration>
+                                                       <filesets>
+                                                               <fileset>
+                                                                       <directory>${basedir}/lib</directory>
+                                                                       <includes>
+                                                                               <include>cdmlib-*</include>
+                                                                       </includes>
+                                                                       <followSymlinks>false</followSymlinks>
+                                                               </fileset>
+                                                       </filesets>
+                                               </configuration>
+                                       </plugin>
+                               </plugins>
+                       </build>
+               </profile>
+               <profile>
+                       <id>cleanAllJars</id>
+                       <build>
+                               <plugins>
+                                       <plugin>
+                                               <artifactId>maven-clean-plugin</artifactId>
+                                               <version>2.3</version>
+                                               <configuration>
+                                                       <filesets>
+                                                               <fileset>
+                                                                       <directory>${basedir}/lib</directory>
+                                                                       <includes>
+                                                                               <include>*</include>
+                                                                       </includes>
+                                                                       <followSymlinks>false</followSymlinks>
+                                                               </fileset>
+                                                       </filesets>
+                                               </configuration>
+                                       </plugin>
+                               </plugins>
+                       </build>
+               </profile>
+               <profile>
+                       <id>copyAllJars</id>
+                       <build>
+                               <plugins>
+                                       <plugin>
+                                               <groupId>org.apache.maven.plugins</groupId>
+                                               <artifactId>maven-dependency-plugin</artifactId>
+                                               <version>2.4</version>
+                                               <executions>
+                                                       <execution>
+                                                               <id>copy-all-dependencies</id>
+                                                               <phase>validate</phase>
+                                                               <goals>
+                                                                       <goal>copy-dependencies</goal>
+                                                               </goals>
+                                                               <configuration>
+                                                                       <excludeArtifactIds>
+                                                                               cdmlib-remote-webapp
+                                                                       </excludeArtifactIds>
+                                                                       <outputDirectory>${basedir}/lib</outputDirectory>
+                                                                       <overWriteReleases>true</overWriteReleases>
+                                                                       <overWriteSnapshots>true</overWriteSnapshots>
+                                                                       <excludeTransitive>true</excludeTransitive>
+                                                               </configuration>
+                                                       </execution>
+                                               </executions>
+                                       </plugin>
+                               </plugins>
+                       </build>
+               </profile>
+       </profiles>
+       <repositories>
+               <repository>
+                       <id>SpringSource Enterprise Bundle Repository - External Bundle
+                               Milestones
+                       </id>
+                       <url>http://repository.springsource.com/maven/bundles/milestone
+                       </url>
+               </repository>
+               <repository>
+                       <id>SpringSource Enterprise Bundle Repository - SpringSource
+                               Bundle
+                               Releases
+                       </id>
+                       <url>http://repository.springsource.com/maven/bundles/release
+                       </url>
+               </repository>
+               <repository>
+                       <id>SpringSource Enterprise Bundle Repository - External Bundle
+                               Releases
+                       </id>
+                       <url>http://repository.springsource.com/maven/bundles/external
+                       </url>
+               </repository>
+       </repositories>
+       <dependencies>
+               <dependency>
+                       <groupId>eu.etaxonomy</groupId>
+                       <artifactId>cdmlib-remote-webapp</artifactId>
+                       <version>${cdmlib.version}</version>
+                       <type>war</type>
+               </dependency>
+               <dependency>
+                       <groupId>eu.etaxonomy</groupId>
+                       <artifactId>cdmlib-services</artifactId>
+                       <version>${cdmlib.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>eu.etaxonomy</groupId>
+                       <artifactId>cdmlib-commons</artifactId>
+                       <version>${cdmlib.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>eu.etaxonomy</groupId>
+                       <artifactId>cdmlib-persistence</artifactId>
+                       <version>${cdmlib.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>eu.etaxonomy</groupId>
+                       <artifactId>cdmlib-ext</artifactId>
+                       <version>${cdmlib.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>eu.etaxonomy</groupId>
+                       <artifactId>cdmlib-model</artifactId>
+                       <version>${cdmlib.version}</version>
+               </dependency>
 
-    <dependency>
-      <groupId>org.unitils</groupId>
-      <artifactId>unitils-core</artifactId>
-      <version>3.4.2</version>
-    </dependency>
-    <!-- <dependency> -->
-    <!-- <groupId>org.eclipse.jetty</groupId> -->
-    <!-- <artifactId>jetty-server</artifactId> -->
-    <!-- <version>9.1.3.v20140225</version> -->
-    <!-- </dependency> -->
-    <!-- <dependency> -->
-    <!-- <groupId>org.eclipse.jetty</groupId> -->
-    <!-- <artifactId>jetty-util</artifactId> -->
-    <!-- <version>9.1.3.v20140225</version> -->
-    <!-- </dependency> -->
-    <!-- <dependency> -->
-    <!-- <groupId>org.eclipse.jetty</groupId> -->
-    <!-- <artifactId>jetty-xml</artifactId> -->
-    <!-- <version>9.1.3.v20140225</version> -->
-    <!-- </dependency> -->
-    <!-- <dependency> -->
-    <!-- <groupId>org.eclipse.jetty</groupId> -->
-    <!-- <artifactId>jetty-servlet</artifactId> -->
-    <!-- <version>9.1.3.v20140225</version> -->
-    <!-- </dependency> -->
-    <!-- <dependency> -->
-    <!-- <groupId>org.eclipse.jetty</groupId> -->
-    <!-- <artifactId>jetty-webapp</artifactId> -->
-    <!-- <version>9.1.3.v20140225</version> -->
-    <!-- </dependency> -->
-    <!-- <dependency> -->
-    <!-- <groupId>org.eclipse.jetty</groupId> -->
-    <!-- <artifactId>jetty-security</artifactId> -->
-    <!-- <version>9.1.3.v20140225</version> -->
-    <!-- </dependency> -->
-    <!-- <dependency> -->
-    <!-- <groupId>org.eclipse.jetty</groupId> -->
-    <!-- <artifactId>jetty-http</artifactId> -->
-    <!-- <version>${jetty.version}</version> -->
-    <!-- </dependency> -->
-    <!-- <dependency> -->
-    <!-- <groupId>org.eclipse.jetty</groupId> -->
-    <!-- <artifactId>jetty-io</artifactId> -->
-    <!-- <version>${jetty.version}</version> -->
-    <!-- </dependency> -->
-    <!-- <dependency> -->
-    <!-- <groupId>javax.servlet</groupId> -->
-    <!-- <artifactId>javax.servlet-api</artifactId> -->
-    <!-- <version>3.1.0</version> -->
-    <!-- </dependency> -->
+               <dependency>
+                       <groupId>org.unitils</groupId>
+                       <artifactId>unitils-core</artifactId>
+                       <version>3.4.2</version>
+               </dependency>
+               <!-- <dependency> -->
+               <!-- <groupId>org.eclipse.jetty</groupId> -->
+               <!-- <artifactId>jetty-server</artifactId> -->
+               <!-- <version>9.1.3.v20140225</version> -->
+               <!-- </dependency> -->
+               <!-- <dependency> -->
+               <!-- <groupId>org.eclipse.jetty</groupId> -->
+               <!-- <artifactId>jetty-util</artifactId> -->
+               <!-- <version>9.1.3.v20140225</version> -->
+               <!-- </dependency> -->
+               <!-- <dependency> -->
+               <!-- <groupId>org.eclipse.jetty</groupId> -->
+               <!-- <artifactId>jetty-xml</artifactId> -->
+               <!-- <version>9.1.3.v20140225</version> -->
+               <!-- </dependency> -->
+               <!-- <dependency> -->
+               <!-- <groupId>org.eclipse.jetty</groupId> -->
+               <!-- <artifactId>jetty-servlet</artifactId> -->
+               <!-- <version>9.1.3.v20140225</version> -->
+               <!-- </dependency> -->
+               <!-- <dependency> -->
+               <!-- <groupId>org.eclipse.jetty</groupId> -->
+               <!-- <artifactId>jetty-webapp</artifactId> -->
+               <!-- <version>9.1.3.v20140225</version> -->
+               <!-- </dependency> -->
+               <!-- <dependency> -->
+               <!-- <groupId>org.eclipse.jetty</groupId> -->
+               <!-- <artifactId>jetty-security</artifactId> -->
+               <!-- <version>9.1.3.v20140225</version> -->
+               <!-- </dependency> -->
+               <!-- <dependency> -->
+               <!-- <groupId>org.eclipse.jetty</groupId> -->
+               <!-- <artifactId>jetty-http</artifactId> -->
+               <!-- <version>${jetty.version}</version> -->
+               <!-- </dependency> -->
+               <!-- <dependency> -->
+               <!-- <groupId>org.eclipse.jetty</groupId> -->
+               <!-- <artifactId>jetty-io</artifactId> -->
+               <!-- <version>${jetty.version}</version> -->
+               <!-- </dependency> -->
+               <!-- <dependency> -->
+               <!-- <groupId>javax.servlet</groupId> -->
+               <!-- <artifactId>javax.servlet-api</artifactId> -->
+               <!-- <version>3.1.0</version> -->
+               <!-- </dependency> -->
 
-    <!-- <dependency> -->
-    <!-- <groupId>javax.servlet</groupId> -->
-    <!-- <artifactId>jsp-api</artifactId> -->
-    <!-- <version>2.0</version> -->
-    <!-- </dependency> -->
+               <!-- <dependency> -->
+               <!-- <groupId>javax.servlet</groupId> -->
+               <!-- <artifactId>jsp-api</artifactId> -->
+               <!-- <version>2.0</version> -->
+               <!-- </dependency> -->
 
-    <dependency>
-      <groupId>net.sf.ehcache</groupId>
-      <artifactId>ehcache-core</artifactId>
-      <version>2.4.3</version>
-    </dependency>
-    <dependency>
-      <groupId>org.hibernate</groupId>
-      <artifactId>hibernate-core</artifactId>
-      <version>4.1.10.Final</version>
-    </dependency>
-    <dependency>
-      <groupId>org.hibernate.common</groupId>
-      <artifactId>hibernate-commons-annotations</artifactId>
-      <version>4.0.1.Final</version>
-    </dependency>
-    <dependency>
-      <groupId>org.hibernate</groupId>
-      <artifactId>hibernate-search-engine</artifactId>
-      <version>4.2.0.Final</version>
-    </dependency>
-    <dependency>
-      <groupId>org.hibernate.javax.persistence</groupId>
-      <artifactId>hibernate-jpa-2.0-api</artifactId>
-      <version>1.0.1.Final</version>
-    </dependency>
-    <dependency>
-      <groupId>org.hibernate</groupId>
-      <artifactId>hibernate-envers</artifactId>
-      <version>4.1.10.Final</version>
-    </dependency>
-    <dependency>
-      <groupId>org.hibernate</groupId>
-      <artifactId>hibernate-entitymanager</artifactId>
-      <version>4.1.10.Final</version>
-    </dependency>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.11</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-      <version>1.2.17</version>
-    </dependency>
-    <dependency>
-      <groupId>org.jdom</groupId>
-      <artifactId>jdom</artifactId>
-      <version>1.1.3</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>org.springframework.context</artifactId>
-      <version>3.2.2.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>org.springframework.aspects</artifactId>
-      <version>3.2.2.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>org.springframework.beans</artifactId>
-      <version>3.2.2.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>org.springframework.transaction</artifactId>
-      <version>3.2.2.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>org.springframework.web</artifactId>
-      <version>3.2.2.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>org.springframework.core</artifactId>
-      <version>3.2.2.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>org.springframework.aop</artifactId>
-      <version>3.2.2.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>org.springframework.expression</artifactId>
-      <version>3.2.2.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>org.springframework.orm</artifactId>
-      <version>3.2.2.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>org.springframework.jdbc</artifactId>
-      <version>3.2.2.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework.security</groupId>
-      <artifactId>spring-security-core</artifactId>
-      <version>3.1.3.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework.security</groupId>
-      <artifactId>spring-security-config</artifactId>
-      <version>3.1.3.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework.security</groupId>
-      <artifactId>spring-security-remoting</artifactId>
-      <version>3.1.3.RELEASE</version>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.logging</groupId>
-      <artifactId>jboss-logging</artifactId>
-      <version>3.1.3.GA</version>
-    </dependency>
-    <dependency>
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-core</artifactId>
-      <version>1.3</version>
-    </dependency>
-    <dependency>
-      <groupId>com.mchange</groupId>
-      <artifactId>c3p0</artifactId>
-      <version>0.9.2</version>
-    </dependency>
-    <dependency>
-      <groupId>org.jboss.spec.javax.transaction</groupId>
-      <artifactId>jboss-transaction-api_1.1_spec</artifactId>
-      <version>1.0.0.Final</version>
-    </dependency>
-    <dependency>
-      <groupId>org.aspectj</groupId>
-      <artifactId>aspectjrt</artifactId>
-      <version>1.7.1</version>
-    </dependency>
-    <dependency>
-      <groupId>commons-logging</groupId>
-      <artifactId>commons-logging</artifactId>
-      <version>1.1.1</version>
-    </dependency>
-    <dependency>
-      <groupId>commons-lang</groupId>
-      <artifactId>commons-lang</artifactId>
-      <version>2.6</version>
-    </dependency>
-    <dependency>
-      <groupId>aopalliance</groupId>
-      <artifactId>aopalliance</artifactId>
-      <version>1.0</version>
-    </dependency>
-    <dependency>
-      <groupId>joda-time</groupId>
-      <artifactId>joda-time</artifactId>
-      <version>2.1</version>
-    </dependency>
-    <dependency>
-      <groupId>com.ibm.lsid</groupId>
-      <artifactId>lsid-client</artifactId>
-      <version>1.1.2</version>
-    </dependency>
-    <dependency>
-      <groupId>com.ibm.lsid</groupId>
-      <artifactId>lsid-server</artifactId>
-      <version>1.1.2</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.lucene</groupId>
-      <artifactId>lucene-core</artifactId>
-      <version>3.6.2</version>
-    </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
-      <version>1.7.2</version>
-    </dependency>
-    <dependency>
-      <groupId>org.javassist</groupId>
-      <artifactId>javassist</artifactId>
-      <version>3.17.1-GA</version>
-    </dependency>
-    <dependency>
-      <groupId>au.com.bytecode</groupId>
-      <artifactId>opencsv</artifactId>
-      <version>2.4</version>
-    </dependency>
+               <dependency>
+                       <groupId>net.sf.ehcache</groupId>
+                       <artifactId>ehcache-core</artifactId>
+                       <version>2.4.3</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.hibernate</groupId>
+                       <artifactId>hibernate-core</artifactId>
+                       <version>4.1.10.Final</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.hibernate.common</groupId>
+                       <artifactId>hibernate-commons-annotations</artifactId>
+                       <version>4.0.1.Final</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.hibernate</groupId>
+                       <artifactId>hibernate-search-engine</artifactId>
+                       <version>4.2.0.Final</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.hibernate.javax.persistence</groupId>
+                       <artifactId>hibernate-jpa-2.0-api</artifactId>
+                       <version>1.0.1.Final</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.hibernate</groupId>
+                       <artifactId>hibernate-envers</artifactId>
+                       <version>4.1.10.Final</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.hibernate</groupId>
+                       <artifactId>hibernate-entitymanager</artifactId>
+                       <version>4.1.10.Final</version>
+               </dependency>
+               <dependency>
+                       <groupId>dom4j</groupId>
+                       <artifactId>dom4j</artifactId>
+                       <version>1.6</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.jadira.usertype</groupId>
+                       <artifactId>usertype.jodatime</artifactId>
+                       <version>2.0.1</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.jadira.usertype</groupId>
+                       <artifactId>usertype.spi</artifactId>
+                       <version>2.0.1</version>
+               </dependency>
 
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <version>4.11</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>log4j</groupId>
+                       <artifactId>log4j</artifactId>
+                       <version>1.2.17</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.jdom</groupId>
+                       <artifactId>jdom</artifactId>
+                       <version>1.1.3</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.context</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.context.support</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.aspects</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.test</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.beans</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.transaction</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.web</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.core</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.aop</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.expression</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.orm</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework</groupId>
+                       <artifactId>org.springframework.jdbc</artifactId>
+                       <version>3.2.2.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework.security</groupId>
+                       <artifactId>spring-security-core</artifactId>
+                       <version>3.1.3.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework.security</groupId>
+                       <artifactId>spring-security-config</artifactId>
+                       <version>3.1.3.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.springframework.security</groupId>
+                       <artifactId>spring-security-remoting</artifactId>
+                       <version>3.1.3.RELEASE</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.jboss.logging</groupId>
+                       <artifactId>jboss-logging</artifactId>
+                       <version>3.1.3.GA</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.hamcrest</groupId>
+                       <artifactId>hamcrest-core</artifactId>
+                       <version>1.3</version>
+               </dependency>
+               <dependency>
+                       <groupId>com.mchange</groupId>
+                       <artifactId>c3p0</artifactId>
+                       <version>0.9.2</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.jboss.spec.javax.transaction</groupId>
+                       <artifactId>jboss-transaction-api_1.1_spec</artifactId>
+                       <version>1.0.0.Final</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.aspectj</groupId>
+                       <artifactId>aspectjrt</artifactId>
+                       <version>1.7.1</version>
+               </dependency>
+               <dependency>
+                       <groupId>commons-logging</groupId>
+                       <artifactId>commons-logging</artifactId>
+                       <version>1.1.1</version>
+               </dependency>
+               <dependency>
+                       <groupId>commons-lang</groupId>
+                       <artifactId>commons-lang</artifactId>
+                       <version>2.6</version>
+               </dependency>
+               <dependency>
+                       <groupId>aopalliance</groupId>
+                       <artifactId>aopalliance</artifactId>
+                       <version>1.0</version>
+               </dependency>
+               <dependency>
+                       <groupId>joda-time</groupId>
+                       <artifactId>joda-time</artifactId>
+                       <version>2.1</version>
+               </dependency>
+               <dependency>
+                       <groupId>com.ibm.lsid</groupId>
+                       <artifactId>lsid-client</artifactId>
+                       <version>1.1.2</version>
+               </dependency>
+               <dependency>
+                       <groupId>com.ibm.lsid</groupId>
+                       <artifactId>lsid-server</artifactId>
+                       <version>1.1.2</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.apache.lucene</groupId>
+                       <artifactId>lucene-core</artifactId>
+                       <version>3.6.2</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+                       <version>1.7.2</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.javassist</groupId>
+                       <artifactId>javassist</artifactId>
+                       <version>3.17.1-GA</version>
+               </dependency>
+               <dependency>
+                       <groupId>au.com.bytecode</groupId>
+                       <artifactId>opencsv</artifactId>
+                       <version>2.4</version>
+               </dependency>
 
-    <!-- For Unit Tests -->
-    <dependency>
-      <groupId>org.unitils</groupId>
-      <artifactId>unitils-spring</artifactId>
-      <version>3.4.2</version>
-    </dependency>
-    <dependency>
-      <groupId>org.unitils</groupId>
-      <artifactId>unitils-database</artifactId>
-      <version>3.4.2</version>
-    </dependency>
-    <dependency>
-      <groupId>commons-dbcp</groupId>
-      <artifactId>commons-dbcp</artifactId>
-      <version>1.4</version>
-    </dependency>
-    <dependency>
-      <groupId>commons-pool</groupId>
-      <artifactId>commons-pool</artifactId>
-      <version>1.5.4</version>
-    </dependency>
-    <dependency>
-      <groupId>org.unitils</groupId>
-      <artifactId>unitils-dbmaintainer</artifactId>
-      <version>3.4.2</version>
-    </dependency>
-    <dependency>
-      <groupId>com.h2database</groupId>
-      <artifactId>h2</artifactId>
-      <version>1.4.181</version>
-    </dependency>
-    <dependency>
-      <groupId>org.unitils</groupId>
-      <artifactId>unitils-dbunit</artifactId>
-      <version>3.4.2</version>
-    </dependency>
-    <dependency>
-      <groupId>org.dbunit</groupId>
-      <artifactId>dbunit</artifactId>
-      <version>2.4.9</version>
-    </dependency>
-  </dependencies>
+
+               <!-- For Unit Tests Start -->
+               <dependency>
+                       <groupId>org.unitils</groupId>
+                       <artifactId>unitils-spring</artifactId>
+                       <version>3.4.2</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.unitils</groupId>
+                       <artifactId>unitils-database</artifactId>
+                       <version>3.4.2</version>
+               </dependency>
+               <dependency>
+                       <groupId>commons-dbcp</groupId>
+                       <artifactId>commons-dbcp</artifactId>
+                       <version>1.4</version>
+               </dependency>
+               <dependency>
+                       <groupId>commons-pool</groupId>
+                       <artifactId>commons-pool</artifactId>
+                       <version>1.5.4</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.unitils</groupId>
+                       <artifactId>unitils-dbmaintainer</artifactId>
+                       <version>3.4.2</version>
+               </dependency>
+               <dependency>
+                       <groupId>com.h2database</groupId>
+                       <artifactId>h2</artifactId>
+                       <version>1.4.181</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.unitils</groupId>
+                       <artifactId>unitils-dbunit</artifactId>
+                       <version>3.4.2</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.dbunit</groupId>
+                       <artifactId>dbunit</artifactId>
+                       <version>2.4.9</version>
+               </dependency>
+               <!-- For Unit Tests End -->
+
+               <!-- For Hibernate Mapping Start -->
+               <dependency>
+                       <groupId>wsdl4j</groupId>
+                       <artifactId>wsdl4j</artifactId>
+                       <version>1.6.3</version>
+               </dependency>
+               <dependency>
+                       <groupId>javax.validation</groupId>
+                       <artifactId>validation-api</artifactId>
+                       <version>1.1.0.Final</version>
+               </dependency>
+               <!-- For Hibernate Mapping End -->
+       </dependencies>
 </project>
\ No newline at end of file
index ea88f5fe07eca8f2663d986ea467cb50d27e5b8d..0a10de1070395fb5b7663bece983b95574acea6e 100644 (file)
@@ -32,6 +32,7 @@ import eu.etaxonomy.cdm.api.service.ICommonService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.PersistentMultiLanguageText;
 import eu.etaxonomy.taxeditor.remoting.session.CdmEntitySessionManager;
+import eu.etaxonomy.taxeditor.remoting.CdmRemotingException;
 
 /**
  * @author cmathew
@@ -68,14 +69,8 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
     @Override
     public CdmBase find(Class<? extends CdmBase> clazz, int id) {
         if(cacheEnabled) {
-            CdmBase cdmEntity = cdmEntitySessionManager.getActiveCdmTransientEntityCacher().getFromCache(clazz, id);
-            if(cdmEntity != null) {
-                return cdmEntity;
-            } else {
-                cdmEntity = CdmBase.deproxy(commonService.find(clazz, id),clazz);
-                cdmEntitySessionManager.getActiveCdmTransientEntityCacher().put(cdmEntity);
-                return cdmEntity;
-            }
+            CdmBase cdmEntity = CdmBase.deproxy(commonService.find(clazz, id),clazz);
+            return cdmEntitySessionManager.getActiveCdmTransientEntityCacher().load(cdmEntity, true);
         } else {
             return CdmBase.deproxy(commonService.find(clazz, id),clazz);
         }
@@ -93,13 +88,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
     @Override
     public void updatePersistentCollection(CollectionField colf) {
        if(cacheEnabled) {
-               switch(colf.getType()) {
-               case MAP:
-                       cdmEntityCachingUtils.cachify((Map<Object,Object>)colf.getCollection());
-               case SET:
-               case LIST:
-               default:
-               }
+               cdmEntitySessionManager.getActiveCdmTransientEntityCacher().load(colf.getCollection(), true);
        }
     }
 
@@ -176,6 +165,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
             if(pc instanceof PersistentSortedMap) {
                 return new CollectionField(new TreeMap((Map)pc), CollectionType.MAP);
             }
+            throw new CdmRemotingException("Cannot get Collection field for type " + pc.getClass().getName());
         }
         return null;
     }
index b5a15241fd2639d30296db5683d6613d5042f48d..476522af11ff2b32493176ec800a19b3bd2f1118 100644 (file)
@@ -36,7 +36,7 @@ public class CdmEntityCacheKey {
                        return true;
                }
                CdmEntityCacheKey that = (CdmEntityCacheKey) obj;
-               if(this.persistenceClass.equals(that.getClass()) && this.persistenceId == that.persistenceId) {
+               if(this.persistenceClass.equals(that.persistenceClass) && this.persistenceId == that.persistenceId) {
                        return true;
                }
                
index 0dd85c5c2e081de8153f26cd2827302046d415fa..ae20c6a9533aa0503641bfa63b6539a4de178f68 100644 (file)
@@ -1,6 +1,9 @@
 package eu.etaxonomy.cdm.api.cache;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
@@ -19,7 +22,7 @@ public class CdmModelCacher {
 
        private static final Logger logger = Logger.getLogger(CdmModelCacher.class);
 
-       private List<CdmModelGetMethodFromClass> cmgmfcList = new ArrayList<CdmModelGetMethodFromClass>();
+       private List<CdmModelFieldPropertyFromClass> cmgmfcList = new ArrayList<CdmModelFieldPropertyFromClass>();
 
        public void cacheGetters() {
 
@@ -35,17 +38,19 @@ public class CdmModelCacher {
                        Class mappedClass = persistentClass.getMappedClass();
                        String mappedClassName = mappedClass.getName();
 
-                       CdmModelGetMethodFromClass cmgmfc = new CdmModelGetMethodFromClass(mappedClassName);
+                       CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName);
                        Iterator propertyIt = persistentClass.getPropertyIterator();       
 
                        logger.info("Adding class : " + mappedClassName + " to cache");
+                                               
                        while(propertyIt.hasNext())
                        {
                                Property property = (Property)propertyIt.next();
                                Getter getter = property.getGetter(mappedClass);              
-                               if(getter != null && getter.getMember() != null) {           
-                                       String getMethod = getMethodNameFromFieldName(getter.getMember().getName());
-                                       logger.info(" - getMethod : " + getMethod);
+                               if(getter != null && getter.getMember() != null) {         
+                                       Field field = (Field)getter.getMember();
+                                       String getMethod = getMethodNameFromFieldName(field.getName(), field.getType().getName());                                      
+                                       logger.info(" - getMethod : " + getMethod + " for type " + field.getType().getName());
                                        cmgmfc.addGetMethods(getMethod);
                                }
                        }
@@ -54,8 +59,89 @@ public class CdmModelCacher {
                }
                cache.flush();
        }
+       
+       public void cacheGetterFields() {
 
-       public List<CdmModelGetMethodFromClass> getCdmModelGetMethodFromClassList() {
+               Configuration configuration = new Configuration().configure("/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml");
+               configuration.buildMappings();
+               Iterator<PersistentClass> classMappingIterator =   configuration.getClassMappings();                      
+
+               Cache cache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
+               cache.removeAll();
+
+               while(classMappingIterator.hasNext()) {
+                       PersistentClass persistentClass = classMappingIterator.next();
+                       Class mappedClass = persistentClass.getMappedClass();
+                       String mappedClassName = mappedClass.getName();
+
+                       CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName);
+                       Iterator propertyIt = persistentClass.getPropertyIterator();       
+
+                       logger.info("Adding class : " + mappedClassName + " to cache");
+                                               
+                       while(propertyIt.hasNext())
+                       {
+                               Property property = (Property)propertyIt.next();
+                               Getter getter = property.getGetter(mappedClass);              
+                               if(getter != null && getter.getMember() != null) {         
+                                       Field field = (Field)getter.getMember();
+                                       //String getMethod = getMethodNameFromFieldName(field.getName(), field.getType().getName());                                    
+                                       logger.info(" - contains field '" + field.getName() + "' of type '" + field.getType().getName() + "'");
+                                       cmgmfc.addGetMethods(field.getName());
+                               }
+                       }
+                       cache.put(new Element(mappedClassName, cmgmfc));
+
+               }
+               cache.flush();
+       }
+       
+       public void checkGetterMethods() {
+
+               Configuration configuration = new Configuration().configure("/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml");
+               configuration.buildMappings();
+               Iterator<PersistentClass> classMappingIterator =   configuration.getClassMappings();                      
+
+               Cache cache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
+               cache.removeAll();
+
+               while(classMappingIterator.hasNext()) {
+                       PersistentClass persistentClass = classMappingIterator.next();
+                       Class mappedClass = persistentClass.getMappedClass();
+                       String mappedClassName = mappedClass.getName();
+                       
+                       Iterator propertyIt = persistentClass.getPropertyIterator();       
+                       
+                       Method[] methods = mappedClass.getMethods();
+
+                       while(propertyIt.hasNext())
+                       {
+                               Property property = (Property)propertyIt.next();
+                               Getter getter = property.getGetter(mappedClass);              
+                               if(getter != null && getter.getMember() != null) {         
+                                       Field field = (Field)getter.getMember();
+                                       String getMethod = getMethodNameFromFieldName(field.getName(), field.getType().getName());                                      
+                                       
+                                       boolean foundMethod = false;
+                                       for(Method method : methods) {
+                                               if(method.getName().equals(getMethod)) {
+                                                       foundMethod = true;
+                                                       break;
+                                               }
+                                       }
+                                       if(!foundMethod) {
+                                               logger.info("Inferred method " + getMethod + " does not exist in class " + mappedClassName);
+                                               //throw new CdmClientCacheException("Inferred method " + getMethod + " does not exist in class " + mappedClassName);
+                                       }
+                               }
+                       }
+                       
+
+               }
+               
+       }
+
+       public List<CdmModelFieldPropertyFromClass> getCdmModelGetMethodFromClassList() {
                cmgmfcList.clear();
                Configuration configuration = new Configuration().configure("/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml");
                configuration.buildMappings();
@@ -66,15 +152,16 @@ public class CdmModelCacher {
                        Class mappedClass = persistentClass.getMappedClass();
                        String mappedClassName = mappedClass.getName();
 
-                       CdmModelGetMethodFromClass cmgmfc = new CdmModelGetMethodFromClass(mappedClassName);
+                       CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName);
                        Iterator propertyIt = persistentClass.getPropertyIterator();       
 
                        while(propertyIt.hasNext())
                        {
                                Property property = (Property)propertyIt.next();
                                Getter getter = property.getGetter(mappedClass);              
-                               if(getter != null && getter.getMember() != null) {           
-                                       String getMethod = getMethodNameFromFieldName(getter.getMember().getName());                     
+                               if(getter != null && getter.getMember() != null) {      
+                                       Field field = (Field)getter.getMember();
+                                       String getMethod = getMethodNameFromFieldName(getter.getMember().getName(),field.getType().getName());                   
                                        cmgmfc.addGetMethods(getMethod);
                                }
                        }
@@ -84,9 +171,13 @@ public class CdmModelCacher {
 
        }
 
-       public static String getMethodNameFromFieldName(String fieldName) {
-               return "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
+       public static String getMethodNameFromFieldName(String fieldName, String type) {
+               String prefix = type != null && type.toLowerCase().endsWith("boolean") ? "is" : "get";          
+               String getMethod =  prefix + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
+               return getMethod;
        }
+       
+
 
 
 
similarity index 59%
rename from eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelGetMethodFromClass.java
rename to eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelFieldPropertyFromClass.java
index 9490fed3b2e4345d9c27b2732b77c57cc56979f5..37cb8128dcc0d1ab0efb46d5b1fd200bbae44f49 100644 (file)
@@ -4,15 +4,16 @@ import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
-public class CdmModelGetMethodFromClass implements Serializable {
+public class CdmModelFieldPropertyFromClass implements Serializable {
 
+       private static final long serialVersionUID = 5726395976531887526L;
        private String className;
        private String parentClassName;
        
-       private List<String> getMethods = new ArrayList<String>();
+       private List<String> fields = new ArrayList<String>();
        
        
-       public CdmModelGetMethodFromClass(String className) {
+       public CdmModelFieldPropertyFromClass(String className) {
                this.setClassName(className);
        }
        
@@ -24,16 +25,16 @@ public class CdmModelGetMethodFromClass implements Serializable {
                this.parentClassName = parentClassName;
        }
 
-       public List<String> getGetMethods() {
-               return getMethods;
+       public List<String> getFields() {
+               return fields;
        }
 
-       public void setGetMethods(List<String> getMethods) {
-               this.getMethods = getMethods;
+       public void setFields(List<String> fields) {
+               this.fields = fields;
        }
        
        public void addGetMethods(String getMethod) {
-               this.getMethods.add(getMethod);
+               this.fields.add(getMethod);
        }
 
        public String getClassName() {
index 664c2cf6065b6c204e71444d8c1638eb1bcd3839..2387c23275b36684f0468bdaa332786f9ae51837 100644 (file)
@@ -1,30 +1,50 @@
 // $Id$
 /**
-* Copyright (C) 2014 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2014 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
 package eu.etaxonomy.cdm.api.cache;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.UUID;
 
+import javassist.util.proxy.ProxyFactory;
+
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
 import net.sf.ehcache.config.CacheConfiguration;
 import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
 
 import org.apache.log4j.Logger;
+import org.hibernate.collection.spi.PersistentCollection;
+import org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.ReflectionUtils;
 
+import eu.etaxonomy.cdm.api.service.ICommonService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 
 /**
+ * 
+ * This cache guarantees that
+ *  - all objects put will be ancestors of CdmBase
+ *  - all CdmBase objects in the cache will be already de-proxied
+ *  - after any CdmBase object is put in the cache, 
+ *  all non-null / non-proxy CdmBase objects in the sub-graph 
+ *  will also be present in the cache.
+ *   
  * @author cmathew
  * @date 14 Oct 2014
  *
@@ -33,192 +53,405 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 public class CdmTransientEntityCacher extends CdmServiceCacher {
 
        private static final Logger logger = Logger.getLogger(CdmTransientEntityCacher.class);
-       
+
+       @Autowired
+       private CdmEntityCachingUtils cdmEntityCachingUtils;
+
     @Autowired
-    private CdmEntityCachingUtils cdmEntityCachingUtils;
+    private ICommonService commonService;
     
        private String cacheId;
-               
+
        private Cache cache; 
-       
+
        private Cache cdmlibModelCache;
+
+       private static boolean isRecursiveEnabled = true;
+
+
+       public CdmTransientEntityCacher(String cacheId) {
+               this.cacheId = cacheId;
+
+               cache = new Cache(getEntityCacheConfiguration(cacheId));                
+               getDefaultCacheManager().addCache(cache);
+
+               cdmlibModelCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
+
+       }
+
+       public CdmTransientEntityCacher(Object obj) {
+               this(obj.getClass().getName() +  String.valueOf(obj.hashCode()));
+       }
+
+       /**
+        * Returns the default cache configuration.
+        *
+        * @return
+        */
+       private CacheConfiguration getEntityCacheConfiguration(String cacheId) {
+               // For a better understanding on how to size caches, refer to
+               // http://ehcache.org/documentation/configuration/cache-size
+               return new CacheConfiguration(cacheId, 500)        
+               .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
+               .eternal(false)
+               // default ttl and tti set to 2 hours
+               .timeToLiveSeconds(60*60*2)
+               .timeToIdleSeconds(60*60*2);
+
+       }
+
+
+       /**
+        * Returns the cache corresponding to the cache id
+        *
+        * @param cacheId
+        * @return
+        */
+       private Cache getCache() {
+               return getDefaultCacheManager().getCache(cacheId);
+       }
+
+       public <T extends Object> T load(T obj, boolean recursive) {
+               if(obj instanceof CdmBase) {
+                       return load(obj, recursive);
+               } else if (obj instanceof Map) {
+                       return load(obj, recursive);
+               }
+               
+               return obj;
+       }
        
-       private static boolean isRecursiveEnabled;
+       @SuppressWarnings("unchecked")
+       private <T extends Object> T loadRecursive(T obj, Set<CdmBase> alreadyVisitedEntities) {
+               if(obj instanceof CdmBase) {
+                       return loadRecursive(obj, alreadyVisitedEntities);
+               } else if (obj instanceof Map) {
+                       return (T) load((Map<T,T>)obj, alreadyVisitedEntities);
+               }
+               logger.info("No caching yet for type " + obj.getClass().getName());
+               
+               return obj;
+       }
        
-    public CdmTransientEntityCacher(String cacheId) {
-       this.cacheId = cacheId;
-     // Create entity cache
-       cache = new Cache(getEntityCacheConfiguration(cacheId));                
-        getDefaultCacheManager().addCache(cache);
-        
-        cdmlibModelCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
-       
-    }
-    
-    public CdmTransientEntityCacher(Object obj) {
-       this(obj.getClass().getName() +  String.valueOf(obj.hashCode()));
-    }
-    
-    /**
-     * Returns the default cache configuration.
-     *
-     * @return
-     */
-    private CacheConfiguration getEntityCacheConfiguration(String cacheId) {
-        // For a better understanding on how to size caches, refer to
-        // http://ehcache.org/documentation/configuration/cache-size
-        return new CacheConfiguration(cacheId, 500)        
-        .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
-        .eternal(false)
-        // default ttl and tti set to 2 hours
-        .timeToLiveSeconds(60*60*2)
-        .timeToIdleSeconds(60*60*2);
-        
-        // This is 2.6.9 API
-        //.maxEntriesLocalDisk(1000);
-        //.persistence(new PersistenceConfiguration().strategy(Strategy.LOCALTEMPSWAP));
-    }
+       public <T extends Object> Map<T,T> load(Map<T,T> map, boolean recursive){
+               if(isRecursiveEnabled && recursive) {
+                       logger.info("---- starting recursive load for map");
+                       Set<CdmBase> alreadyVisitedEntities = new HashSet<CdmBase>();
+                       Map<T,T> cachedMap = load(map, alreadyVisitedEntities);
+                       alreadyVisitedEntities.clear();
+                       logger.info("---- ending recursive load for cdm entity map \n");
+                       return cachedMap;
+               } else {
+                       return load(map, null);
+               }
+       }
 
-    
-    /**
-     * Returns the cache corresponding to the cache id
-     *
-     * @param cacheId
-     * @return
-     */
-    private Cache getCache() {
-        return getDefaultCacheManager().getCache(cacheId);
-    }
-
-
-    /**
-     * Puts the (Key,Value) pair of ({@link java.util.UUID}, {@link eu.etaxonomy.cdm.model.common.CdmBase}),
-     * in the cache corresponding to the given cache id
-     *
-     * @param cacheId
-     * @param uuid
-     * @param cdmEntity
-     */
-    public CdmBase load(CdmBase cdmEntity, boolean recursive) {
-       CdmEntityCacheKey id = new CdmEntityCacheKey(cdmEntity);
-       // first look in 'this' cache
-       CdmBase cachedCdmEntity = getFromCache(id);
-                
-        if(cachedCdmEntity == null) {
-               // then try the permanent (uuid-based) cache
-               cachedCdmEntity = getFromCache(cdmEntity.getUuid());            
-        }
-        if(isRecursiveEnabled && recursive) {
-               String className = cdmEntity.getClass().getName();
-               CdmModelGetMethodFromClass cmgmfc = getFromCdmlibModelCache(className);
-               if(cmgmfc != null) {
-                       List<String> getMethods = cmgmfc.getGetMethods();
-               }
-        }
-        if(cachedCdmEntity != null) {
-            return cachedCdmEntity;
-        } else {
-            getCache().put(new Element(id, cdmEntity));
-            return cdmEntity;
+       private <T extends Object> Map<T,T> load(Map<T,T> map, Set<CdmBase> alreadyVisitedEntities){
+        if(map == null || map.isEmpty()) {
+            return map;
         }
-    }
-
-    public void put(CdmBase cdmEntity) {       
-       CdmEntityCacheKey id = new CdmEntityCacheKey(cdmEntity);
-        Element cachedCdmEntityElement = getCacheElement(id);
-                
-        if(cachedCdmEntityElement == null) {
-               cachedCdmEntityElement = getCacheElement(cdmEntity.getUuid());
-               if(cachedCdmEntityElement != null) {
-                       logger.info("Cdm Entity with id : " + cdmEntity.getId() + " already exists in permanent cache. Ignoring put.");
-                       return;
-               }
+
+        int originalMapSize = map.size();
+        Object[] result = new Object[ map.size() * 2 ];
+        Iterator<Map.Entry<T,T>> iter = map.entrySet().iterator();
+        int i=0;
+        while ( iter.hasNext() ) {
+            Map.Entry<T,T> e = (Map.Entry<T,T>) iter.next();
+            result[i++] = e.getKey();
+            result[i++] = e.getValue();
         }
-        
-        getCache().put(new Element(id, cdmEntity));       
-    }
 
-    
-    private Element getCacheElement(CdmEntityCacheKey key) {
-        return getCache().get(key);
-    }
-
-    public CdmModelGetMethodFromClass getFromCdmlibModelCache(String className) {
-        Element e = cdmlibModelCache.get(className);
-        if (e == null) {
-            return null;
-        } else {
-            return (CdmModelGetMethodFromClass) e.getObjectValue();
+        for(i=0; i<result.length;i++) {            
+               if(alreadyVisitedEntities == null) {
+                       result[i] = load(result[i], false);
+               } else {                              
+                       result[i] = loadRecursive(result[i], alreadyVisitedEntities);
+               }
         }
-    }
-
-    public CdmBase getFromCache(CdmEntityCacheKey id) {
-        Element e = getCacheElement(id);
-        if (e == null) {
-            return null;
-        } else {
-            return (CdmBase) e.getObjectValue();
+        map.clear();
+        for(i = 0; i < originalMapSize; i+=2 ) {
+            map.put(
+                    (T)result[i],
+                    (T)result[i+1]
+                );
         }
-    }
+        return map;
+       }
+       /**
+        * Puts the (Key,Value) pair of ({@link java.util.UUID}, {@link eu.etaxonomy.cdm.model.common.CdmBase}),
+        * in the cache corresponding to the given cache id
+        *
+        * @param cacheId
+        * @param uuid
+        * @param cdmEntity
+        */
+       public CdmBase load(CdmBase cdmEntity, boolean recursive) {
+               
+               if(isRecursiveEnabled && recursive) {
+                       logger.info("---- starting recursive load for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
+                       Set<CdmBase> alreadyVisitedEntities = new HashSet<CdmBase>();
+                       CdmBase cb =  loadRecursive(cdmEntity, alreadyVisitedEntities);
+                       alreadyVisitedEntities.clear();
+                       logger.info("---- ending recursive load for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + "\n");
+                       return cb;
+               } else {
+                       return load(cdmEntity);
+               }
+               
+               // split into two methods 
+               // - load(CdmBase cdmBase)
+               // - recursiveLoad(CdmBase cdmbase, List<CdmBase> alreadyVisitedEntities) 
+               //   : the entity to be visted should added before the recursive call
+               //     and deleted after the call to end finally with a list
+               //     of size zero at the end
+               //   : entity to recurse should be the original entity and
+               //     not the cached one
+               
+       }
 
-    public CdmBase getFromCache(Class<? extends CdmBase> clazz, int id) {
-        CdmEntityCacheKey cacheId = generateKey(clazz,id);
-        return getFromCache(cacheId);
-    }
-    
-    public CdmBase getFromCache(CdmBase cdmBase) {
-        CdmEntityCacheKey cacheId = generateKey(cdmBase);
-        return getFromCache(cacheId);
-    }
-    
-    public List<CdmBase> getAllEntities() {
-       List<CdmBase> entities = new ArrayList<CdmBase>();
-       Map<String, CdmBase> elementsMap = getCache().getAllWithLoader(getCache().getKeys(), null);
-       for (Map.Entry<String, CdmBase> entry : elementsMap.entrySet()) {
-           entities.add(entry.getValue());
-       }
-       return entities;
-    }
+       
+       private CdmBase load(CdmBase cdmEntity) {
+               logger.info("loading object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
 
+               // start by looking up the cdm entity in the cache
+               CdmBase cachedCdmEntity = getFromCache(cdmEntity);
+               
+               if(cachedCdmEntity != null) {
+                       // if cdm entity was found in cache then return ...
+                       logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " already exists");
+                       return cachedCdmEntity;
+               } else {                
+                       // ... else save the entity in the cache        
+                       getCache().put(new Element(generateKey(cdmEntity), cdmEntity));
+                       logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " put in cache");
+                       return cdmEntity;
+               }         
+       }
+       
+       private CdmBase loadRecursive(CdmBase cdmEntity, Set<CdmBase> alreadyVisitedEntities) {
 
+               CdmBase cachedCdmEntity = load(cdmEntity);
+               
+               // we want to recursive through the cdmEntity (and not the cachedCdmEntity)
+               // since there could be new initialized object in the cdmEntity sub-graph
+               
+               // start by getting the fields from the cdm entity
+               String className = cdmEntity.getClass().getName();
+               CdmModelFieldPropertyFromClass cmgmfc = getFromCdmlibModelCache(className);
+               if(cmgmfc != null) {
+                       alreadyVisitedEntities.add(cdmEntity);
+                       List<String> fields = cmgmfc.getFields();
+                       for(String field : fields) {
+                               // retrieve the actual object corresponding to the field.
+                               // this object will be either a CdmBase or a Collection / Map
+                               // with CdmBase as the generic type
 
+                               // In the case that the returned is either a Collection or a Map
+                               // the individual objects inside these also need to be loaded
+                               // by calling the corresponding cachify method in the
+                               // CdmEntityCachingUtils   
+                                                               
+                               CdmBase cdmEntityInSubGraph = getCdmBaseTypeFieldValue(cdmEntity, cachedCdmEntity, field);
+                               if(cdmEntityInSubGraph != null && !alreadyVisitedEntities.contains(cdmEntityInSubGraph)) {                                                                                              
+                                       logger.info("recursive loading object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId());
+                                       loadRecursive(cdmEntityInSubGraph, alreadyVisitedEntities);
+                               }                               
+                       }
+               }
+               return cachedCdmEntity;
+       }
 
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.cdm.model.ICdmCacher#exists(java.util.UUID)
-     */
-    @Override
-    public boolean exists(UUID uuid) {
-        return (getCacheElement(uuid) != null || super.getCacheElement(uuid) != null);
-    }
+       
+       private CdmBase getCdmBaseTypeFieldValue(CdmBase cdmEntity, CdmBase cachedCdmEntity, String fieldName) {
+               
+               
+               if(cachedCdmEntity == null) {
+                       throw new CdmClientCacheException("When trying to set filed value, the cached cdm entity cannot be null");
+               }
+               
+               Class<?> clazz = cdmEntity.getClass();
+               try {
+                       // this call will search in the provided class as well as
+                       // the super classes until it finds the field
+                       Field field = ReflectionUtils.findField(clazz, fieldName);
+                       //                      logger.info("Retrieving field " + field
+                       //                                      + " from cdm entity of type " + c.getName() 
+                       //                                      + " with id " + cdmEntity.getId());
 
-    public boolean exists(CdmEntityCacheKey key) {
-        return (getCacheElement(key) != null);
-    }
 
+                       if(field == null) {
+                               throw new CdmClientCacheException("Field '" + fieldName 
+                                               + "' not found when searching in class '" + clazz.getName() + "' and its supercalsses");
+                       }
+                       field.setAccessible(true);
+                       Object o = field.get(cdmEntity);
+                       //                      if(o == null) {
+                       //                              logger.info(" - resulting object is null");
+                       //                      } else if(ProxyFactory.isProxyClass(o.getClass())) {
+                       //                              logger.info(" - resulting object is a proxy object");
+                       //                      } else if(o instanceof PersistentCollection) {
+                       //                              logger.info(" - resulting object is a persistent collection object");
+                       //                      } else {                        
+                       //                              logger.info(" - resulting object is of type " + o.getClass().getName());
+                       //                      }
+                       CdmBase cdmEntityInSubGraph = null;
+                       if(o != null 
+                                       && !ProxyFactory.isProxyClass(o.getClass()) 
+                                       && !(o instanceof PersistentCollection)                                         
+                                       && CdmBase.class.isAssignableFrom(o.getClass())) {
+                               //                              logger.info("retrieving object of type " + o.getClass().getName() 
+                               //                                              + " with id " + ((CdmBase)o).getId());
+                               
+                               //FIXME:Remoting add case for collection / map
+                               //FIXME:Remoting if cached entity != original entity then
+                               //               replace original with cache using
+                               //               field.set and return original entity
+                               cdmEntityInSubGraph  = (CdmBase)o;
+                               
+                               CdmBase cachedCdmEntityInSubGraph = getFromCache(cdmEntityInSubGraph);
 
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.cdm.model.ICdmCacher#existsAndIsNotNull(java.util.UUID)
-     */
-    @Override
-    public boolean existsAndIsNotNull(UUID uuid) {
-        return getFromCache(uuid) != null;
-    }
+                               if(cachedCdmEntityInSubGraph != null) {
+                                       if(cachedCdmEntityInSubGraph != cdmEntityInSubGraph) {                          
+                                               field.set(cachedCdmEntity, cachedCdmEntityInSubGraph);
+                                       }
+                               } else {
+                                       field.set(cachedCdmEntity, cdmEntityInSubGraph);
+                               }
+                       } 
+                       // we return the original cdm entity in the sub graph because we
+                       // want to continue to recurse on the input cdm entity graph
+                       // and not the one in the cache
+                       return cdmEntityInSubGraph;
+               } catch (SecurityException e) {
+                       throw new CdmClientCacheException(e);
+               } catch (IllegalArgumentException e) {
+                       throw new CdmClientCacheException(e);
+               } catch (IllegalAccessException e) {
+                       throw new CdmClientCacheException(e);
+               }        
+       }
 
-    public boolean existsAndIsNotNull(CdmEntityCacheKey id) {
-        return getFromCache(id) != null;
-    }
+       public void put(CdmBase cdmEntity) {            
+               CdmEntityCacheKey id = new CdmEntityCacheKey(cdmEntity);
+               Element cachedCdmEntityElement = getCacheElement(id);
 
+               if(cachedCdmEntityElement == null) {
+                       cachedCdmEntityElement = getCacheElement(cdmEntity.getUuid());
+                       if(cachedCdmEntityElement != null) {
+                               logger.info("Cdm Entity with id : " + cdmEntity.getId() + " already exists in permanent cache. Ignoring put.");
+                               return;
+                       }
+               }
+               
+               getCache().put(new Element(id, cdmEntity));       
+       }
 
-    public static CdmEntityCacheKey generateKey(Class<? extends CdmBase> clazz, int id) {
-        return new CdmEntityCacheKey(clazz, id);
-    }
-    
-    
-    public static CdmEntityCacheKey generateKey(CdmBase cdmBase) {
+
+       private Element getCacheElement(CdmEntityCacheKey key) {
+               return getCache().get(key);
+       }
+
+       public CdmModelFieldPropertyFromClass getFromCdmlibModelCache(String className) {
+               Element e = cdmlibModelCache.get(className);
+               if (e == null) {
+                       return null;
+               } else {
+                       return (CdmModelFieldPropertyFromClass) e.getObjectValue();
+               }
+       }
+
+       public CdmBase getFromCache(CdmEntityCacheKey id) {
+               Element e = getCacheElement(id);
+               if (e == null) {
+                       return null;
+               } else {
+                       return (CdmBase) e.getObjectValue();
+               }
+       }
+
+       public CdmBase getFromCache(Class<? extends CdmBase> clazz, int id) {
+               CdmEntityCacheKey cacheId = generateKey(clazz,id);
+               return getFromCache(cacheId);
+       }
+
+       public CdmBase getFromCache(CdmBase cdmBase) {
+               
+               CdmEntityCacheKey cacheId = generateKey(cdmBase);
+
+               CdmBase cachedCdmEntity = getFromCache(cacheId);
+
+               if(cachedCdmEntity == null) {
+                       // ... then try the permanent (uuid-based) cache
+                       cachedCdmEntity = getFromCache(cdmBase.getUuid());              
+               }
+
+               return cachedCdmEntity;
+       }
+       
+       public CdmBase getFromCache(CdmBase cdmBase, Class<? extends CdmBase> clazz) {
+               
+               cdmBase = CdmBase.deproxy(cdmBase, clazz);
+               
+               CdmEntityCacheKey cacheId = generateKey(cdmBase);
+
+               CdmBase cachedCdmEntity = getFromCache(cacheId);
+
+               if(cachedCdmEntity == null) {
+                       // ... then try the permanent (uuid-based) cache
+                       cachedCdmEntity = getFromCache(cdmBase.getUuid());              
+               }
+
+               return cachedCdmEntity;
+       }
+
+       public List<CdmBase> getAllEntities() {
+               List<CdmBase> entities = new ArrayList<CdmBase>();
+               Map<String, CdmBase> elementsMap = getCache().getAllWithLoader(getCache().getKeys(), null);
+               for (Map.Entry<String, CdmBase> entry : elementsMap.entrySet()) {
+                       entities.add(entry.getValue());
+               }
+               return entities;
+       }
+
+
+
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.model.ICdmCacher#exists(java.util.UUID)
+        */
+       @Override
+       public boolean exists(UUID uuid) {
+               return (getCacheElement(uuid) != null || super.getCacheElement(uuid) != null);
+       }
+
+       public boolean exists(CdmEntityCacheKey key) {
+               return (getCacheElement(key) != null);
+       }
+
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.model.ICdmCacher#existsAndIsNotNull(java.util.UUID)
+        */
+       @Override
+       public boolean existsAndIsNotNull(UUID uuid) {
+               return getFromCache(uuid) != null;
+       }
+
+       public boolean existsAndIsNotNull(CdmEntityCacheKey id) {
+               return getFromCache(id) != null;
+       }
+
+
+       public static CdmEntityCacheKey generateKey(Class<? extends CdmBase> clazz, int id) {
+               return new CdmEntityCacheKey(clazz, id);
+       }
+
+
+       public static CdmEntityCacheKey generateKey(CdmBase cdmBase) {
                Class<? extends CdmBase> entityClass = cdmBase.getClass();
                int id = cdmBase.getId();
                return new CdmEntityCacheKey(entityClass, id);
-    }
+       }
 
        public static boolean isRecursiveEnabled() {
                return isRecursiveEnabled;
diff --git a/eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/taxeditor/remoting/CdmRemotingException.java b/eu.etaxonomy.taxeditor.remoting/src/main/java/eu/etaxonomy/taxeditor/remoting/CdmRemotingException.java
new file mode 100644 (file)
index 0000000..68f5ca0
--- /dev/null
@@ -0,0 +1,14 @@
+package eu.etaxonomy.taxeditor.remoting;
+
+public class CdmRemotingException extends RuntimeException {
+       
+       /**
+        * 
+        */
+       private static final long serialVersionUID = -560332689478356360L;
+
+       public CdmRemotingException(String message) {
+               super(message);
+       }
+
+}
index f8c6ba808f91d05e35674848bc00c28b74a57447..817e430be2fc9952a812961e824813c991a557cd 100644 (file)
@@ -83,9 +83,10 @@ public class CdmEntitySessionManager {
                activeSession = session;
        }
        
-       public void add(ISessionEventListener sessionOwner, CdmBase cdmBase) {
+       @SuppressWarnings("unchecked")
+       public <T extends CdmBase> T add(ISessionEventListener sessionOwner, T cdmBase) {
                CdmEntitySession session = newSession(sessionOwner,true);
-               session.getCdmTransientEntityCacher().load(cdmBase,true);
+               return (T)session.getCdmTransientEntityCacher().load(cdmBase,true);
        }
        
        void addToOwnerSessionMap(ISessionEventListener owner, CdmEntitySession session) {
index cadc85c931ca5c137ff415b2fe83d7162b7dc5b0..5c11354536e5fb33d842e6d8cffec2fe6893dd04 100644 (file)
@@ -445,7 +445,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
                                throw new HibernateException("commonService not initialized (null)");
                        }
 
-                       CdmBase cdmBase = CdmBase.deproxy(cachedCommonService.find(clazz,classid),clazz);
+                       CdmBase cdmBase = cachedCommonService.find(clazz,classid);
                        setImplementation(cdmBase);
 
                }
index c0aca306ff5a8a570dc04b6793b806a3289f62b6..4d2abf58951574e08a8118c2fcd3aa6d2d2ddf69 100644 (file)
@@ -9,42 +9,29 @@
 */
 package eu.etaxonomy.cdm.api.cache;
 
-import java.io.IOException;
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.UUID;
 
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.hibernate.collection.spi.PersistentCollection;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
 import org.unitils.dbunit.annotation.DataSet;
 
-import eu.etaxonomy.cdm.api.cache.CachedCommonServiceImpl;
 import eu.etaxonomy.cdm.api.service.ICommonService;
 import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
 import eu.etaxonomy.cdm.api.service.ITaxonService;
-import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.common.Credit;
-import eu.etaxonomy.cdm.model.common.Extension;
-import eu.etaxonomy.cdm.model.common.IdentifiableSource;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.description.KeyStatement;
 import eu.etaxonomy.cdm.model.description.PolytomousKey;
 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
-import eu.etaxonomy.cdm.model.media.Rights;
-import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
-import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest;
 import eu.etaxonomy.taxeditor.httpinvoker.CDMServer;
 import eu.etaxonomy.taxeditor.remoting.session.CdmEntitySessionManager;
@@ -71,13 +58,20 @@ public class CdmClientCachingTest extends BaseRemotingTest {
 
     CdmEntitySessionManager cdmEntitySessionManager = getRemoteApplicationController().getCdmEntitySessionManager();
     
+       CdmTransientEntityCacher cacher;
+       
     Language english = Language.getLanguageFromUuid(Language.uuidEnglish);
-
+       
+    private static final List<String> PKEY_DEPTH1_INIT_STRATEGY = Arrays.asList(new String[] {
+                       });
     
-
+    private static final List<String> PKEY_DEPTH2_INIT_STRATEGY = Arrays.asList(new String[] {
+               "root"});
+    
+    private static final List<String> PKEY_DEPTH3_INIT_STRATEGY = Arrays.asList(new String[] {                 
+               "root.statement"});
     
-    private static final List<String> PKEY_INIT_STRATEGY = Arrays.asList(new String[] {
-            "root"});
+    private ISessionEventListener sessionOwner;
     
     @BeforeClass
     public static void initializePolytomousKeyTest() {
@@ -85,21 +79,20 @@ public class CdmClientCachingTest extends BaseRemotingTest {
         CDMServer.getInstance().setKeepServerRunning(true);    
 
                CdmModelCacher cmdmc = new CdmModelCacher();
-               cmdmc.cacheGetters();
+               cmdmc.cacheGetterFields();
                
         //initializeController("default", "127.0.0.1", 8080, "", NomenclaturalCode.ICNAFP);
     }
 
-    @Test
-    public void readAllPolytomousKeys() {
-        List<PolytomousKey> pKeys = polytomousKeyService.list(PolytomousKey.class, null, null, null, null);
-        for(PolytomousKey pKey : pKeys) {
-            logger.info("Polytomous Key : " + pKey.getTitleCache());
-        }
+    @Before
+    public void initializeSession() {
+       sessionOwner = new MockSessionOwner();    
+       cdmEntitySessionManager.bind(sessionOwner);
+       cacher = cdmEntitySessionManager.getCdmTransientEntityCacher(sessionOwner);
     }
 
     @Test
-    public void testCachifyNonRecursive() {
+    public void whenRecursiveCachingIsDisabledObjectsInSubGraphAreNotLoadedInSessionCache() {
        CdmTransientEntityCacher.setRecursiveEnabled(false);
        ISessionEventListener sessionOwner = new MockSessionOwner();
        cdmEntitySessionManager.bind(sessionOwner);
@@ -107,19 +100,197 @@ public class CdmClientCachingTest extends BaseRemotingTest {
         cdmEntitySessionManager.add(sessionOwner, pkey);
         CdmTransientEntityCacher cacher = cdmEntitySessionManager.getCdmTransientEntityCacher(sessionOwner);
         Assert.assertNull(cacher.getFromCache(pkey));
-
+        CdmTransientEntityCacher.setRecursiveEnabled(true);
     }
     
+    
     @Test
-    public void testCachifyRecursive() {
-       CdmTransientEntityCacher.setRecursiveEnabled(false);
-       ISessionEventListener sessionOwner = new MockSessionOwner();
-       cdmEntitySessionManager.bind(sessionOwner);
-        PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_INIT_STRATEGY),PolytomousKey.class);
-        cdmEntitySessionManager.add(sessionOwner, pkey);
+    public void recursiveLoadSubGraphDepth1Test() {
+
+       // this call will load into the session cache the graph 
+       // polytomous key  
+       //      |- root : polytomous key node 
+       // in a recursive call          
+        PolytomousKey pkey1 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH1_INIT_STRATEGY),PolytomousKey.class);
+        pkey1 = cdmEntitySessionManager.add(sessionOwner, pkey1);
         CdmTransientEntityCacher cacher = cdmEntitySessionManager.getCdmTransientEntityCacher(sessionOwner);
+        // checking to make sure the root object is in the session cache
+        Assert.assertSame(pkey1.getRoot(), cacher.getFromCache(pkey1.getRoot()));
+        
+    }
+
+    
+    @Test
+    public void recursiveLoadSubGraphDepth2Test() {
+
+       // this call will load into the session cache the graph 
+       // polytomous key  
+       //      |- root : polytomous key node 
+       //              |- question : KeyStatement
+       //              |- statement : KeyStatement     
+       // in a recursive call          
+        PolytomousKey pkey = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
+        pkey = cdmEntitySessionManager.add(sessionOwner, pkey);
+        CdmTransientEntityCacher cacher = cdmEntitySessionManager.getCdmTransientEntityCacher(sessionOwner);
+        // checking to make sure the root object is in the session cache
         Assert.assertSame(pkey.getRoot(), cacher.getFromCache(pkey.getRoot()));
+        Assert.assertSame(pkey.getRoot().getStatement(), cacher.getFromCache(pkey.getRoot().getStatement()));
+        Assert.assertSame(pkey.getRoot().getQuestion(), cacher.getFromCache(pkey.getRoot().getQuestion()));
+        
+    }
+        
+    /**
+     * when : retrieving objects using recursive caching of object graphs with different depths 
+     * then : the objects in the sub-graph having the same persistence id should be the same
+     */
+    @Test
+    public void lazyLoadRecursiveTest() {
+
+       // this call will load into the session cache the graph and update the objects in the sub-graph for a
+       // polytomous key  
+       //      |- root : polytomous key node 
+       //              |- question : KeyStatement
+       //              |- statement : KeyStatement     
+        PolytomousKey pkey1 = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
+        pkey1 = cdmEntitySessionManager.add(sessionOwner, pkey1);
+        CdmTransientEntityCacher cacher = cdmEntitySessionManager.getCdmTransientEntityCacher(sessionOwner);
+               
     }
+    
+
+    /**
+     * when : retrieving objects using recursive caching of object graphs with different depths      
+     * then : the objects in the sub-graph having the same persistence id should be the same
+     */
+    @Test
+    public void differentSubGraphDepthTest1() {
+       
+       // this call will load into the session cache the graph and update the objects in the sub-graph for a
+       // polytomous key  
+       //      |- root : polytomous key node 
+       // in a recursive call    
+        PolytomousKey pkey1 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH1_INIT_STRATEGY),PolytomousKey.class);
+        pkey1 = cdmEntitySessionManager.add(sessionOwner, pkey1);
+        CdmTransientEntityCacher cacher = cdmEntitySessionManager.getCdmTransientEntityCacher(sessionOwner);
+               
+       // this call will load into the session cache the graph and update the objects in the sub-graph for a
+       // polytomous key  
+       //      |- root : polytomous key node 
+       //              |- question : KeyStatement
+       //              |- statement : KeyStatement            
+        PolytomousKey pkey2 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
+        pkey2 = cdmEntitySessionManager.add(sessionOwner, pkey2);
+
+        Assert.assertSame(pkey2.getRoot().getStatement(), cacher.getFromCache(pkey2.getRoot().getStatement()));
+        Assert.assertSame(pkey1.getRoot().getStatement(), pkey2.getRoot().getStatement());
+        Assert.assertSame(cacher.getFromCache(pkey1.getRoot().getStatement()), cacher.getFromCache(pkey2.getRoot().getStatement()));
+        
+    }
+    
+    /**
+     * when : retrieving objects using recursive caching of object graphs with different depths 
+     * then : the objects in the sub-graph having the same persistence id should be the same
+     */
+    @Test
+    public void differentSubGraphDepthTest2() {
+
+       // this call will load into the session cache the graph and update the objects in the sub-graph for a
+       // polytomous key  
+       //      |- root : polytomous key node 
+       //              |- question : KeyStatement
+       //              |- statement : KeyStatement     
+        PolytomousKey pkey1 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
+        pkey1 = cdmEntitySessionManager.add(sessionOwner, pkey1);
+        CdmTransientEntityCacher cacher = cdmEntitySessionManager.getCdmTransientEntityCacher(sessionOwner);
+               
+       // this call will load into the session cache the graph and update the objects in the sub-graph for a
+       // polytomous key  
+       //      |- root : polytomous key node  
+        PolytomousKey pkey2 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH1_INIT_STRATEGY),PolytomousKey.class);
+        pkey2 = cdmEntitySessionManager.add(sessionOwner, pkey2);
+
+        Assert.assertSame(pkey2.getRoot().getStatement(), cacher.getFromCache(pkey2.getRoot().getStatement()));
+        Assert.assertSame(pkey1.getRoot().getStatement(), pkey2.getRoot().getStatement());
+        Assert.assertSame(cacher.getFromCache(pkey1.getRoot().getStatement()), cacher.getFromCache(pkey2.getRoot().getStatement()));
+    }
+    
+    /**
+     * when : retrieving objects using (first) recursive load directly and (second) lazy loading in the same session
+     * then : the objects in the sub-graph having the same persistence id should be the same
+     */
+    @Test
+    public void recursiveLoadAndLazyLoadTest() {
+       
+       // this call will load into the session cache the graph and update the objects in the sub-graph for a
+       // polytomous key  
+       //      |- root : polytomous key node 
+       //              |- question : KeyStatement
+       //              |- statement : KeyStatement     
+        PolytomousKey pkey1 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
+        pkey1 = cdmEntitySessionManager.add(sessionOwner, pkey1);
+        CdmTransientEntityCacher cacher = cdmEntitySessionManager.getCdmTransientEntityCacher(sessionOwner);
+               
+        // checking that the root is not null and 
+        // that it exists in the cache and
+        // that both the original object and the 
+        // cached object are the same
+        Assert.assertNotNull(pkey1.getRoot().getStatement());
+        Assert.assertNotNull(cacher.getFromCache(pkey1.getRoot().getStatement()));
+        
+       // this call will load into the session cache the graph and update the objects in the sub-graph for a
+       // polytomous key  
+       //      |- root : polytomous key node  
+        PolytomousKey pkey2 = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
+        pkey2 = cdmEntitySessionManager.add(sessionOwner, pkey2);
+
+        
+        Assert.assertSame(pkey2.getRoot().getStatement(), cacher.getFromCache(pkey2.getRoot().getStatement()));
+        Assert.assertSame(pkey1.getRoot().getStatement(), pkey2.getRoot().getStatement());
+        Assert.assertSame(cacher.getFromCache(pkey1.getRoot().getStatement()), cacher.getFromCache(pkey2.getRoot().getStatement()));
+    }
+    
+    /**
+     * when : retrieving objects using (first) lazy loading  and (second) recursive load directly in the same session
+     * then : the objects in the sub-graph having the same persistence id should be the same
+     */
+    @Test
+    public void lazyLoadAndRecursiveLoadTest() {
+
+
+       // this call will load into the session cache the graph and update the objects in the sub-graph for a
+       // polytomous key  
+       //      |- root : polytomous key node  
+       
+       PolytomousKey pkey1 = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
+        pkey1 = cdmEntitySessionManager.add(sessionOwner, pkey1);
+        
+        // lazy initialising root.statement
+        KeyStatement st = CdmBase.deproxy(pkey1.getRoot().getStatement(), KeyStatement.class); 
+        st.getLabel();
+        
+        // checking that the root is not null and 
+        // that it exists in the cache and
+        // that both the original object and the 
+        // cached object are the same
+       Assert.assertNotNull(pkey1.getRoot().getStatement());
+       Assert.assertSame(CdmBase.deproxy(pkey1.getRoot().getStatement(), KeyStatement.class),
+                       cacher.getFromCache(pkey1.getRoot().getStatement(), KeyStatement.class));
+       
+       // this call will load into the session cache the graph and update the objects in the sub-graph for a
+       // polytomous key  
+       //      |- root : polytomous key node 
+       //              |- question : KeyStatement
+       //              |- statement : KeyStatement     
+        
+       PolytomousKey pkey2 = CdmBase.deproxy(polytomousKeyService.load(polytomousKeyUuid, PKEY_DEPTH2_INIT_STRATEGY),PolytomousKey.class);
+       pkey2 = cdmEntitySessionManager.add(sessionOwner, pkey2);
+
+       Assert.assertSame(pkey2.getRoot().getStatement(), cacher.getFromCache(pkey2.getRoot().getStatement(), KeyStatement.class));
+       Assert.assertSame(st, pkey2.getRoot().getStatement());
+       Assert.assertSame(cacher.getFromCache(st), cacher.getFromCache(pkey2.getRoot().getStatement(), KeyStatement.class));
+    }
+    
+
 
     @Test
     public void savePolytomousKeyNodeDataWithSameSubKey() {
index cc7e69a17a46374498a2cf8ff204dc368f089e00..44bced2275d56084409d799a06afca6579f88bc8 100644 (file)
@@ -12,6 +12,8 @@ import org.junit.Test;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
 
+import eu.etaxonomy.cdm.api.cache.CdmRemoteCacheManager.CdmCacheManagerType;
+
 
 public class CdmModelGetMethodCacherTest {
 
@@ -20,6 +22,8 @@ public class CdmModelGetMethodCacherTest {
     public static final Resource CDMLIB_DISK_STORE_RESOURCE =
             new ClassPathResource("/eu/etaxonomy/cache");
     
+    
+
        @Test
        public void cacheGettersTest() {
                
@@ -30,21 +34,26 @@ public class CdmModelGetMethodCacherTest {
                        throw new CdmClientCacheException(e);
                }               
                CdmModelCacher cmdmc = new CdmModelCacher();
-               cmdmc.cacheGetters();
+               
+               //cmdmc.checkGetterMethods();
+               
+               cmdmc.cacheGetterFields();
 
                                                
                Cache cdmlibCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
-               List<CdmModelGetMethodFromClass> cmgmfcList = cmdmc.getCdmModelGetMethodFromClassList();
+               List<CdmModelFieldPropertyFromClass> cmgmfcList = cmdmc.getCdmModelGetMethodFromClassList();
                
                List<Object> keys = cdmlibCache.getKeys();
                Assert.assertEquals(cmgmfcList.size(), keys.size());
                                
-               for(CdmModelGetMethodFromClass cmgmfc: cmgmfcList) {
+               for(CdmModelFieldPropertyFromClass cmgmfc: cmgmfcList) {
                        String className = cmgmfc.getClassName();
                        Assert.assertTrue(keys.contains(className));
                        logger.info("Class Name : " + className + " has been cached");
                }
-
+               cdmlibCache.removeAll();
+               cdmlibCache.flush();
+               CdmRemoteCacheManager.getInstance().shutdown(CdmCacheManagerType.CDMLIB_MODEL);
        }
 
        
index fb48dac44e8580bc39f08d1372e29ec2c5a13461..c068d69c20aec48f6a50ce59f56f847852f9297a 100644 (file)
@@ -71,7 +71,7 @@
 
   <RightsInfo id="10" created="2014-10-09 15:45:53.0" uuid="bdfb572b-be25-45e7-9349-22a9da43531f" updated="2014-10-09 15:48:01.0" text="Rights Text Test" createdby_id="10" updatedby_id="10" agent_id="4808" type_id="2056"/>
 
-  <PolytomousKeyNode id="2750" created="2014-03-10 10:02:35.0" uuid="75e4c924-ff58-4ee7-a59d-fd9173517d08" updated="2014-03-10 10:02:42.0" nodenumber="1" createdby_id="30" updatedby_id="30" key_id="1550" question_id="2760"/>
+  <PolytomousKeyNode id="2750" created="2014-03-10 10:02:35.0" uuid="75e4c924-ff58-4ee7-a59d-fd9173517d08" updated="2014-03-10 10:02:42.0" nodenumber="1" createdby_id="30" updatedby_id="30" key_id="1550" question_id="2760" statement_id="2460"/>
   <PolytomousKeyNode id="2751" created="2014-03-10 10:02:52.0" uuid="23e51ff7-11b1-443b-aff2-3fe8b5ace9fe" sortindex="0" key_id="1550" statement_id="2467" subkey_id="1550" taxon_id="37" parent_id="2750"/>
   <PolytomousKeyNode id="2752" created="2014-03-10 10:03:16.0" uuid="dcf326f7-c0ad-4e76-b64e-43aea11f767c" key_id="1550"/>
   <PolytomousKeyNode id="2753" created="2014-03-10 10:03:38.0" uuid="b775c027-13c0-4b87-8aa9-712faeaafbdc" updated="2014-03-10 10:06:32.0" nodenumber="2" sortindex="1" createdby_id="30" updatedby_id="30" key_id="1550" question_id="2761" statement_id="2460"  subkey_id="1550" parent_id="2750"/>