// Path: hibernate/src/main/java/net/sf/beanlib/hibernate5/Hibernate5BeanReplicator.java
// public class Hibernate5BeanReplicator extends HibernateBeanReplicator {
// 
//     /**
//      * By default, all properties will be included for replication.
//      */
//     public Hibernate5BeanReplicator() {
//         super(new Hibernate5BeanTransformer().initPropertyFilter(new HibernatePropertyFilter()));
//     }
// 
//     /**
//      * Constructs with an application package prefix.
//      *
//      * @param applicationPackagePrefix An application package prefix used to determine if a property with a type of an
//      *            entity bean class will be included for replication.
//      */
//     public Hibernate5BeanReplicator(String applicationPackagePrefix) {
//         super(new Hibernate5BeanTransformer().initPropertyFilter(new HibernatePropertyFilter(applicationPackagePrefix)));
//     }
// 
//     /**
//      * Convenient constructor to specify:
//      * <ol>
//      * <li>The set of entity bean classes for matching properties that will be replicated;</li>
//      * <li>The set of collection and map properties that will be replicated;</li>
//      * <li>A {@link PropertyFilter vetoer} used to veto the propagation of specific properties</li>
//      * </ol>
//      * <p>
//      * Note this constructor is relevant only if the default property filter {@link HibernatePropertyFilter} is used.
//      *
//      * @param entityBeanClassSet The set of entity bean classes for matching properties that will be replicated, eagerly
//      *            fetching if necessary. Null means all whereas empty means none.
//      * @param collectionPropertyNameSet The set of collection and map properties that will be replicated, eagerly
//      *            fetching if necessary. Null means all whereas empty means none.
//      * @param vetoer used to veto the propagation of specific properties.
//      */
//     public Hibernate5BeanReplicator(Set<Class<?>> entityBeanClassSet, Set<? extends CollectionPropertyName<?>> collectionPropertyNameSet,
//             PropertyFilter vetoer) {
//         super(new Hibernate5BeanTransformer().initPropertyFilter(new HibernatePropertyFilter().withEntityBeanClassSet(entityBeanClassSet)
//                 .withCollectionPropertyNameSet(collectionPropertyNameSet).withVetoer(vetoer)));
//     }
// 
//     /**
//      * Convenient constructor to specify:
//      * <ol>
//      * <li>An application package prefix used to determine if a property with a type of an entity bean class will be
//      * included for replication;</li>
//      * <li>The set of entity bean classes for matching properties that will be replicated;</li>
//      * <li>The set of collection and map properties that will be replicated;</li>
//      * <li>A {@link PropertyFilter vetoer} used to veto the propagation of specific properties</li>
//      * </ol>
//      * <p>
//      * Note this constructor is relevant only if the default property filter {@link HibernatePropertyFilter} is used.
//      *
//      * @param entityBeanClassSet The set of entity bean classes for matching properties that will be replicated, eagerly
//      *            fetching if necessary. Null means all whereas empty means none.
//      * @param collectionPropertyNameSet The set of collection and map properties that will be replicated, eagerly
//      *            fetching if necessary. Null means all whereas empty means none.
//      * @param vetoer used to veto the propagation of specific properties.
//      */
//     public Hibernate5BeanReplicator(String applicationPackagePrefix, Set<Class<?>> entityBeanClassSet,
//             Set<? extends CollectionPropertyName<?>> collectionPropertyNameSet, PropertyFilter vetoer) {
//         super(new Hibernate5BeanTransformer().initPropertyFilter(new HibernatePropertyFilter(applicationPackagePrefix)
//                 .withEntityBeanClassSet(entityBeanClassSet).withCollectionPropertyNameSet(collectionPropertyNameSet).withVetoer(vetoer)));
//     }
// }
// 
// Path: core/src/main/java/net/sf/beanlib/spi/PropertyFilter.java
// public interface PropertyFilter {
// 
//     /**
//      * Returns true if the given JavaBean property should be propagated; false otherwise.
//      *
//      * @param propertyName JavaBean property name.
//      * @param readerMethod reader method of the JavaBean property name.
//      * @return true if the given JavaBean property should be propagated.
//      */
//     boolean propagate(String propertyName, Method readerMethod);
// }


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Method;
import java.util.Collection;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import net.sf.beanlib.hibernate5.Hibernate5BeanReplicator;
import net.sf.beanlib.spi.PropertyFilter;
        // f.addSupplier(mac);

        f.setAddress("main street");

        this.session.save(f);
        this.id = f.getId();
        this.session.flush();

        beginTransaction.commit();
        // this.session.connection().commit();
        this.session.close();
    }

    @Test
    public void load() throws Exception {
        this.session = this.sessionFactory.openSession();
        final Factory load = this.session.load(Factory.class, this.id); // (long) 350);

        System.out.println("factory " + load);
        final Collection<Supplier> suppliers = load.getSuppliers();
        final Collection<Contract> contracts = load.getContracts();
        assertEquals(1, load.getSuppliers().size());
        for (final Contract contract : contracts) {
            final Supplier supplier = contract.getSupplier();
            assertTrue(suppliers.contains(supplier));
            supplier.setName("hello");
            assertEquals(supplier.getName(), suppliers.iterator().next().getName());
        }

        final Hibernate5BeanReplicator r = new Hibernate5BeanReplicator();
// Path: hibernate/src/main/java/net/sf/beanlib/hibernate5/Hibernate5BeanReplicator.java
// public class Hibernate5BeanReplicator extends HibernateBeanReplicator {
// 
//     /**
//      * By default, all properties will be included for replication.
//      */
//     public Hibernate5BeanReplicator() {
//         super(new Hibernate5BeanTransformer().initPropertyFilter(new HibernatePropertyFilter()));
//     }
// 
//     /**
//      * Constructs with an application package prefix.
//      *
//      * @param applicationPackagePrefix An application package prefix used to determine if a property with a type of an
//      *            entity bean class will be included for replication.
//      */
//     public Hibernate5BeanReplicator(String applicationPackagePrefix) {
//         super(new Hibernate5BeanTransformer().initPropertyFilter(new HibernatePropertyFilter(applicationPackagePrefix)));
//     }
// 
//     /**
//      * Convenient constructor to specify:
//      * <ol>
//      * <li>The set of entity bean classes for matching properties that will be replicated;</li>
//      * <li>The set of collection and map properties that will be replicated;</li>
//      * <li>A {@link PropertyFilter vetoer} used to veto the propagation of specific properties</li>
//      * </ol>
//      * <p>
//      * Note this constructor is relevant only if the default property filter {@link HibernatePropertyFilter} is used.
//      *
//      * @param entityBeanClassSet The set of entity bean classes for matching properties that will be replicated, eagerly
//      *            fetching if necessary. Null means all whereas empty means none.
//      * @param collectionPropertyNameSet The set of collection and map properties that will be replicated, eagerly
//      *            fetching if necessary. Null means all whereas empty means none.
//      * @param vetoer used to veto the propagation of specific properties.
//      */
//     public Hibernate5BeanReplicator(Set<Class<?>> entityBeanClassSet, Set<? extends CollectionPropertyName<?>> collectionPropertyNameSet,
//             PropertyFilter vetoer) {
//         super(new Hibernate5BeanTransformer().initPropertyFilter(new HibernatePropertyFilter().withEntityBeanClassSet(entityBeanClassSet)
//                 .withCollectionPropertyNameSet(collectionPropertyNameSet).withVetoer(vetoer)));
//     }
// 
//     /**
//      * Convenient constructor to specify:
//      * <ol>
//      * <li>An application package prefix used to determine if a property with a type of an entity bean class will be
//      * included for replication;</li>
//      * <li>The set of entity bean classes for matching properties that will be replicated;</li>
//      * <li>The set of collection and map properties that will be replicated;</li>
//      * <li>A {@link PropertyFilter vetoer} used to veto the propagation of specific properties</li>
//      * </ol>
//      * <p>
//      * Note this constructor is relevant only if the default property filter {@link HibernatePropertyFilter} is used.
//      *
//      * @param entityBeanClassSet The set of entity bean classes for matching properties that will be replicated, eagerly
//      *            fetching if necessary. Null means all whereas empty means none.
//      * @param collectionPropertyNameSet The set of collection and map properties that will be replicated, eagerly
//      *            fetching if necessary. Null means all whereas empty means none.
//      * @param vetoer used to veto the propagation of specific properties.
//      */
//     public Hibernate5BeanReplicator(String applicationPackagePrefix, Set<Class<?>> entityBeanClassSet,
//             Set<? extends CollectionPropertyName<?>> collectionPropertyNameSet, PropertyFilter vetoer) {
//         super(new Hibernate5BeanTransformer().initPropertyFilter(new HibernatePropertyFilter(applicationPackagePrefix)
//                 .withEntityBeanClassSet(entityBeanClassSet).withCollectionPropertyNameSet(collectionPropertyNameSet).withVetoer(vetoer)));
//     }
// }
// 
// Path: core/src/main/java/net/sf/beanlib/spi/PropertyFilter.java
// public interface PropertyFilter {
// 
//     /**
//      * Returns true if the given JavaBean property should be propagated; false otherwise.
//      *
//      * @param propertyName JavaBean property name.
//      * @param readerMethod reader method of the JavaBean property name.
//      * @return true if the given JavaBean property should be propagated.
//      */
//     boolean propagate(String propertyName, Method readerMethod);
// }


// Path: hibernate/src/test/java/elh/maayan/test/TestRep.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Method;
import java.util.Collection;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import net.sf.beanlib.hibernate5.Hibernate5BeanReplicator;
import net.sf.beanlib.spi.PropertyFilter;

        // f.addSupplier(mac);

        f.setAddress("main street");

        this.session.save(f);
        this.id = f.getId();
        this.session.flush();

        beginTransaction.commit();
        // this.session.connection().commit();
        this.session.close();
    }

    @Test
    public void load() throws Exception {
        this.session = this.sessionFactory.openSession();
        final Factory load = this.session.load(Factory.class, this.id); // (long) 350);

        System.out.println("factory " + load);
        final Collection<Supplier> suppliers = load.getSuppliers();
        final Collection<Contract> contracts = load.getContracts();
        assertEquals(1, load.getSuppliers().size());
        for (final Contract contract : contracts) {
            final Supplier supplier = contract.getSupplier();
            assertTrue(suppliers.contains(supplier));
            supplier.setName("hello");
            assertEquals(supplier.getName(), suppliers.iterator().next().getName());
        }

        final Hibernate5BeanReplicator r = new Hibernate5BeanReplicator();
        r.initPropertyFilter(new PropertyFilter() {