// Path: spi/src/main/java/org/jipijapa/management/spi/EntityManagerFactoryAccess.java
// public interface EntityManagerFactoryAccess {
//     /**
//      * returns the entity manager factory that statistics should be obtained for.
//      *
//      * @throws IllegalStateException if scopedPersistenceUnitName is not found
//      *
//      * @param scopedPersistenceUnitName is persistence unit name scoped to the current platform
//      *
//      * @return EntityManagerFactory
//      */
//     EntityManagerFactory entityManagerFactory(String scopedPersistenceUnitName) throws IllegalStateException;
// 
// }
// 
// Path: spi/src/main/java/org/jipijapa/management/spi/Operation.java
// public interface Operation {
// 
//     /**
//      * Invoke operation
//      * @param args will be passed to invoked operation
//      * @return
//      */
//     Object invoke(Object... args);
// }
// 
// Path: spi/src/main/java/org/jipijapa/management/spi/PathAddress.java
// public interface PathAddress {
// 
//     int size();
// 
//     String getValue(String name);
//     String getValue(int index);
// }


import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import javax.persistence.EntityManagerFactory;
import org.hibernate.SessionFactory;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.jipijapa.management.spi.EntityManagerFactoryAccess;
import org.jipijapa.management.spi.Operation;
import org.jipijapa.management.spi.PathAddress;
        types.put(OPERATION_SECOND_LEVEL_CACHE_SIZE_IN_MEMORY, Long.class);

    }

    @Override
    public Collection<String> getDynamicChildrenNames(EntityManagerFactoryAccess entityManagerFactoryLookup, PathAddress pathAddress) {
        return Collections.unmodifiableCollection(Arrays.asList(
                getBaseStatistics(entityManagerFactoryLookup.entityManagerFactory(pathAddress.getValue(HibernateStatistics.PROVIDER_LABEL))).getEntityNames()));
    }

    private org.hibernate.stat.Statistics getBaseStatistics(EntityManagerFactory entityManagerFactory) {
        HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
        SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
        if (sessionFactory != null) {
            return sessionFactory.getStatistics();
        }
        return null;
    }

    org.hibernate.stat.SecondLevelCacheStatistics getStatistics(EntityManagerFactoryAccess entityManagerFactoryaccess, PathAddress pathAddress) {
        String scopedPersistenceUnitName = pathAddress.getValue(HibernateStatistics.PROVIDER_LABEL);
        HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactoryaccess.entityManagerFactory(scopedPersistenceUnitName);
        SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
        if (sessionFactory != null) {
            // The entity class name is prefixed by the application scoped persistence unit name
            return sessionFactory.getStatistics().getSecondLevelCacheStatistics(scopedPersistenceUnitName + "." +
                    pathAddress.getValue(HibernateStatistics.ENTITYCACHE));
        }
        return null;
    }
// Path: spi/src/main/java/org/jipijapa/management/spi/EntityManagerFactoryAccess.java
// public interface EntityManagerFactoryAccess {
//     /**
//      * returns the entity manager factory that statistics should be obtained for.
//      *
//      * @throws IllegalStateException if scopedPersistenceUnitName is not found
//      *
//      * @param scopedPersistenceUnitName is persistence unit name scoped to the current platform
//      *
//      * @return EntityManagerFactory
//      */
//     EntityManagerFactory entityManagerFactory(String scopedPersistenceUnitName) throws IllegalStateException;
// 
// }
// 
// Path: spi/src/main/java/org/jipijapa/management/spi/Operation.java
// public interface Operation {
// 
//     /**
//      * Invoke operation
//      * @param args will be passed to invoked operation
//      * @return
//      */
//     Object invoke(Object... args);
// }
// 
// Path: spi/src/main/java/org/jipijapa/management/spi/PathAddress.java
// public interface PathAddress {
// 
//     int size();
// 
//     String getValue(String name);
//     String getValue(int index);
// }


// Path: hibernate4_1/src/main/java/org/jboss/as/jpa/hibernate4/management/HibernateEntityCacheStatistics.java
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import javax.persistence.EntityManagerFactory;
import org.hibernate.SessionFactory;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.jipijapa.management.spi.EntityManagerFactoryAccess;
import org.jipijapa.management.spi.Operation;
import org.jipijapa.management.spi.PathAddress;

        types.put(OPERATION_SECOND_LEVEL_CACHE_SIZE_IN_MEMORY, Long.class);

    }

    @Override
    public Collection<String> getDynamicChildrenNames(EntityManagerFactoryAccess entityManagerFactoryLookup, PathAddress pathAddress) {
        return Collections.unmodifiableCollection(Arrays.asList(
                getBaseStatistics(entityManagerFactoryLookup.entityManagerFactory(pathAddress.getValue(HibernateStatistics.PROVIDER_LABEL))).getEntityNames()));
    }

    private org.hibernate.stat.Statistics getBaseStatistics(EntityManagerFactory entityManagerFactory) {
        HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactory;
        SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
        if (sessionFactory != null) {
            return sessionFactory.getStatistics();
        }
        return null;
    }

    org.hibernate.stat.SecondLevelCacheStatistics getStatistics(EntityManagerFactoryAccess entityManagerFactoryaccess, PathAddress pathAddress) {
        String scopedPersistenceUnitName = pathAddress.getValue(HibernateStatistics.PROVIDER_LABEL);
        HibernateEntityManagerFactory entityManagerFactoryImpl = (HibernateEntityManagerFactory) entityManagerFactoryaccess.entityManagerFactory(scopedPersistenceUnitName);
        SessionFactory sessionFactory = entityManagerFactoryImpl.getSessionFactory();
        if (sessionFactory != null) {
            // The entity class name is prefixed by the application scoped persistence unit name
            return sessionFactory.getStatistics().getSecondLevelCacheStatistics(scopedPersistenceUnitName + "." +
                    pathAddress.getValue(HibernateStatistics.ENTITYCACHE));
        }
        return null;
    }
    private Operation getEntityCacheRegionName = new Operation() {