You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2013/04/30 09:57:42 UTC
svn commit: r1477500 -
/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
Author: rmannibucau
Date: Tue Apr 30 07:57:42 2013
New Revision: 1477500
URL: http://svn.apache.org/r1477500
Log:
emf should be serializable because CDI TCKs needs it
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java?rev=1477500&r1=1477499&r2=1477500&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java Tue Apr 30 07:57:42 2013
@@ -35,6 +35,7 @@ import org.apache.openejb.monitoring.Loc
import org.apache.openejb.monitoring.ObjectNameBuilder;
import org.apache.openejb.persistence.PersistenceUnitInfoImpl;
import org.apache.openejb.persistence.QueryLogEntityManager;
+import org.apache.openejb.spi.ContainerSystem;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
@@ -49,6 +50,7 @@ import javax.management.openmbean.Simple
import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;
+import javax.naming.NamingException;
import javax.persistence.Cache;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -63,6 +65,9 @@ import javax.xml.bind.Marshaller;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
@@ -71,7 +76,7 @@ import java.util.Properties;
import java.util.concurrent.TimeUnit;
@Internal
-public class ReloadableEntityManagerFactory implements EntityManagerFactory {
+public class ReloadableEntityManagerFactory implements EntityManagerFactory, Serializable {
private static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB, ReloadableEntityManagerFactory.class);
public static final String JAVAX_PERSISTENCE_SHARED_CACHE_MODE = "javax.persistence.sharedCache.mode";
@@ -81,7 +86,7 @@ public class ReloadableEntityManagerFact
public static final String OPENEJB_JPA_CRITERIA_LOG_JPQL = "openejb.jpa.criteria.log.jpql";
public static final String OPENEJB_JPA_CRITERIA_LOG_JPQL_LEVEL = "openejb.jpa.criteria.log.jpql.level";
- private final PersistenceUnitInfoImpl unitInfoImpl;
+ private PersistenceUnitInfoImpl unitInfoImpl;
private ClassLoader classLoader;
private EntityManagerFactory delegate;
private EntityManagerFactoryCallable entityManagerFactoryCallable;
@@ -417,6 +422,10 @@ public class ReloadableEntityManagerFact
return entityManagerFactoryCallable.getUnitInfo().excludeUnlistedClasses();
}
+ Object writeReplace() throws ObjectStreamException {
+ return new SerializableEm("java:" + Assembler.PERSISTENCE_UNIT_NAMING_CONTEXT + unitInfoImpl.getId());
+ }
+
@MBean
@Internal
@Description("represents a persistence unit managed by OpenEJB")
@@ -688,4 +697,20 @@ public class ReloadableEntityManagerFact
}
}
}
+
+ private static final class SerializableEm implements Serializable {
+ private String jndiName;
+
+ private SerializableEm(final String jndiName) {
+ this.jndiName = jndiName;
+ }
+
+ Object readResolve() throws ObjectStreamException {
+ try {
+ return SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext().lookup(jndiName);
+ } catch (final NamingException e) {
+ throw new InvalidObjectException(e.getMessage());
+ }
+ }
+ }
}