All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gvnix.web.datatables.util.EntityManagerProviderImpl Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2015 DISID Corporation S.L. All rights reserved.
 *
 * Project  : [PROJECT NAME]
 * SVN Id   : $Id$
 */
package org.gvnix.web.datatables.util;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import javax.persistence.EntityManager;

import org.springframework.stereotype.Service;

/**
 * Service which provides EntityManager instance for a JPA Entity class from a
 * ActiveRecord Spring-Roo entity
 * 
 * @author gvNIX Team
 * @deprecated use
 *             {@link org.gvnix.web.datatables.util.impl.EntityManagerProviderImpl}
 */
@Service
public class EntityManagerProviderImpl implements EntityManagerProvider {

    /* (non-Javadoc)
     * @see org.gvnix.web.datatables.util.EntityManagerProvider#getEntityManager(java.lang.Class)
     */
    public EntityManager getEntityManager(Class klass) {

        try {
            Method[] methods = klass.getMethods();

            for (Method method : methods) {
                if ((method.getModifiers() & Modifier.STATIC) != 0) {
                    if (method.getReturnType() == EntityManager.class) {
                        method.setAccessible(true);
                        return (EntityManager) method.invoke(null, null);
                    }
                }
            }
        }
        catch (Exception e) {
            throw new IllegalStateException(
                    "Error getting entity manager for domain class: ".concat(klass
                            .getName()), e);
        }
        throw new IllegalStateException(
                "Cannot get entity manager for domain class: ".concat(klass
                        .getName()));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy