Package com.enioka.jqm.jpamodel

Examples of com.enioka.jqm.jpamodel.JndiObjectResource


        }
    }

    private static JndiResourceDescriptor fromDatabase(String alias) throws NamingException
    {
        JndiObjectResource resource = null;
        EntityManager em = null;
        try
        {
            // Using the horrible CriteriaBuilder API instead of a string query. This avoids classloading issues - Hibernate binds
            // the entities at run time with the thread current classloader...
            em = Helpers.getNewEm();

            CriteriaBuilder cb = em.getCriteriaBuilder();
            CriteriaQuery<JndiObjectResource> q = cb.createQuery(JndiObjectResource.class);
            Root<JndiObjectResource> c = q.from(JndiObjectResource.class);
            ParameterExpression<String> p = cb.parameter(String.class);
            q.select(c).where(cb.equal(c.get("name"), p));

            TypedQuery<JndiObjectResource> query = em.createQuery(q);
            query.setParameter(p, alias);
            resource = query.getSingleResult();
        }
        catch (Exception e)
        {
            NamingException ex = new NamingException("Could not find a JNDI object resource of name " + alias);
            ex.setRootCause(e);
            throw ex;
        }
        finally
        {
            if (em != null)
            {
                em.close();
            }
        }

        // Create the ResourceDescriptor from the JPA object
        JndiResourceDescriptor d = new JndiResourceDescriptor(resource.getType(), resource.getDescription(), null, resource.getAuth(),
                resource.getFactory(), resource.getSingleton());
        for (JndiObjectResourceParameter prm : resource.getParameters())
        {
            d.add(new StringRefAddr(prm.getKey(), prm.getValue()));
        }

        return d;
View Full Code Here


    // ------------------ JNDI FOR JMS & co --------------------------------
    public static JndiObjectResource createJndiObjectResource(EntityManager em, String jndiAlias, String className, String factoryClass,
            String description, boolean singleton, HashMap<String, String> parameters)
    {
        JndiObjectResource res = new JndiObjectResource();
        res.setAuth(null);
        res.setDescription(description);
        res.setFactory(factoryClass);
        res.setName(jndiAlias);
        res.setType(className);
        res.setSingleton(singleton);
        em.persist(res);

        for (String parameterName : parameters.keySet())
        {
            JndiObjectResourceParameter prm = new JndiObjectResourceParameter();
            prm.setKey(parameterName);
            prm.setValue(parameters.get(parameterName));
            em.persist(prm);
            res.getParameters().add(prm);
            prm.setResource(res);
        }

        return res;
    }
View Full Code Here

TOP

Related Classes of com.enioka.jqm.jpamodel.JndiObjectResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.