Package javax.persistence

Examples of javax.persistence.Query


     * @return the list of results.
     */
    public List findLifecycleEventByEntity(final String className, final CallbackType callbackEvent,
            final int entityId) {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Query query = entityManager.createQuery("SELECT e FROM ListenerManager "
                + "e WHERE e.className = :className AND e.callbackEvent= :event AND e.entityId = :entityId");
        query.setParameter("className", className);
        query.setParameter("event", callbackEvent);
        query.setParameter("entityId", new Integer(entityId));
        return query.getResultList();
    }
View Full Code Here


    /**
     * Verifies if the inner join works.
     */
    public void testInnerJoin() {
        startup();
        Query query = entityManager
                .createQuery("SELECT p.category FROM ProductOrder po JOIN po.products p WHERE po.id BETWEEN ?1 AND  ?2");
        query.setParameter(1, new Long(0));
        query.setParameter(2, new Long(NUMBER_OF_ORDERS));
        List lstCategory = query.getResultList();
        assertEquals(lstCategory.size(), NUMBER_OF_ORDERS / 2, "The inner join does not work properly");
    }
View Full Code Here

    /**
     * Verifies if the container can manage the query with is empty.
     */
    public void testIsEmpty() {
        startup();
        Query query = entityManager.createQuery("SELECT po FROM ProductOrder po  WHERE po.products IS EMPTY");
        List lstProductOrder = query.getResultList();
        for (Object obj : lstProductOrder) {
            ProductOrder order = (ProductOrder) obj;
            assertEquals(order.getId(), 0, "The query result is incorrect.");
        }
    }
View Full Code Here

    /**
     * Verifies if the container can make a bulk operation delete.
     */
    public void testDelete() {
        startup();
        Query query = entityManager.createQuery("DELETE FROM Customer c  WHERE  c.id > 2");
        query.executeUpdate();
        entityManager.flush();
        Query queryTest = entityManager.createQuery("SELECT c FROM Customer c");
        List lstCustomer = queryTest.getResultList();
        for (Object obj : lstCustomer) {
            Customer customer = (Customer) obj;
            assertTrue(customer.getId() <= 2, "The operation delete does not work.");
        }
    }
View Full Code Here

    /**
     * Verifies if the container can make a bulk operation update.
     */
    public void testUpdate() {
        startup();
        Query query = entityManager.createQuery("UPDATE Address a SET a.country = 'Brazil' WHERE a.id =1");
        query.executeUpdate();
        entityManager.flush();
        testVerifyUpdate();
      }
View Full Code Here

    /**
     * Verifies if the clause having works properly.
     */
    public void testHaving() {
        startup();
        Query query = entityManager
                .createQuery("SELECT p.price, COUNT(p) FROM Product p GROUP BY p.price HAVING p.price > 2");
        query.getResultList();
    }
View Full Code Here

        // Checks if the size of descriptions is the same as eventClassNames.
        assertTrue(descriptions.length == eventClassNames.length,
                "The length of descriptions and event class names must be equal.");

        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Query query = entityManager.createQuery("SELECT e FROM OperationLogger "
                + "e WHERE e.className = :className AND e.callbackEvent= :event AND e.operationType = :operationType");
        query.setParameter("className", className);
        query.setParameter("event", event);
        query.setParameter("operationType", operationType);
        List callbackList = query.getResultList();

        assertTrue(callbackList.size() == eventClassNames.length,
                "The length of operations expected is different from the length of operations found.");

        // Sorts the events by date.
View Full Code Here

        }

        logger.debug("Finding: className={0}, callbackEvent={1}", className, callbackEvent);

        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Query query = entityManager.createNamedQuery("findLifecycleEvent");
        query.setParameter("className", className);
        query.setParameter("event", callbackEvent);


        List arFound = query.getResultList();
        for(int i = 0; i <  arFound.size(); i++){
            logger.debug("Found callback: {0}", arFound.get(i).toString());
        }

        return arFound;
View Full Code Here

     */
    public List findCallbackEvent(final String className) {
        logger.debug("Finding: className={0}", className);

        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Query query = entityManager.createNamedQuery("findLifecycleEventByClass");
        query.setParameter("className", className);
        return query.getResultList();
    }
View Full Code Here

     * @return the list of results.
     */
    public List findCallbackEventByCallbackMethod(final String className, final CallbackType callbackEvent,
            final String callbackClassName) {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Query query = entityManager.createNamedQuery("findLifecycleEventByCallbackMethod");
        query.setParameter("className", className);
        query.setParameter("event", callbackEvent);
        query.setParameter("callbackClassName", callbackClassName);
        return query.getResultList();
    }
View Full Code Here

TOP

Related Classes of javax.persistence.Query

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.