Example usage for org.hibernate.criterion Restrictions isNotNull

List of usage examples for org.hibernate.criterion Restrictions isNotNull

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions isNotNull.

Prototype

public static Criterion isNotNull(String propertyName) 

Source Link

Document

Apply an "is not null" constraint to the named property

Usage

From source file:com.bean.DirectoryViewBean.java

public List<Directory> getAllDirectory() {
    Dao dao = new Dao();

    Criterion c = Restrictions.eq("dirtId", type);
    List<DirectoryType> d = dao.getByCondition(DirectoryType.class, c);
    //DirectoryType d = (DirectoryType) dao.getById(DirectoryType.class, type);
    Criterion cType = null;/*from  www. jav a2 s  .  c om*/
    if (d.size() == 0) {
        title = "Category of directory";
        cType = Restrictions.isNotNull("directoryType");
    } else {
        title = d.get(0).getDirtName();
        cType = Restrictions.eq("directoryType", d.get(0));
    }
    Order o = Order.desc("dirName");
    return listDirectory = dao.getByCondition(Directory.class, cType, o);
}

From source file:com.bean.PropertyBean.java

public List<Property> getGenerateList() {
    Dao dao = new Dao();
    HibernateUtil.getInstance().clear();
    if (searchkey == null) {
        searchkey = "";
    }//www. j a  va 2  s .co m
    long idP = 0;
    try {
        idP = Long.parseLong(searchkey);
    } catch (Exception ex) {

    }
    Criterion cTitle = Restrictions.like("proTitle", "%" + searchkey + "%");
    Criterion cUser = Restrictions.eq("users", new Users(searchkey));
    LogicalExpression logic = Restrictions.or(cTitle, cUser);
    if (idP != 0) {
        Criterion cid = Restrictions.eq("proId", idP);
        logic = Restrictions.or(logic, cid);
    }

    Criterion cType = null;
    if (searchtype != null && !searchtype.equals("")) {
        int id = 0;
        try {
            id = Integer.parseInt(searchtype);
            cType = Restrictions.eq("exchangeType", new ExchangeType(id));
        } catch (Exception ex) {
            cType = Restrictions.isNotNull("exchangeType");
        }
    } else {
        cType = Restrictions.isNotNull("exchangeType");
    }
    logic = Restrictions.and(cType, logic);

    Criterion cCat = null;
    if (searchcat != null && !searchcat.equals("")) {
        int id = 0;
        try {
            id = Integer.parseInt(searchcat);
            cCat = Restrictions.eq("propertyType", new PropertyType(id));
            logic = Restrictions.and(logic, cCat);
        } catch (Exception ex) {

        }
    }
    Criterion cPub = null;
    if (searchpub != null && !searchpub.equals("")) {
        boolean id = false;
        try {
            id = Boolean.parseBoolean(searchpub);
            cPub = Restrictions.eq("proPublish", id);
            logic = Restrictions.and(logic, cPub);
        } catch (Exception ex) {
        }
    }
    Criterion cStt = null;
    if (searchStt != null && !searchStt.equals("")) {
        int id;
        try {
            id = Integer.parseInt(searchpub);
            cStt = Restrictions.eq("proStatus", id);
            logic = Restrictions.and(logic, cStt);
        } catch (Exception ex) {
        }
    }
    Order o = Order.desc("proPublishDate");
    listProperty = dao.getByCondition(Property.class, logic, o);
    return listProperty;
}

From source file:com.bean.PropertyOfUserBean.java

