Example usage for javax.persistence EntityManager toString

List of usage examples for javax.persistence EntityManager toString

Introduction

In this page you can find the example usage for javax.persistence EntityManager toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.github.fharms.camel.entitymanager.CamelEntityManagerHandler.java

private <T> T createEntityManagerProxy(Class<T> interfaceClass, Object emProxy) {
    InvocationHandler handler = (proxy, method, args) -> {

        EntityManager em = entityManagerLocal.get() != null ? entityManagerLocal.get()
                : (EntityManager) emProxy;
        switch (method.getName()) {
        case "hashCode":
            return hashCode();
        case "equals":
            return (em == args[0]);
        case "toString":
            return "Camel EntityManager proxy [" + em.toString() + "]";
        }//  w ww.j ava 2 s  . c  o  m

        if (!em.isJoinedToTransaction()) {
            em.joinTransaction();
        }
        return method.invoke(em, args);
    };
    return (T) Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[] { interfaceClass }, handler);
}