Package org.hibernate.criterion

Examples of org.hibernate.criterion.DetachedCriteria


    public List<User> getUsersInterestedIn(School school) {
        return getUsersInterestedIn(school, 10);
    }

    public List<User> getUsersInterestedIn(School school, int max) {
        DetachedCriteria crit = DetachedCriteria.forClass(
                Application.class, "app").add(
                Expression.eq("school", school));

        List<Application> applications = getHibernateTemplate()
                .findByCriteria(crit, 0, max);
View Full Code Here


    @SuppressWarnings("unchecked")
    public final List<E> findByExampleLike(final E example) {
        Example exam = Example.create(example);
        exam.enableLike(MatchMode.ANYWHERE); // this is it.
        exam.ignoreCase();
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(clazz).add(exam);
       
        detachedCriteria = getCriteria(example, detachedCriteria);

        // DetachedCriteria c = DetachedCriteria.forClass(clazz).add(exam);
View Full Code Here

                            "get" + StringUtils.capitalize(field.getName()),
                            (Class[]) null);
                    if (method.invoke(example, (Object[]) null) != null) {
                        Object object = method.invoke(example,
                                (Object[]) null);
                        DetachedCriteria childCriteria = detachedCriteria.createCriteria(field.getName()).add(
                                Example.create(object));
                        getCriteria(object, childCriteria);
                    }
                    }
                }
View Full Code Here

   * @see com.jdroid.java.repository.RandomRepository#getRandomIds(java.lang.Integer)
   */
  @SuppressWarnings("unchecked")
  @Override
  public List<Long> getRandomIds(Integer maxResults) {
    DetachedCriteria criteria = this.createDetachedCriteria();
    criteria.setProjection(Projections.id());
    criteria.add(getRandomRestriction());
    return this.getHibernateTemplate().findByCriteria(criteria, 0, maxResults);
  }
View Full Code Here

  /**
   * @see com.jdroid.javaweb.push.DeviceRepository#find(java.lang.String, com.jdroid.javaweb.push.DeviceType)
   */
  @Override
  public Device find(String deviceId, DeviceType deviceType) {
    DetachedCriteria criteria = createDetachedCriteria();
    criteria.add(Restrictions.eq("deviceId", deviceId));
    criteria.add(Restrictions.eq("deviceType", deviceType));
    return this.findUnique(criteria);
  }
View Full Code Here

   * @see com.jdroid.javaweb.push.DeviceRepository#find(java.lang.String, com.jdroid.javaweb.push.DeviceType,
   *      java.lang.String)
   */
  @Override
  public Device find(String deviceId, DeviceType deviceType, String registrationId) {
    DetachedCriteria criteria = createDetachedCriteria();
    criteria.add(Restrictions.eq("deviceId", deviceId));
    criteria.add(Restrictions.eq("deviceType", deviceType));
    criteria.add(Restrictions.eq("registrationId", registrationId));
    return this.findUnique(criteria);
  }
View Full Code Here

  public void testCriteriaControl() {
    TestData testData = new TestData();
    testData.prepare();

    // the subquery...
    DetachedCriteria subquery = DetachedCriteria.forClass( Salesperson.class )
        .setProjection( Property.forName( "name" ) );

    Session session = openSession();
    session.beginTransaction();
    session.enableFilter( "fulfilledOrders" ).setParameter( "asOfDate", testData.lastMonth.getTime() );
View Full Code Here

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

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

    DetachedCriteria lineItemSubquery = DetachedCriteria.forClass(LineItem.class)
        .add(Restrictions.ge("quantity", new Long(1)))
        .createCriteria("product")
        .add(Restrictions.eq("name", "Acme Hair Gel"))
        .setProjection(Property.forName("id"));

    List orders = session.createCriteria(Order.class)
        .add(Subqueries.exists(lineItemSubquery))
        .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"));

    lineItemSubquery = DetachedCriteria.forClass(LineItem.class)
        .add(Restrictions.ge("quantity", new Long(1)))
View Full Code Here

 
  public static final String ROLE_NAME = "roleName";
  public static final String ROLE_REMARK = "roleRemark";

  public void findPage(PaginationSupport<AppRole> pagination, String search) {
    DetachedCriteria criteria = DetachedCriteria.forClass(AppRole.class);
    criteria.add(Restrictions.eq(DELETE_FLAG, false));
    if (StringUtils.isNotBlank(search)) {
      criteria.add(
          Restrictions.or(
              Restrictions.ilike(ROLE_NAME, search, MatchMode.ANYWHERE),
              Restrictions.ilike(ROLE_REMARK, search, MatchMode.ANYWHERE)));
    }
    criteria.addOrder(Order.desc(CREATE_TIME));
    super.findPageByCriteria(pagination, criteria);
  }
View Full Code Here

  public static final String AUTH_CODE = "authCode";
  public static final String AUTH_NAME = "authName";
  public static final String AUTH_REMARK = "authRemark";

  public void findPage(PaginationSupport<AppAuth> pagination, String search) {
    DetachedCriteria criteria = DetachedCriteria.forClass(AppAuth.class);
    criteria.add(Restrictions.eq(DELETE_FLAG, false));
    if (StringUtils.isNotBlank(search)) {
      criteria.add(Restrictions.or(
          Restrictions.ilike(AUTH_CODE, search, MatchMode.ANYWHERE),
          Restrictions.or(Restrictions.ilike(AUTH_NAME, search, MatchMode.ANYWHERE),
              Restrictions.ilike(AUTH_REMARK, search, MatchMode.ANYWHERE))));
    }
    criteria.addOrder(Order.desc(CREATE_TIME));
    super.findPageByCriteria(pagination, criteria);
  }
View Full Code Here

TOP

Related Classes of org.hibernate.criterion.DetachedCriteria

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.