@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // if no instance yet exists for the current thread then look one up // and stash it if (this.get() == null) { Context ctx = new InitialContext(); T t = (T) ctx.lookup(name); this.set(t); } return super.invoke(proxy,method,args); } }
@Override public Injectable<EntityManagerFactory> getInjectable(ComponentContext ic, PersistenceUnit pu, Type c) { if (!c.equals(EntityManagerFactory.class)) return null; // TODO localize error message if (!persistenceUnits.containsKey(pu.unitName())) throw new ContainerException("Persistence unit '"+ pu.unitName()+ "' is not configured as a servlet parameter in web.xml"); String jndiName = persistenceUnits.get(pu.unitName()); ThreadLocalNamedInvoker<EntityManagerFactory> emfHandler = new ThreadLocalNamedInvoker<EntityManagerFactory>(jndiName); final EntityManagerFactory emf = (EntityManagerFactory) Proxy.newProxyInstance( this.getClass().getClassLoader(), new Class[] { EntityManagerFactory.class }, emfHandler); return new Injectable<EntityManagerFactory>() { @Override public EntityManagerFactory getValue() { return emf; } }; } });
@Override public Injectable<EntityManagerFactory> getInjectable(ComponentContext ic, PersistenceUnit pu, Type c) { if (!c.equals(EntityManagerFactory.class)) return null; // TODO localize error message if (!persistenceUnits.containsKey(pu.unitName())) throw new ContainerException("Persistence unit '"+ pu.unitName()+ "' is not configured as a servlet parameter in web.xml"); String jndiName = persistenceUnits.get(pu.unitName()); ThreadLocalNamedInvoker<EntityManagerFactory> emfHandler = new ThreadLocalNamedInvoker<EntityManagerFactory>(jndiName); final EntityManagerFactory emf = (EntityManagerFactory) Proxy.newProxyInstance( this.getClass().getClassLoader(), new Class[] { EntityManagerFactory.class }, emfHandler); return new Injectable<EntityManagerFactory>() { @Override public EntityManagerFactory getValue() { return emf; } }; } });
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // if no instance yet exists for the current thread then look one up // and stash it if (this.get() == null) { Context ctx = new InitialContext(); T t = (T) ctx.lookup(name); this.set(t); } return super.invoke(proxy,method,args); } }
@Override public Injectable<EntityManagerFactory> getInjectable(ComponentContext ic, PersistenceUnit pu, Type c) { if (!c.equals(EntityManagerFactory.class)) return null; // TODO localize error message if (!persistenceUnits.containsKey(pu.unitName())) throw new ContainerException("Persistence unit '"+ pu.unitName()+ "' is not configured as a servlet parameter in web.xml"); String jndiName = persistenceUnits.get(pu.unitName()); ThreadLocalNamedInvoker<EntityManagerFactory> emfHandler = new ThreadLocalNamedInvoker<EntityManagerFactory>(jndiName); final EntityManagerFactory emf = (EntityManagerFactory) Proxy.newProxyInstance( this.getClass().getClassLoader(), new Class[] { EntityManagerFactory.class }, emfHandler); return new Injectable<EntityManagerFactory>() { @Override public EntityManagerFactory getValue() { return emf; } }; } });
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // if no instance yet exists for the current thread then look one up // and stash it if (this.get() == null) { Context ctx = new InitialContext(); T t = (T) ctx.lookup(name); this.set(t); } return super.invoke(proxy,method,args); } }