public List<Property> getGenerateList() {
    Dao dao = new Dao();
    HibernateUtil.getInstance().clear();
    Users u = (Users) dao.getById(Users.class, user);
    Criterion cUser = Restrictions.eq("users", u);
    if (searchkey == null) {
        searchkey = "";
    }/*from   ww w . ja va2  s .c om*/
    Criterion cTitle = Restrictions.like("proTitle", "%" + searchkey + "%");
    LogicalExpression logic;

    Criterion cType = null;
    if (searchtype != null && !searchtype.equals("")) {
        int id = 0;
        try {
            id = Integer.parseInt(searchtype);
            cType = Restrictions.eq("exchangeType", new ExchangeType(id));
        } catch (Exception ex) {
            cType = Restrictions.isNotNull("exchangeType");
        }
    } else {
        cType = Restrictions.isNotNull("exchangeType");
    }
    logic = Restrictions.and(cType, cTitle);

    Criterion cCat = null;
    if (searchcat != null && !searchcat.equals("")) {
        int id = 0;
        try {
            id = Integer.parseInt(searchcat);
            cCat = Restrictions.eq("propertyType", new PropertyType(id));
            logic = Restrictions.and(logic, cCat);
        } catch (Exception ex) {

        }
    }
    Criterion cPub = null;
    if (searchpub != null && !searchpub.equals("")) {
        boolean id = false;
        try {
            id = Boolean.parseBoolean(searchpub);
            cPub = Restrictions.eq("proPublish", id);
            logic = Restrictions.and(logic, cPub);
        } catch (Exception ex) {
        }
    }
    Criterion cStt = null;
    if (searchStt != null && !searchStt.equals("")) {
        int id;
        try {
            id = Integer.parseInt(searchpub);
            cStt = Restrictions.eq("proStatus", id);
            logic = Restrictions.and(logic, cStt);
        } catch (Exception ex) {
        }
    }
    logic = Restrictions.and(logic, cUser);
    Order o = Order.desc("proPublishDate");
    listProperty = dao.getByCondition(Property.class, logic, o);
    return listProperty;
}

From source file:com.bean.PropertyUserBean.java

public List<Property> getGenerateListProperty() {
    Dao dao = new Dao();
    Users u = (Users) SessionUtils.getSession().getAttribute("login");
    if (u != null) {
        LogicalExpression logic = null;/*from  ww w .  ja va  2 s.c o  m*/
        Criterion cr = Restrictions.eq("users", u);

        if (publish != null && !publish.equals("")) {
            Criterion pub = Restrictions.eq("proPublish", Boolean.parseBoolean(publish));
            logic = Restrictions.and(cr, pub);
        } else {
            Criterion pub = Restrictions.isNotNull("proPublish");
            logic = Restrictions.and(cr, pub);
        }

        Order o = Order.desc("proPublishDate");
        if (fromDate != null) {
            Criterion from = Restrictions.gt("proCreateDate", fromDate);
            logic = Restrictions.and(logic, from);
        }
        if (toDate != null) {
            Criterion to = Restrictions.lt("proCreateDate", toDate);
            logic = Restrictions.and(logic, to);
        }
        if (cat != 0) {
            PropertyType t = new PropertyType(cat);
            Criterion ca = Restrictions.eq("propertyType", t);
            logic = Restrictions.and(logic, ca);
        }
        listProperty = dao.getByCondition(Property.class, logic, o);
    }
    return listProperty;
}

From source file:com.bean.PropertyViewBean.java

public void init() {
    Criterion cType = null;// w  w w .  ja v  a2  s . c o  m
    Criterion cCat = null;
    title = "Real estate | Buy, sell, rent out real estate";
    if (type == 1) {
        title = "Property for sale";
        ExchangeType e = new ExchangeType(type);
        cType = Restrictions.eq("exchangeType", e);
    } else if (type == 2) {
        title = "Property for rent";
        ExchangeType e = new ExchangeType(type);
        cType = Restrictions.eq("exchangeType", e);
    } else {
        cType = Restrictions.isNotNull("exchangeType");
    }

    if (cat != 0) {
        PropertyType t = new PropertyType(cat);
        cCat = Restrictions.eq("propertyType", t);
    } else {
        cCat = Restrictions.isNotNull("propertyType");
    }
    Dao dao = new Dao();
    Criterion stt = Restrictions.eq("proStatus", 0);
    Criterion cpub = Restrictions.eq("proPublish", true);
    Conjunction logic = Restrictions.and(new Criterion[] { cCat, cType, stt, cpub });
    Order o = Order.desc("proPublishDate");
    listProperty = dao.getByCondition(Property.class, logic, o);
}

From source file:com.bean.SearchBean.java

