|
From: <fc...@us...> - 2007-10-26 11:06:48
|
Revision: 485
http://openutils.svn.sourceforge.net/openutils/?rev=485&view=rev
Author: fcarone
Date: 2007-10-26 04:06:52 -0700 (Fri, 26 Oct 2007)
Log Message:
-----------
[maven-release-plugin] copy for tag openutils-spring-rmibernate-1.0.2
Added Paths:
-----------
tags/openutils-spring-rmibernate-1.0.2/
tags/openutils-spring-rmibernate-1.0.2/pom.xml
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/util/EntitySerializer.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/exporter/HibernateRmiServiceExporter.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/managers/HibernateLazyServiceImpl.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/shared/HibernateLazyLoaderCallbackFilter.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/shared/LazyReference.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/shared/managers/HibernateLazyService.java
Removed Paths:
-------------
tags/openutils-spring-rmibernate-1.0.2/pom.xml
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/util/EntitySerializer.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/exporter/HibernateRmiServiceExporter.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/managers/HibernateLazyServiceImpl.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/shared/LazyReference.java
tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/shared/managers/HibernateLazyService.java
Copied: tags/openutils-spring-rmibernate-1.0.2 (from rev 475, trunk/openutils-spring-rmibernate)
Deleted: tags/openutils-spring-rmibernate-1.0.2/pom.xml
===================================================================
--- trunk/openutils-spring-rmibernate/pom.xml 2007-10-17 17:06:38 UTC (rev 475)
+++ tags/openutils-spring-rmibernate-1.0.2/pom.xml 2007-10-26 11:06:52 UTC (rev 485)
@@ -1,122 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>net.sourceforge.openutils</groupId>
- <artifactId>openutils</artifactId>
- <version>3</version>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>openutils-spring-rmibernate</artifactId>
- <name>openutils base Spring-Hibernate RMI remote lazy loading support</name>
- <version>1.0.1-SNAPSHOT</version>
- <description>openutils base Spring-Hibernate RMI remote lazy loading support</description>
- <properties>
- <spring.version>2.0.6</spring.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.4.1</version>
- </dependency>
- <dependency>
- <!-- replaces commons-logging -->
- <groupId>org.slf4j</groupId>
- <artifactId>jcl104-over-slf4j</artifactId>
- <version>1.4.1</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-hibernate3</artifactId>
- <version>${spring.version}</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-remoting</artifactId>
- <version>${spring.version}</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aop</artifactId>
- <version>${spring.version}</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate</artifactId>
- <version>3.2.4.ga</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- <exclusion>
- <groupId>cglib</groupId>
- <artifactId>cglib</artifactId>
- </exclusion>
- <exclusion>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- </exclusion>
- <exclusion>
- <groupId>asm</groupId>
- <artifactId>asm-attrs</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>1.7.0</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.3</version>
- </dependency>
- <dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>3.1</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>cglib</groupId>
- <artifactId>cglib-nodep</artifactId>
- <version>2.1_3</version>
- </dependency>
- <dependency>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- <version>2.2.3</version>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
Copied: tags/openutils-spring-rmibernate-1.0.2/pom.xml (from rev 484, trunk/openutils-spring-rmibernate/pom.xml)
===================================================================
--- tags/openutils-spring-rmibernate-1.0.2/pom.xml (rev 0)
+++ tags/openutils-spring-rmibernate-1.0.2/pom.xml 2007-10-26 11:06:52 UTC (rev 485)
@@ -0,0 +1,128 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sourceforge.openutils</groupId>
+ <artifactId>openutils</artifactId>
+ <version>3</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>openutils-spring-rmibernate</artifactId>
+ <name>openutils base Spring-Hibernate RMI remote lazy loading support</name>
+ <version>1.0.2</version>
+ <description>openutils base Spring-Hibernate RMI remote lazy loading support</description>
+ <properties>
+ <spring.version>2.0.6</spring.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.4.1</version>
+ </dependency>
+ <dependency>
+ <!-- replaces commons-logging -->
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl104-over-slf4j</artifactId>
+ <version>1.4.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-hibernate3</artifactId>
+ <version>${spring.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-remoting</artifactId>
+ <version>${spring.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate</artifactId>
+ <version>3.2.4.ga</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>asm</groupId>
+ <artifactId>asm-attrs</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.7.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ <version>2.1_3</version>
+ </dependency>
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ <version>2.2.3</version>
+ </dependency>
+ </dependencies>
+
+ <scm>
+ <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-rmibernate-1.0.2</connection>
+ <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/tags/openutils-spring-rmibernate-1.0.2</developerConnection>
+ <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/tags/openutils-spring-rmibernate-1.0.2</url>
+ </scm>
+</project>
\ No newline at end of file
Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java
===================================================================
--- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java 2007-10-17 17:06:38 UTC (rev 475)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -1,54 +0,0 @@
-package it.openutils.spring.rmibernate.client;
-
-import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService;
-
-import org.aopalliance.intercept.MethodInvocation;
-import org.springframework.remoting.rmi.RmiProxyFactoryBean;
-
-
-/**
- * ProxyFactoryBean for automatic injection of remote lazy loading proxies
- * @author mmolaschi
- * @version $Id: $
- */
-public class HibernateRmiProxyFactoryBean extends RmiProxyFactoryBean
-{
-
- /**
- * Store the hibernate lazy service to be used by remote lazy loading
- */
- public static ThreadLocal<HibernateLazyService> hibernateLazyServiceTL = new ThreadLocal<HibernateLazyService>();
-
- private HibernateLazyService hibernateLazyService;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object invoke(MethodInvocation invocation) throws Throwable
- {
- // store the lazy service for this thread
- if (hibernateLazyService == null)
- {
- // if hibernateLazyService is null this means that this service IS hibernateLazyService
- hibernateLazyServiceTL.set((HibernateLazyService)this.getObject());
- }
- else
- {
- hibernateLazyServiceTL.set(hibernateLazyService);
- }
-
- // proceed with rmi call
- return super.invoke(invocation);
- }
-
- /**
- * Sets the hibernateLazyService.
- * @param hibernateLazyService the hibernateLazyService to set
- */
- public void setHibernateLazyService(HibernateLazyService hibernateLazyService)
- {
- this.hibernateLazyService = hibernateLazyService;
- }
-
-}
Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java)
===================================================================
--- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java (rev 0)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/HibernateRmiProxyFactoryBean.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -0,0 +1,59 @@
+package it.openutils.spring.rmibernate.client;
+
+import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService;
+
+import org.aopalliance.intercept.MethodInvocation;
+import org.springframework.remoting.rmi.RmiProxyFactoryBean;
+
+
+/**
+ * ProxyFactoryBean for automatic injection of remote lazy loading proxies
+ * @author mmolaschi
+ * @version $Id$
+ */
+public class HibernateRmiProxyFactoryBean extends RmiProxyFactoryBean
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6545259150454309616L;
+
+ /**
+ * Store the hibernate lazy service to be used by remote lazy loading
+ */
+ public static ThreadLocal<HibernateLazyService> hibernateLazyServiceTL = new ThreadLocal<HibernateLazyService>();
+
+ private HibernateLazyService hibernateLazyService;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object invoke(MethodInvocation invocation) throws Throwable
+ {
+ // store the lazy service for this thread
+ if (hibernateLazyService == null)
+ {
+ // if hibernateLazyService is null this means that this service IS hibernateLazyService
+ hibernateLazyServiceTL.set((HibernateLazyService)this.getObject());
+ }
+ else
+ {
+ hibernateLazyServiceTL.set(hibernateLazyService);
+ }
+
+ // proceed with rmi call
+ return super.invoke(invocation);
+ }
+
+ /**
+ * Sets the hibernateLazyService.
+ * @param hibernateLazyService the hibernateLazyService to set
+ */
+ public void setHibernateLazyService(HibernateLazyService hibernateLazyService)
+ {
+ this.hibernateLazyService = hibernateLazyService;
+ }
+
+}
Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java)
===================================================================
--- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java (rev 0)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/ClientSerializationInterceptor.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) Openmind. All rights reserved. http://www.openmindonline.it
+ */
+package it.openutils.spring.rmibernate.client.aspects;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+
+/**
+ * @author fcarone
+ * @version $Id: $
+ */
+public class ClientSerializationInterceptor implements MethodInterceptor, Serializable
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2694751376173790718L;
+
+ private HibernateLazyLoaderAspect hibernateLazyLoaderAspect;
+
+ /**
+ * @param hlla
+ */
+ public ClientSerializationInterceptor(HibernateLazyLoaderAspect hibernateLazyLoaderAspect)
+ {
+ this.hibernateLazyLoaderAspect = hibernateLazyLoaderAspect;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable
+ {
+ return hibernateLazyLoaderAspect.loadObject();
+ }
+
+}
Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java
===================================================================
--- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java 2007-10-17 17:06:38 UTC (rev 475)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -1,75 +0,0 @@
-package it.openutils.spring.rmibernate.client.aspects;
-
-import it.openutils.spring.rmibernate.client.HibernateRmiProxyFactoryBean;
-import it.openutils.spring.rmibernate.client.pagination.Paginator;
-import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService;
-
-import java.io.Serializable;
-
-import net.sf.cglib.proxy.LazyLoader;
-
-
-/**
- * Aspect that does remote lazy loading on cglib proxy
- * @author mmolaschi
- * @version $Id: $
- */
-public class HibernateLazyLoaderAspect implements LazyLoader, Serializable
-{
-
- private static ThreadLocal<Paginator> paginator = new ThreadLocal<Paginator>();
-
- private String className;
-
- private String fieldName;
-
- private Serializable id;
-
- /**
- * Constructor
- * @param className parent class name
- * @param fieldName field to be lazy loaded
- * @param id id of current entity
- */
- public HibernateLazyLoaderAspect(String className, String fieldName, Serializable id)
- {
- this.className = className;
- this.fieldName = fieldName;
- this.id = id;
- }
-
- /**
- * Set pagination for next calls in current thread
- * @param from starting row number
- * @param size max number of rows
- */
- public static void setPagination(int from, int size)
- {
- paginator.set(new Paginator(from, size));
- }
-
- /**
- * Disable pagination for next calls in current thread
- */
- public static void resetPagination()
- {
- paginator.set(null);
- }
-
- /**
- * {@inheritDoc}
- */
- public Object loadObject() throws Exception
- {
- // Load from remote
- HibernateLazyService hls = HibernateRmiProxyFactoryBean.hibernateLazyServiceTL.get();
-
- if (paginator.get() != null)
- {
- return hls.invoke(className, fieldName, id, paginator.get().getFrom(), paginator.get().getSize());
- }
-
- return hls.invoke(className, fieldName, id);
- }
-
-}
Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java)
===================================================================
--- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java (rev 0)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/aspects/HibernateLazyLoaderAspect.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -0,0 +1,86 @@
+package it.openutils.spring.rmibernate.client.aspects;
+
+import it.openutils.spring.rmibernate.client.pagination.Paginator;
+import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService;
+
+import java.io.Serializable;
+
+import net.sf.cglib.proxy.LazyLoader;
+
+
+/**
+ * Aspect that does remote lazy loading on cglib proxy
+ * @author mmolaschi
+ * @version $Id$
+ */
+public class HibernateLazyLoaderAspect implements LazyLoader, Serializable
+{
+
+ /**
+ * UID
+ */
+ private static final long serialVersionUID = -365731708075101363L;
+
+ private static ThreadLocal<Paginator> paginator = new ThreadLocal<Paginator>();
+
+ private String className;
+
+ private String fieldName;
+
+ private Serializable id;
+
+ private Object localReference;
+
+ private HibernateLazyService hibernateLazyService;
+
+ /**
+ * Constructor
+ * @param className parent class name
+ * @param fieldName field to be lazy loaded
+ * @param id id of current entity
+ */
+ public HibernateLazyLoaderAspect(String className, String fieldName, Serializable id, HibernateLazyService hibernateLazyService)
+ {
+ this.className = className;
+ this.fieldName = fieldName;
+ this.id = id;
+ this.hibernateLazyService = hibernateLazyService;
+ }
+
+ /**
+ * Set pagination for next calls in current thread
+ * @param from starting row number
+ * @param size max number of rows
+ */
+ public static void setPagination(int from, int size)
+ {
+ paginator.set(new Paginator(from, size));
+ }
+
+ /**
+ * Disable pagination for next calls in current thread
+ */
+ public static void resetPagination()
+ {
+ paginator.set(null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object loadObject() throws Exception
+ {
+ // @todo handle localreference with paginator
+ // Load from remote
+ if (paginator.get() != null)
+ {
+ return hibernateLazyService.invoke(className, fieldName, id, paginator.get().getFrom(), paginator.get().getSize());
+ }
+ if (localReference == null)
+ {
+ localReference = hibernateLazyService.invoke(className, fieldName, id);
+ }
+ return localReference;
+ }
+
+}
Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java
===================================================================
--- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java 2007-10-17 17:06:38 UTC (rev 475)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -1,68 +0,0 @@
-package it.openutils.spring.rmibernate.client.pagination;
-
-/**
- * @author mmolaschi
- * @version $Id: $
- */
-public class Paginator
-{
-
- private int from;
-
- private int size;
-
- /**
- *
- */
- public Paginator()
- {
-
- }
-
- /**
- * @param from starting row number
- * @param size max rows
- */
- public Paginator(int from, int size)
- {
- this.from = from;
- this.size = size;
- }
-
- /**
- * Get starting row number
- * @return starting row number
- */
- public int getFrom()
- {
- return from;
- }
-
- /**
- * Set starting row number
- * @param from starting row number
- */
- public void setFrom(int from)
- {
- this.from = from;
- }
-
- /**
- * Get max number of rows
- * @return max number of rows
- */
- public int getSize()
- {
- return size;
- }
-
- /**
- * Set max number of rows
- * @param size max number of rows
- */
- public void setSize(int size)
- {
- this.size = size;
- }
-
-}
Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java)
===================================================================
--- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java (rev 0)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/client/pagination/Paginator.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -0,0 +1,68 @@
+package it.openutils.spring.rmibernate.client.pagination;
+
+/**
+ * @author mmolaschi
+ * @version $Id$
+ */
+public class Paginator
+{
+
+ private int from;
+
+ private int size;
+
+ /**
+ *
+ */
+ public Paginator()
+ {
+
+ }
+
+ /**
+ * @param from starting row number
+ * @param size max rows
+ */
+ public Paginator(int from, int size)
+ {
+ this.from = from;
+ this.size = size;
+ }
+
+ /**
+ * Get starting row number
+ * @return starting row number
+ */
+ public int getFrom()
+ {
+ return from;
+ }
+
+ /**
+ * Set starting row number
+ * @param from starting row number
+ */
+ public void setFrom(int from)
+ {
+ this.from = from;
+ }
+
+ /**
+ * Get max number of rows
+ * @return max number of rows
+ */
+ public int getSize()
+ {
+ return size;
+ }
+
+ /**
+ * Set max number of rows
+ * @param size max number of rows
+ */
+ public void setSize(int size)
+ {
+ this.size = size;
+ }
+
+}
Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java
===================================================================
--- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java 2007-10-17 17:06:38 UTC (rev 475)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -1,27 +0,0 @@
-package it.openutils.spring.rmibernate.server.aspects;
-
-import java.lang.reflect.Method;
-
-import net.sf.cglib.proxy.MethodInterceptor;
-import net.sf.cglib.proxy.MethodProxy;
-
-
-/**
- * @author mmolaschi
- * @version $Id: $
- */
-public class EmptyMethodInterceptor implements MethodInterceptor
-{
-
- public static final MethodInterceptor INSTANCE = new EmptyMethodInterceptor();
-
- /**
- * {@inheritDoc}
- */
- public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable
- {
- // TODO Auto-generated method stub
- return proxy.invokeSuper(obj, args);
- }
-
-}
Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java)
===================================================================
--- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java (rev 0)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/EmptyMethodInterceptor.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -0,0 +1,27 @@
+package it.openutils.spring.rmibernate.server.aspects;
+
+import java.lang.reflect.Method;
+
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+
+/**
+ * @author mmolaschi
+ * @version $Id$
+ */
+public class EmptyMethodInterceptor implements MethodInterceptor
+{
+
+ public static final MethodInterceptor INSTANCE = new EmptyMethodInterceptor();
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable
+ {
+ // TODO Auto-generated method stub
+ return proxy.invokeSuper(obj, args);
+ }
+
+}
Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java
===================================================================
--- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java 2007-10-17 17:06:38 UTC (rev 475)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -1,58 +0,0 @@
-package it.openutils.spring.rmibernate.server.aspects;
-
-import org.aopalliance.intercept.MethodInterceptor;
-import org.aopalliance.intercept.MethodInvocation;
-import org.hibernate.SessionFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Main server interceptor on rmi calls
- * @author mmolaschi
- * @version $Id: $
- */
-public class HibernateLazyRmiInterceptor implements MethodInterceptor
-{
-
- /**
- * log
- */
- protected static final Logger logger = LoggerFactory.getLogger(HibernateLazyRmiInterceptor.class);
-
- private SessionFactory sessionFactory;
-
- /**
- * Contructor
- * @param sessionFactory hibernate session factory
- */
- public HibernateLazyRmiInterceptor(SessionFactory sessionFactory)
- {
- this.sessionFactory = sessionFactory;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object invoke(MethodInvocation invocation) throws Throwable
- {
- try
- {
- Object retVal = invocation.proceed();
-
- SerializationInterceptor.clean();
- // Proxy class for serialization work
- return SerializationInterceptor.getEnhancedObject(retVal, sessionFactory);
- }
- catch (Throwable ex)
- {
- if (logger.isInfoEnabled())
- {
- logger.info("Processing of " + " remote call resulted in exception: ", ex);
- }
-
- throw ex;
- }
- }
-
-}
Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java)
===================================================================
--- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java (rev 0)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/HibernateLazyRmiInterceptor.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -0,0 +1,61 @@
+package it.openutils.spring.rmibernate.server.aspects;
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+import org.hibernate.SessionFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Main server interceptor on rmi calls
+ * @author mmolaschi
+ * @version $Id$
+ */
+public class HibernateLazyRmiInterceptor implements MethodInterceptor
+{
+
+ /**
+ * log
+ */
+ protected static final Logger logger = LoggerFactory.getLogger(HibernateLazyRmiInterceptor.class);
+
+ private SessionFactory sessionFactory;
+
+ /**
+ * Contructor
+ * @param sessionFactory hibernate session factory
+ */
+ public HibernateLazyRmiInterceptor(SessionFactory sessionFactory)
+ {
+ this.sessionFactory = sessionFactory;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object invoke(MethodInvocation invocation) throws Throwable
+ {
+ logger.debug("Catched invocation: {}", invocation);
+ try
+ {
+ Object retVal = invocation.proceed();
+
+ SerializationInterceptor.clean();
+ // Proxy class for serialization work
+ Object result = SerializationInterceptor.getEnhancedObject(retVal, sessionFactory);
+ logger.debug("Returning enhanced object {}", result);
+ return result;
+ }
+ catch (Throwable ex)
+ {
+ if (logger.isInfoEnabled())
+ {
+ logger.info("Processing of " + " remote call resulted in exception: ", ex);
+ }
+
+ throw ex;
+ }
+ }
+
+}
Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java
===================================================================
--- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java 2007-10-17 17:06:38 UTC (rev 475)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -1,40 +0,0 @@
-package it.openutils.spring.rmibernate.server.aspects;
-
-import it.openutils.spring.rmibernate.shared.LazyReference;
-
-import java.lang.reflect.Method;
-
-import net.sf.cglib.proxy.MethodInterceptor;
-import net.sf.cglib.proxy.MethodProxy;
-
-
-/**
- * Aspect on lazy fields to intercept writeReplace
- * @author mmolaschi
- * @version $Id: $
- */
-public class LazyReferenceAspect implements MethodInterceptor
-{
-
- private LazyReference lazyReference;
-
- public LazyReference getLazyReference()
- {
- return lazyReference;
- }
-
- public void setLazyReference(LazyReference lazyReference)
- {
- this.lazyReference = lazyReference;
- }
-
- /**
- * {@inheritDoc}
- */
- public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable
- {
- // TODO Auto-generated method stub
- return lazyReference;
- }
-
-}
Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java (from rev 481, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java)
===================================================================
--- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java (rev 0)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/LazyReferenceAspect.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -0,0 +1,39 @@
+package it.openutils.spring.rmibernate.server.aspects;
+
+import it.openutils.spring.rmibernate.shared.LazyReference;
+
+import java.lang.reflect.Method;
+
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+
+/**
+ * Aspect on lazy fields to intercept writeReplace
+ * @author mmolaschi
+ * @version $Id$
+ */
+public class LazyReferenceAspect implements MethodInterceptor
+{
+
+ private LazyReference lazyReference;
+
+ public LazyReference getLazyReference()
+ {
+ return lazyReference;
+ }
+
+ public void setLazyReference(LazyReference lazyReference)
+ {
+ this.lazyReference = lazyReference;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable
+ {
+ return lazyReference;
+ }
+
+}
Deleted: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java
===================================================================
--- trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2007-10-17 17:06:38 UTC (rev 475)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -1,334 +0,0 @@
-package it.openutils.spring.rmibernate.server.aspects;
-
-import it.openutils.spring.rmibernate.server.aspects.util.EntitySerializer;
-import it.openutils.spring.rmibernate.shared.LazyReference;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import net.sf.cglib.proxy.Callback;
-import net.sf.cglib.proxy.CallbackFilter;
-import net.sf.cglib.proxy.Enhancer;
-import net.sf.cglib.proxy.Factory;
-import net.sf.cglib.proxy.MethodInterceptor;
-import net.sf.cglib.proxy.MethodProxy;
-import net.sf.cglib.proxy.NoOp;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.collections.SetUtils;
-import org.apache.commons.collections.Transformer;
-import org.hibernate.EntityMode;
-import org.hibernate.SessionFactory;
-import org.hibernate.collection.PersistentCollection;
-import org.hibernate.collection.PersistentSet;
-import org.hibernate.proxy.HibernateProxy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.util.ReflectionUtils;
-
-
-/**
- * Proxy object with {@link EntitySerializer} and Intercept writeReplace calls
- * @author mmolaschi
- * @version $Id: $
- */
-public class SerializationInterceptor implements MethodInterceptor
-{
-
- private static ThreadLocal<List<Object>> processed = new ThreadLocal<List<Object>>();
-
- private static Map<Class, Object> proxies = Collections.synchronizedMap(new HashMap<Class, Object>());
-
- /**
- * log
- */
- private static Logger log = LoggerFactory.getLogger(SerializationInterceptor.class);
-
- /**
- * non proxied object
- */
- private Object original;
-
- /**
- * hibernate sessionfactory
- */
- private SessionFactory sessionFactory;
-
- /**
- * Constructor
- * @param o object to be proxied
- * @param sessionFactory hibernate sessionfactory
- */
- private SerializationInterceptor(Object o, SessionFactory sessionFactory)
- {
- this.original = o;
- this.sessionFactory = sessionFactory;
- }
-
- public static void clean()
- {
- processed.set(null);
- }
-
- /**
- * Get proxy object intercepting writeReplace calls
- * @param o object to be proxied
- * @param sessionFactory hibernate sessionfactory
- * @return proxied object
- */
- public static Object getEnhancedObject(Object o, SessionFactory sessionFactory)
- {
- return getEnhancedObject(o, sessionFactory, null);
- }
-
- /**
- * Get proxy object intercepting writeReplace calls
- * @param o object to be proxied
- * @param sessionFactory hibernate sessionfactory
- * @param lazyRef reference to a lazy field
- * @return proxied object
- */
- public static Object getEnhancedObject(Object o, SessionFactory sessionFactory, LazyReference lazyRef)
- {
- if (o == null)
- {
- return null;
- }
-
- if (!(o instanceof HibernateProxy)
- && !(o instanceof PersistentSet)
- && processed.get() != null
- && processed.get().contains(o))
- {
- return o;
- }
-
- // check if there is an empty constructor
- try
- {
- o.getClass().getConstructor(new Class[]{});
- }
- catch (NoSuchMethodException ex)
- {
- return o;
- }
-
- // check if object can be subclassed
- if (Modifier.isFinal(o.getClass().getModifiers()))
- {
- return o;
- }
-
- try
- {
- // get class
- Class clazz = o.getClass();
-
- // if it is an hibernateproxy get superclass
- if (o instanceof HibernateProxy)
- {
- clazz = o.getClass().getSuperclass();
- if (clazz == null)
- {
- clazz = o.getClass().getInterfaces()[0];
- }
- }
-
- Callback callback = null;
-
- // if this is a lazy field user lazyreferenceaspect
- if (lazyRef != null)
- {
- LazyReferenceAspect lra = new LazyReferenceAspect();
- lra.setLazyReference(lazyRef);
- callback = lra;
- }
- else
- {
- // user default interceptor
- callback = new SerializationInterceptor(o, sessionFactory);
- }
-
- synchronized (proxies)
- {
- if (proxies.containsKey(clazz))
- {
- Factory proxy = (Factory)proxies.get(clazz);
- return proxy.newInstance(new Callback[]{callback, NoOp.INSTANCE });
- }
- }
- // create proxy to listen on writeReplace method calls
- Object proxy = Enhancer.create(clazz, new Class[]{EntitySerializer.class }, new CallbackFilter()
- {
-
- public int accept(Method method)
- {
- if (method.getName().equals("writeReplace"))
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
-
- }, new Callback[]{callback, NoOp.INSTANCE });
-
- // store proxy
- proxies.put(clazz, ((Factory)proxy).newInstance(new Callback[]{EmptyMethodInterceptor.INSTANCE, NoOp.INSTANCE }));
- return proxy;
- }
- catch (Throwable t)
- {
- log.warn(t.getMessage(), t);
- return o;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable
- {
-
- try
- {
- if (original == null)
- {
- return null;
- }
-
- if (processed.get() == null)
- {
- processed.set(new ArrayList<Object>());
- }
-
- // add to processed objects
- processed.get().add(original);
-
- if (original.getClass().isPrimitive())
- {
- return original;
- }
- else if (original.getClass().isArray())
- {
- // replace array entries with proxied ones
- Object[] array = (Object[]) original;
- for (int i = 0; i < array.length; i++)
- {
- array[i] = SerializationInterceptor.getEnhancedObject(array[i], sessionFactory);
- }
- return array;
- }
- else if (original instanceof Collection)
- {
- // replace collection entries with proxied ones
- Collection collection = (Collection) original;
- CollectionUtils.transform(collection, transformer(sessionFactory));
- return collection;
- }
- else if (original instanceof Map)
- {
- // replace map entries with proxied ones
- Map map = (Map) original;
- MapUtils.transformedMap(map, transformer(sessionFactory), transformer(sessionFactory));
- return map;
- }
- else if (original instanceof Set)
- {
- // replace set entries with proxied ones
- Set set = (Set) original;
- SetUtils.transformedSet(set, transformer(sessionFactory));
- return set;
- }
- else
- {
- // cycle on bean fields
- ReflectionUtils.doWithFields(original.getClass(), new ReflectionUtils.FieldCallback()
- {
-
- /**
- * {@inheritDoc}
- */
- public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException
- {
- // set field accessible
- field.setAccessible(true);
-
- // get original value
- Object oldValue = field.get(original);
-
- // get new value
- Object newValue = null;
-
- if (oldValue instanceof HibernateProxy || oldValue instanceof PersistentCollection)
- {
- // if this field is a hibernate proxy or a persistent collection store reference
- LazyReference lazyRef = new LazyReference();
- lazyRef.setFieldClassName(field.getType().getName());
- lazyRef.setClassName(original.getClass().getName());
- lazyRef.setFieldName(field.getName());
- // load id
- lazyRef.setId(sessionFactory.getClassMetadata(original.getClass()).getIdentifier(
- original,
- EntityMode.POJO));
-
- // get proxy for lazy
- newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory, lazyRef);
- }
- else
- {
- // get default proxy
- newValue = SerializationInterceptor.getEnhancedObject(oldValue, sessionFactory);
- }
-
- // if there is a variation store it
- if (newValue != oldValue)
- {
- field.set(original, newValue);
- }
- }
-
- });
- }
-
- return original;
-
- }
- catch (Throwable t)
- {
- log.error(t.getMessage(), t);
- return original;
- }
- }
-
- /**
- * Get transformer for collection, map or set injection of proxied objects
- * @param factory hibernate session factory
- * @return transformer
- */
- private Transformer transformer(SessionFactory factory)
- {
- return new Transformer()
- {
-
- public Object transform(Object input)
- {
- return SerializationInterceptor.getEnhancedObject(input, sessionFactory);
- }
-
- };
- }
-
-}
Copied: tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java (from rev 483, trunk/openutils-spring-rmibernate/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java)
===================================================================
--- tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java (rev 0)
+++ tags/openutils-spring-rmibernate-1.0.2/src/main/java/it/openutils/spring/rmibernate/server/aspects/SerializationInterceptor.java 2007-10-26 11:06:52 UTC (rev 485)
@@ -0,0 +1,371 @@
+package it.openutils.spring.rmibernate.server.aspects;
+
+import it.openutils.spring.rmibernate.server.aspects.util.EntitySerializer;
+import it.openutils.spring.rmibernate.shared.LazyReference;
+import it.openutils.spring.rmibernate.shared.managers.HibernateLazyService;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import net.sf.cglib.proxy.Callback;
+import net.sf.cglib.proxy.CallbackFilter;
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.Factory;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+import net.sf.cglib.proxy.NoOp;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.collections.SetUtils;
+import org.apache.commons.collections.Transformer;
+import org.hibernate.EntityMode;
+import org.hibernate.SessionFactory;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.collection.PersistentSet;
+import org.hibernate.proxy.HibernateProxy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.util.ReflectionUtils;
+
+
+/**
+ * Proxy object with {@link EntitySerializer} and Intercept writeReplace calls
+ * @author mmolaschi
+ * @version $Id$
+ */
+public class SerializationInterceptor implements MethodInterceptor
+{
+
+ private static ThreadLocal<List<Object>> processed = new ThreadLocal<List<Object>>();
+
+ private static ThreadLocal<HibernateLazyService> hibernateLazyService = new ThreadLocal<HibernateLazyService>();
+
+ private static Map<Class, Object> proxies = Collections.synchronizedMap(new HashMap<Class, Object>());
+
+ /**
+ * log
+ */
+ private static Logger log = LoggerFactory.getLogger(SerializationInterceptor.class);
+
+ /**
+ * non proxied object
+ */
+ private Object original;
+
+ /**
+ * hibernate sessionfactory
+ */
+ private SessionFactory sessionFactory;
+
+ /**
+ * Constructor
+ * @param o object to be proxied
+ * @param sessionFactory hibernate sessionfactory
+ */
+ private SerializationInterceptor(Object o, SessionFactory sessionFactory)
+ {
+ this.original = o;
+ this.sessionFactory = sessionFactory;
+ }
+
+ /**
+ * Cleans the processed beans cache
+ */
+ public static void clean()
+ {
+ processed.set(null);
+ }
+
+ /**
+ * Get proxy object intercepting writeReplace calls
+ * @param o object to be proxied
+ * @param sessionFactory hibernate sessionfactory
+ * @return proxied object
+ */
+ public static Object getEnhancedObject(Object o, SessionFactory sessionFactory)
+ {
+ return getEnhancedObject(o, sessionFactory, null);
+ }
+
+ /**
+ * Get proxy object intercepting writeReplace calls
+ * @param o object to be proxied
+ * @param sessionFactory hibernate sessionfactory
+ * @param lazyRef reference to a lazy field
+ * @return proxied object
+ */
+ public static Object getEnhancedObject(Object o, SessionFactory sessionFactory, LazyReference lazyRef)
+ {
+ if (o == null)
+ {
+ return null;
+ }
+
+ if (!(o instanceof HibernateProxy)
+ && !(o instanceof PersistentSet)
+ && processed.get() != null
+ && processed.get().contains(o))
+ {
+ return o;
+ }
+
+ if (o.getClass().getName().startsWith("java.") && !((o instanceof Collection) || (o instanceof Map)))
+ {
+ return o;
+ }
+
+ // check if there is an empty constructor
+ try
+ {
+ o.getClass().getConstructor(new Class[]{});
+ }
+ catch (NoSuchMethodException ex)
+ {
+ return o;
+ }
+
+ // check if object can be subclassed
+ if (Modifier.isFinal(o.getClass().getModifiers()))
+ {
+ return o;
+ }
+
+ try
+ {
+ // get class
+ Class clazz = o.getClass();
+
+ // if it is an hibernateproxy get superclass
+ if (o instanceof HibernateProxy)
+ {
+ clazz = o.getClass().getSuperclass();
+ if (clazz == null)
+ {
+ clazz = o.getClass().getInterfaces()[0];
+ }
+ }
+
+ Callback callback = null;
+
+ // if this is a lazy field user lazyreferenceaspect
+ if (lazyRef != null)
+ {
+ LazyReferenceAspect lra = new LazyReferenceAspect();
+ lra.setLazyReference(lazyRef);
+ callback = lra;
+ }
+ else
+ {
+ // user default interceptor
+ callback = new SerializationInterceptor(o, sessionFactory);
+ }
+
+ synchronized (proxies)
+ {
+ if (proxies.containsKey(clazz))
+ {
+ Factory proxy = (Factory) proxies.get(clazz);
+ return proxy.newInstance(new Callback[]{callback, NoOp.INSTANCE });
+ }
+ }
+ // create proxy to listen on writeReplace method calls
+ Object proxy = Enhancer.create(clazz, new Class[]{EntitySerializer.class }, new CallbackFilter()
+ {
+
+ public int accept(Method method)
+ {
+ if (method.getName().equals("writeReplace"))
+ {
+ return 0;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+
+ }, new Callback[]{callback, NoOp.INSTANCE });
+
+ // store proxy
+ proxies.put(clazz, ((Factory) proxy).newInstance(new Callback[]{
+ EmptyMethodInterceptor.INSTANCE,
+ NoOp.INSTANCE }));
+ return proxy;
+ }
+ catch (Throwable t)
+ {
+ log.warn(t.getMessage(), t);
+ return o;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable
+ {
+ try
+ {
+ if (original == null)
+ {
+ return null;
+ }
+
+ if (original.getClass().getName().startsWith("java.")
+ && !(original instanceof Collection)
+ || (original instanceof Map))
+ {
+ return original;
+ }
+
+ if (processed.get() == null)
+ {
+ processed.set(new ArrayList<Object>());
+ }
+
+ // add to processed objects
+ processed.get().add(original);
+
+ if (original.getClass().isPrimitive())
+ {
+ log.debug("Non enhancing primitive type: {}", original.getClass().getName());
+ return original;
+ }
+ else if (original.getClass().isArray())
+ {
+ // replace array entries with proxied ones
+ Object[] array = (Object[]) original;
+ for (int i = 0; i < array.length; i++)
+ {
+ array[i] = SerializationInterceptor.getEnhancedObject(array[i], sessionFactory);
+ }
+ return array;
+ }
+ else if (original instanceof Set)
+ {
+ // replace set entries with proxied ones
+ Set set = (Set) original;
+ SetUtils.transformedSet(set, transformer(sessionFactory));
+ return set;
+ }
+ else if (original instanceof Collection)
+ {
+ // replace collection entries with proxied ones
+ Collection collection = (Collection) original;
+ CollectionUtils.transform(collection, transformer(sessionFactory));
+ return collection;
+ }
+ else if (original instanceof Map)
+ {
+ // replace map entries with proxied ones
+ Map map = (Map) original;
+ MapUtils.transformedMap(map, transformer(sessionFactory), transformer(sessionFactory));
+ return map;
+ }
+ else
+ {
+ // cycle on bean fields
+ ReflectionUtils.doWithFields(original.getClass(), new ReflectionUtils.FieldCallback()
+ {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException
+ {
+ // set field accessible
+ field.setAccessible(true);
+
+ // get original value
+ Object oldValue = field.get(original);
+
+ // get new value
+ Object newValue = null;
+
+ if (oldValue instanceof HibernateProxy || oldValue instanceof PersistentCollection)
+ {
+ // if this field is a hibernate proxy or a persistent collection store reference
+ LazyReference lazyRef = new LazyReference();
+ lazyRef.setFieldClassName(field.getType().getName());
+ lazyRef.setClassName(original.getClass().getName());
+ lazyRef.setFieldName(field.getName());
+ // load id
+ lazyRef.setId(sessionFactory.getClassMetadata(original.getClass()).getIdentifier(
+ original,
+ EntityMode.POJO));
+
+ // get proxy for lazy
+ newValue = SerializationInt...
[truncated message content] |