// Path: croquet-core/src/main/java/com/metrink/croquet/inject/IWriteReplace.java
// public interface IWriteReplace {
// 
//     /**
//      * Write replace method.
//      * @return the new object.
//      * @throws ObjectStreamException .
//      */
//     Object writeReplace() throws ObjectStreamException;
// }


import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Arrays;
import javax.persistence.EntityManager;
import net.sf.cglib.core.DefaultNamingPolicy;
import net.sf.cglib.core.Predicate;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.hibernate.jpa.HibernateEntityManagerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.metrink.croquet.inject.IWriteReplace;
package com.metrink.croquet.hibernate;






/**
 * Factory class that generates a proxy instance for {@link EntityManager}s.
 */
class EntityManagerProxyFactory {
    private static final Logger LOG = LoggerFactory.getLogger(EntityManagerProxyFactory.class);

    private EntityManagerProxyFactory() { }

    /**
     * Creates a proxy object that will write-replace with a wrapper around the {@link EntityManager}.
     * @param factory a factory to generate EntityManagers.
     * @return the proxied instance.
     */
    static EntityManager createProxy(final HibernateEntityManagerFactory factory) {
        final EntityManagerInterceptor handler = new EntityManagerInterceptor(factory);

        final Enhancer e = new Enhancer();

        // make sure we're Serializable and have a write replace method
// Path: croquet-core/src/main/java/com/metrink/croquet/inject/IWriteReplace.java
// public interface IWriteReplace {
// 
//     /**
//      * Write replace method.
//      * @return the new object.
//      * @throws ObjectStreamException .
//      */
//     Object writeReplace() throws ObjectStreamException;
// }


// Path: croquet-core/src/main/java/com/metrink/croquet/hibernate/EntityManagerProxyFactory.java
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Arrays;
import javax.persistence.EntityManager;
import net.sf.cglib.core.DefaultNamingPolicy;
import net.sf.cglib.core.Predicate;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.hibernate.jpa.HibernateEntityManagerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.metrink.croquet.inject.IWriteReplace;

package com.metrink.croquet.hibernate;






/**
 * Factory class that generates a proxy instance for {@link EntityManager}s.
 */
class EntityManagerProxyFactory {
    private static final Logger LOG = LoggerFactory.getLogger(EntityManagerProxyFactory.class);

    private EntityManagerProxyFactory() { }

    /**
     * Creates a proxy object that will write-replace with a wrapper around the {@link EntityManager}.
     * @param factory a factory to generate EntityManagers.
     * @return the proxied instance.
     */
    static EntityManager createProxy(final HibernateEntityManagerFactory factory) {
        final EntityManagerInterceptor handler = new EntityManagerInterceptor(factory);

        final Enhancer e = new Enhancer();

        // make sure we're Serializable and have a write replace method
        e.setInterfaces(new Class[] { EntityManager.class, Serializable.class, IWriteReplace.class });