public void init() {
    Dao dao = new Dao();

    long pMin = 0, pMax = 0, aMin = 0, aMax = 0;
    try {/* www.  ja  v  a 2  s.  co  m*/
        pMin = Long.parseLong(this.priceMin);
    } catch (Exception ex) {

    }
    try {
        pMax = Long.parseLong(this.priceMax);
    } catch (Exception ex) {

    }
    try {
        aMin = Long.parseLong(this.areaMin);
    } catch (Exception ex) {

    }
    try {
        aMax = Long.parseLong(this.areaMax);
    } catch (Exception ex) {

    }

    LogicalExpression logic;
    Criterion district = null;
    Criterion province;
    Criterion propertyType = null;
    Criterion exchange = null;
    Criterion priceMin;
    Criterion priceMax;
    Criterion areaMin;
    Criterion areaMax;

    if (this.propertyType != 0) {
        PropertyType p = new PropertyType(this.propertyType);
        propertyType = Restrictions.eq("propertyType", p);
    } else {
        propertyType = Restrictions.isNotNull("propertyType");
    }

    if (this.exchangeType != 0) {
        ExchangeType e = new ExchangeType(this.exchangeType);
        exchange = Restrictions.eq("exchangeType", e);
    } else {
        exchange = Restrictions.isNotNull("exchangeType");
    }

    if (districtId != 0) {
        District d = new District(districtId);
        district = Restrictions.eq("district", d);
    } else {
        if (provinceId != 0) {
            Province p = (Province) dao.getById1(Province.class, provinceId);
            //Set<District> list = p.getDistricts();
            if (p != null && p.getDistricts().size() > 0) {
                district = Restrictions.in("district", p.getDistricts());
            } else {
                district = Restrictions.isNull("district");
            }
        }
    }
    Criterion cpub = Restrictions.eq("proPublish", true);
    Criterion stt = Restrictions.eq("proStatus", 0);
    logic = Restrictions.and(propertyType, exchange);
    logic = Restrictions.and(logic, stt);
    logic = Restrictions.and(logic, cpub);
    if (district != null) {
        logic = Restrictions.and(logic, district);
    }

    if (pMax > 0) {
        priceMax = Restrictions.between("proPrice", pMin, pMax);
        logic = Restrictions.and(logic, priceMax);
    } else {
        priceMin = Restrictions.gt("proPrice", pMin);
        logic = Restrictions.and(logic, priceMin);
    }

    if (aMax > 0) {
        areaMax = Restrictions.between("proArea", aMin, aMax);
        logic = Restrictions.and(logic, areaMax);
    } else {
        areaMin = Restrictions.gt("proArea", aMin);
        logic = Restrictions.and(logic, areaMin);
    }

    Order o = Order.desc("proPublishDate");

    listSearch = dao.getByCondition(Property.class, logic, o);

}

From source file:com.bloatit.data.queries.DaoFeatureQuery.java

License:Open Source License

/**
 * Add a WHERE close ensuring that there is a selected offer on each
 * returned daoFeature.
 */
public void withSelectedOffer() {
    add(Restrictions.isNotNull(SELECTED_OFFER));
}

From source file:com.bloatit.data.queries.DaoUserContentQuery.java

License:Open Source License

/**
 * Show content created as team.
 */
public void withAnyTeam() {
    add(Restrictions.isNotNull(AS_TEAM));
}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java

License:Open Source License

@SuppressWarnings("unchecked")
private List<ProcessInstance> getProcessInstances(final Long processDefId, final Boolean active) {
    return (List<ProcessInstance>) jbpmTemplate.execute(new JbpmCallback() {
        public Object doInJbpm(JbpmContext context) {
            Session session = context.getSession();
            Criteria criteria = session.createCriteria(ProcessInstance.class);
            if (processDefId != null) {
                Criteria definitionCriteria = criteria.createCriteria("processDefinition");
                definitionCriteria.add(Restrictions.eq("id", processDefId));
            }//from ww w  .j ava 2s  .c om
            if (Boolean.TRUE.equals(active)) {
                criteria.add(Restrictions.isNull("end"));
            } else if (Boolean.FALSE.equals(active)) {
                criteria.add(Restrictions.isNotNull("end"));
            }
            return criteria.list();
        }
    });
}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java

License:Open Source License

/**
 * Construct a JBPM Hibernate query based on the Task Query provided
 * //ww w .j a  va 2s. co m
 * @param session
 * @param query
 * @return  jbpm hiberate query criteria
 */
