Package org.hibernate

Examples of org.hibernate.Session.enableFilter()


    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    TestData testData = new TestData();
    testData.prepare();

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

    DetachedCriteria salespersonSubquery = DetachedCriteria.forClass(Salesperson.class)
        .add(Restrictions.eq("name", "steve"))
        .setProjection(Property.forName("department"));
View Full Code Here


    Criteria departmentsQuery = session.createCriteria(Department.class).add(Subqueries.propertyIn("id", salespersonSubquery));
    List departments = departmentsQuery.list();

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

    session.enableFilter("region").setParameter("region", "Foobar");
    departments = departmentsQuery.list();

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

    session.enableFilter("region").setParameter("region", "APAC");
View Full Code Here

    session.enableFilter("region").setParameter("region", "Foobar");
    departments = departmentsQuery.list();

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

    session.enableFilter("region").setParameter("region", "APAC");

    DetachedCriteria lineItemSubquery = DetachedCriteria.forClass(LineItem.class)
        .add(Restrictions.ge("quantity", new Long(1)))
        .createCriteria("product")
        .add(Restrictions.eq("name", "Acme Hair Gel"))
View Full Code Here

        .add(Restrictions.eq("buyer", "gavin"))
        .list();

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

    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

        .list();

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

    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

        .add(Restrictions.eq("buyer", "gavin"))
        .list();

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

    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

        .list();

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

    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

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    TestData testData = new TestData();
    testData.prepare();

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

    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();

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

    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();

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

    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());

    session.enableFilter("region").setParameter("region", "APAC");
View Full Code Here

    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());

    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

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.