Package org.hibernate

Examples of org.hibernate.Session.enableFilter()


    assertEquals("Incorrect orders count", 1, orders.size());

    log.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region and the product is effective as of last month");
    session.enableFilter("region").setParameter("region", "APAC");
    session.enableFilter("effectiveDate").setParameter("asOfDate", testData.lastMonth.getTime());

    DetachedCriteria productSubquery = DetachedCriteria.forClass(Product.class)
        .add(Restrictions.eq("name", "Acme Hair Gel"))
        .setProjection(Property.forName("id"));
View Full Code Here


    assertEquals("Incorrect orders count", 1, orders.size());


    log.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region and the product is effective as of 4 months ago");
    session.enableFilter("region").setParameter("region", "APAC");
    session.enableFilter("effectiveDate").setParameter("asOfDate", testData.fourMonthsAgo.getTime());

    orders = session.createCriteria(Order.class)
        .add(Subqueries.exists(lineItemSubquery))
        .add(Restrictions.eq("buyer", "gavin"))
View Full Code Here

    assertEquals("Incorrect orders count", 1, orders.size());


    log.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region and the product is effective as of 4 months ago");
    session.enableFilter("region").setParameter("region", "APAC");
    session.enableFilter("effectiveDate").setParameter("asOfDate", testData.fourMonthsAgo.getTime());

    orders = session.createCriteria(Order.class)
        .add(Subqueries.exists(lineItemSubquery))
        .add(Restrictions.eq("buyer", "gavin"))
        .list();
View Full Code Here

    log.info("Starting HQL subquery with filters tests");
    TestData testData = new TestData();
    testData.prepare();

    Session session = openSession();
    session.enableFilter("region").setParameter("region", "APAC");

    log.info("query against Department with a subquery on Salesperson in the APAC reqion...");

    List departments = session.createQuery("select d from Department as d where d.id in (select s.department from Salesperson s where s.name = ?)").setString(0, "steve").list();
View Full Code Here

    assertEquals("Incorrect department count", 1, departments.size());

    log.info("query against Department with a subquery on Salesperson in the FooBar reqion...");

    session.enableFilter("region").setParameter("region", "Foobar");
    departments = session.createQuery("select d from Department as d where d.id in (select s.department from Salesperson s where s.name = ?)").setString(0, "steve").list();

    assertEquals("Incorrect department count", 0, departments.size());

    log.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region for a given buyer");
View Full Code Here

    departments = session.createQuery("select d from Department as d where d.id in (select s.department from Salesperson s where s.name = ?)").setString(0, "steve").list();

    assertEquals("Incorrect department count", 0, departments.size());

    log.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region for a given buyer");
    session.enableFilter("region").setParameter("region", "APAC");

    List orders = session.createQuery("select o from Order as o where exists (select li.id from LineItem li, Product as p where p.id = li.product and li.quantity >= ? and p.name = ?) and o.buyer = ?")
        .setLong(0, 1L).setString(1, "Acme Hair Gel").setString(2, "gavin").list();

    assertEquals("Incorrect orders count", 1, orders.size());
View Full Code Here

    assertEquals("Incorrect orders count", 1, orders.size());

    log.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region and the product is effective as of last month");

    session.enableFilter("region").setParameter("region", "APAC");
    session.enableFilter("effectiveDate").setParameter("asOfDate", testData.lastMonth.getTime());

    orders = session.createQuery("select o from Order as o where exists (select li.id from LineItem li where li.quantity >= ? and li.product in (select p.id from Product p where p.name = ?)) and o.buyer = ?")
        .setLong(0, 1L).setString(1, "Acme Hair Gel").setString(2, "gavin").list();
View Full Code Here

    assertEquals("Incorrect orders count", 1, orders.size());

    log.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region and the product is effective as of last month");

    session.enableFilter("region").setParameter("region", "APAC");
    session.enableFilter("effectiveDate").setParameter("asOfDate", testData.lastMonth.getTime());

    orders = session.createQuery("select o from Order as o where exists (select li.id from LineItem li where li.quantity >= ? and li.product in (select p.id from Product p where p.name = ?)) and o.buyer = ?")
        .setLong(0, 1L).setString(1, "Acme Hair Gel").setString(2, "gavin").list();

    assertEquals("Incorrect orders count", 1, orders.size());
View Full Code Here

    assertEquals("Incorrect orders count", 1, orders.size());


    log.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region and the product is effective as of 4 months ago");

    session.enableFilter("region").setParameter("region", "APAC");
    session.enableFilter("effectiveDate").setParameter("asOfDate", testData.fourMonthsAgo.getTime());

    orders = session.createQuery("select o from Order as o where exists (select li.id from LineItem li where li.quantity >= ? and li.product in (select p.id from Product p where p.name = ?)) and o.buyer = ?")
        .setLong(0, 1L).setString(1, "Acme Hair Gel").setString(2, "gavin").list();
View Full Code Here


    log.info("query against Order with a subquery for line items with a subquery line items where the product name is Acme Hair Gel and the quantity is greater than 1 in a given region and the product is effective as of 4 months ago");

    session.enableFilter("region").setParameter("region", "APAC");
    session.enableFilter("effectiveDate").setParameter("asOfDate", testData.fourMonthsAgo.getTime());

    orders = session.createQuery("select o from Order as o where exists (select li.id from LineItem li where li.quantity >= ? and li.product in (select p.id from Product p where p.name = ?)) and o.buyer = ?")
        .setLong(0, 1L).setString(1, "Acme Hair Gel").setString(2, "gavin").list();

    assertEquals("Incorrect orders count", 0, orders.size());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.