private Criteria createTaskQueryCriteria(Session session, WorkflowTaskQuery query) {
    Criteria task = session.createCriteria(TaskInstance.class);

    // task id
    if (query.getTaskId() != null) {
        task.add(Restrictions.eq("id", getJbpmId(query.getTaskId())));
    }

    // task state
    if (query.getTaskState() != null) {
        WorkflowTaskState state = query.getTaskState();
        if (state == WorkflowTaskState.IN_PROGRESS) {
            task.add(Restrictions.eq("isOpen", true));
            task.add(Restrictions.isNull("end"));
        } else if (state == WorkflowTaskState.COMPLETED) {
            task.add(Restrictions.eq("isOpen", false));
            task.add(Restrictions.isNotNull("end"));
        }
    }

    // task name
    if (query.getTaskName() != null) {
        task.add(Restrictions.eq("name", query.getTaskName().toPrefixString(namespaceService)));
    }

    // task actor
    if (query.getActorId() != null) {
        task.add(Restrictions.eq("actorId", query.getActorId()));
    }

    // task custom properties
    if (query.getTaskCustomProps() != null) {
        Map<QName, Object> props = query.getTaskCustomProps();
        if (props.size() > 0) {
            Criteria variables = task.createCriteria("variableInstances");
            Disjunction values = Restrictions.disjunction();
            for (Map.Entry<QName, Object> prop : props.entrySet()) {
                Conjunction value = Restrictions.conjunction();
                value.add(Restrictions.eq("name", factory.mapQNameToName(prop.getKey())));
                value.add(Restrictions.eq("value", prop.getValue().toString()));
                values.add(value);
            }
            variables.add(values);
        }
    }

    // process criteria
    Criteria process = createProcessCriteria(task, query);

    // process custom properties
    if (query.getProcessCustomProps() != null) {
        // TODO: Due to Hibernate bug
        // http://opensource.atlassian.com/projects/hibernate/browse/HHH-957
        // it's not possible to perform a sub-select with the criteria api.
        // For now issue a
        //       secondary query and create an IN clause.
        Map<QName, Object> props = query.getProcessCustomProps();
        if (props.size() > 0) {
            // create criteria for process variables
            Criteria variables = session.createCriteria(VariableInstance.class);
            variables.setProjection(Projections.distinct(Property.forName("processInstance")));
            Disjunction values = Restrictions.disjunction();
            for (Map.Entry<QName, Object> prop : props.entrySet()) {
                Conjunction value = Restrictions.conjunction();
                value.add(Restrictions.eq("name", factory.mapQNameToName(prop.getKey())));
                value.add(Restrictions.eq("value", prop.getValue().toString()));
                values.add(value);
            }
            variables.add(values);

            // note: constrain process variables to same criteria as tasks
            createProcessCriteria(variables, query);

            Disjunction processIdCriteria = createProcessIdCriteria(variables);

            // constrain tasks by process list
            process = (process == null) ? task.createCriteria("processInstance") : process;
            process.add(processIdCriteria);
        }
    }

    // order by
    if (query.getOrderBy() != null) {
        WorkflowTaskQuery.OrderBy[] orderBy = query.getOrderBy();
        for (WorkflowTaskQuery.OrderBy orderByPart : orderBy) {
            if (orderByPart == WorkflowTaskQuery.OrderBy.TaskActor_Asc) {
                task.addOrder(Order.asc("actorId"));
            } else if (orderByPart == WorkflowTaskQuery.OrderBy.TaskActor_Desc) {
                task.addOrder(Order.desc("actorId"));
            } else if (orderByPart == WorkflowTaskQuery.OrderBy.TaskCreated_Asc) {
                task.addOrder(Order.asc("create"));
            } else if (orderByPart == WorkflowTaskQuery.OrderBy.TaskCreated_Desc) {
                task.addOrder(Order.desc("create"));
            } else if (orderByPart == WorkflowTaskQuery.OrderBy.TaskDue_Asc) {
                task.addOrder(Order.asc("dueDate"));
            } else if (orderByPart == WorkflowTaskQuery.OrderBy.TaskDue_Desc) {
                task.addOrder(Order.desc("dueDate"));
            } else if (orderByPart == WorkflowTaskQuery.OrderBy.TaskId_Asc) {
                task.addOrder(Order.asc("id"));
            } else if (orderByPart == WorkflowTaskQuery.OrderBy.TaskId_Desc) {
                task.addOrder(Order.desc("id"));
            } else if (orderByPart == WorkflowTaskQuery.OrderBy.TaskName_Asc) {
                task.addOrder(Order.asc("name"));
            } else if (orderByPart == WorkflowTaskQuery.OrderBy.TaskName_Desc) {
                task.addOrder(Order.desc("name"));
            } else if (orderByPart == WorkflowTaskQuery.OrderBy.TaskState_Asc) {
                task.addOrder(Order.asc("end"));
            } else if (orderByPart == WorkflowTaskQuery.OrderBy.TaskState_Desc) {
                task.addOrder(Order.desc("end"));
            }
        }
    }

    // limit results
    if (query.getLimit() != -1) {
        task.setMaxResults(query.getLimit());
    }

    return task;
}