Example usage for javax.persistence FetchType equals

List of usage examples for javax.persistence FetchType equals

Introduction

In this page you can find the example usage for javax.persistence FetchType equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.impetus.kundera.ejb.EntityResolver.java

/**
 * Helper method to load Foreign Entity/Proxy
 * /*  www. ja  v a  2  s. c  o  m*/
 * @param entityName
 *            the entity name
 * @param persistentClass
 *            the persistent class
 * @param foreignKey
 *            the foreign key
 * @param relation
 *            the relation
 * @return the foreign entity or proxy
 */
private Object getForeignEntityOrProxy(String entityName, Class<?> persistentClass, String foreignKey,
        EntityMetadata.Relation relation) {

    // Check in session cache!
    Object cached = em.getSession().lookup(persistentClass, foreignKey);
    if (cached != null) {
        return cached;
    }

    FetchType fetch = relation.getFetchType();

    if (fetch.equals(FetchType.EAGER)) {
        log.debug("Eagerly loading >> " + persistentClass.getName() + "_" + foreignKey);
        // load target eagerly!
        return em.immediateLoadAndCache(persistentClass, foreignKey);
    } else {
        log.debug("Creating proxy for >> " + persistentClass.getName() + "#" + relation.getProperty().getName()
                + "_" + foreignKey);

        // metadata
        EntityMetadata m = em.getMetadataManager().getEntityMetadata(persistentClass);

        return em.getFactory().getLazyEntity(entityName, persistentClass, m.getReadIdentifierMethod(),
                m.getWriteIdentifierMethod(), foreignKey, em);
    }
}