Example usage for org.hibernate.criterion Restrictions or

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

Introduction

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

Prototype

public static LogicalExpression or(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the disjuction of two expressions

Usage

From source file:cloudoutput.dao.NetworkMapEntryDAO.java

License:Open Source License

/** 
 * Gets a list of network entries of a given entity.
 * The resulting list contains entries on which the given entity is either
 * the source or the destination.//  w w w  . ja  v  a 2 s  .  com
 * 
 * @param   entityName      the name of the entity of which all related 
 *                          network entries will be retrieved.
 * @return                  a list containing all existing network entries
 *                          in the database; <code>null</code> if no
 *                          entries were found.
 * @see                     NetworkMapEntry
 * @since                   1.0
 */
public List<NetworkMapEntry> getListOfEntries(String entityName) {
    Session session = HibernateUtil.getSession();
    List<NetworkMapEntry> networkList = null;

    try {
        networkList = (List<NetworkMapEntry>) session
                .createCriteria(NetworkMapEntry.class).add(Restrictions
                        .or(Restrictions.eq("source", entityName), Restrictions.eq("destination", entityName)))
                .list();
    } catch (HibernateException ex) {
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        HibernateUtil.closeSession(session);
    }

    return networkList;
}

From source file:cms.pageList.entity.SearcherLabel.java

License:Apache License

public String getIterativeString(TagLabel tagLabel, List<PropertyFilter> filters) {

    String strTag = tagLabel.getTagName();// ??

    // System.out.println("------------------------------------");

    if (tagLabel == null)
        return strTag;

    // // w w w  .  ja va2  s . c o m

    // ??
    if ((!tagLabel.getOrderby().trim().equalsIgnoreCase(""))
            && (!tagLabel.getOrderbyType().trim().equalsIgnoreCase(""))) {

        String arcattStr = null;// 
        for (Long flagid : tagLabel.getflagIds()) {
            arcattStr += "," + flagid;
        }

        // 
        if (arcattStr != null) {
            // ?0,?
            if (tagLabel.getTypeid() == 0) {
                addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                        Restrictions.ge("arcrank", 0),
                        Restrictions.sqlRestriction(
                                "id in  ( select archives_id from archives_arcatt where arcatt_id in("
                                        + arcattStr + ") )"),
                        Restrictions.or(
                                Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
            } else {
                addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                        Restrictions.eq("typeid", tagLabel.getTypeid()), Restrictions.ge("arcrank", 0),
                        Restrictions.sqlRestriction(
                                "id in  ( select archives_id from archives_arcatt where arcatt_id in("
                                        + arcattStr + ") )"),
                        Restrictions.or(
                                Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
            }
        } else { // 

            // ?0,?
            if (tagLabel.getTypeid() == 0) {
                addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                        Restrictions.ge("arcrank", 0),
                        Restrictions.or(
                                Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
            } else {
                addArchivesList(tagLabel.getRow(), 1, tagLabel.getOrderby(), tagLabel.getOrderbyType(),
                        Restrictions.ge("arcrank", 0), Restrictions.eq("typeid", tagLabel.getTypeid()),
                        Restrictions.or(
                                Restrictions.like("title", pfValue("title", filters), MatchMode.ANYWHERE),
                                Restrictions.like("body", pfValue("title", filters), MatchMode.ANYWHERE)));
            }

        }

    } else { // ?
        // ?0,?

        if (tagLabel.getTypeid() == 0) {
            addArchivesList(tagLabel.getRow(), 1, "senddate", "desc", Restrictions.ge("arcrank", 0),
                    Restrictions.eq("typeid", tagLabel.getTypeid()));
        } else {
            addArchivesList(tagLabel.getRow(), 1, "senddate", "desc", Restrictions.ge("arcrank", 0));
        }

    }

    /*strTag = "<s:iterator value=\"pagecontent.listLabel.get("
    + pfValue("getNum", filters)
    + ").getPage().getResult()\" status=\"st\">"
    + tagLabel.getBody() + "</s:iterator>";*/
    strTag = "<#list pagecontent.listLabel.get(" + pfValue("getNum", filters)
            + ").getPage().getResult() as xx >" + tagLabel.getBody() + "</#list>";

    return strTag;
}

From source file:cn.newtouch.hibernate.dao.StudentDAO.java

License:Open Source License

public static void main(String[] args) {
    try {//w  ww.  j a  v  a2s  . com
        Session session = HibernateUtil.getSession();
        String hql = " from Student";
        List<Student> userList = session.createQuery(hql).list();
        System.out.println("=====1=======" + userList.size());
        Criteria criteria = session.createCriteria(Student.class);
        // 
        criteria.add(Restrictions.eq("name", "HZZ"));
        // map
        criteria.add(Restrictions.allEq(new HashMap<String, String>()));
        // 
        criteria.add(Restrictions.gt("id", new Long(1)));
        // 
        criteria.add(Restrictions.ge("id", new Long(1)));
        // ?
        criteria.add(Restrictions.lt("id", new Long(1)));
        // ?
        criteria.add(Restrictions.le("id", new Long(1)));
        // xxxyyy
        criteria.add(Restrictions.between("id", new Long(1), new Long(2)));
        // ?
        criteria.add(Restrictions.like("name", "H"));
        // and?
        criteria.add(Restrictions.and(Restrictions.ge("id", new Long(1)), Restrictions.ge("id", new Long(1))));
        // or?
        criteria.add(Restrictions.or(Restrictions.ge("id", new Long(1)), Restrictions.ge("id", new Long(1))));
        userList = criteria.list();
        System.out.println("=====2=======" + userList.size());
        Student student = new Student();
        student.setId(123456L);
        student.setName("hzz");
        student.setAge(14);
        save(student);

        System.out.println("OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

    } catch (Exception e) {
        e.printStackTrace();

    }
}

From source file:cn.trymore.core.hibernate.HibernateUtils.java

License:Open Source License

/**
 * QBCOR//from  w  w  w.j a  v a 2  s. com
 * @param crit1
 * @param crit2
 * @return
 */
public static Criterion QBC_OR(Criterion crit1, Criterion crit2) {
    if (crit1 == null) {
        return crit2;
    }

    if (crit2 == null) {
        return crit1;
    }

    return Restrictions.or(crit1, crit2);
}

From source file:co.com.codesoftware.logica.contabilidad.PucLogica.java

/**
 * Funcion con la cual obtengo los auxiliares contables por medio de algun criterio
 * @param criterio// w w  w .j  ava2s .  com
 * @return 
 */
public List<AuxContableEntity> obtenerAuxiliaresConXCriterio(String criterio) {
    List<AuxContableEntity> rta = null;
    try {
        this.initOperation();
        Criteria crit = this.sesion.createCriteria(AuxContableEntity.class);
        Criterion uno = Restrictions.like("codigo", "%" + criterio + "%").ignoreCase();
        Criterion dos = Restrictions.like("nombre", "%" + criterio + "%").ignoreCase();
        crit.add(Restrictions.or(uno, dos));
        crit.addOrder(Order.asc("id"));
        rta = crit.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rta;
}

From source file:co.utb.softeng.contactsapp.dao.impl.ContactDAOImpl.java

@Override
public List<Contact> getByCitaName(String citaName) {
    Criterion crit1 = Restrictions.ilike("asunto", citaName, MatchMode.ANYWHERE);
    Criterion crit2 = Restrictions.ilike("lugar", citaName, MatchMode.ANYWHERE);

    DetachedCriteria subQuery = DetachedCriteria.forClass(Contact.class).createCriteria("citas")
            .add(Restrictions.or(crit1, crit2)).setProjection(Projections.id());

    Criteria mainCriteria = getSession().createCriteria(Contact.class)
            .add(Subqueries.propertyIn("id", subQuery)).setFetchMode("citas", FetchMode.JOIN);

    return mainCriteria.list();
}

From source file:com.abiquo.server.core.appslibrary.VirtualMachineTemplateDAO.java

License:Open Source License

/** Virtual Machine Template compatible or some conversion compatible. */
private Criterion compatibleOrConversions(final HypervisorType hypervisorType, final Criteria criteria) {
    return Restrictions.or(compatible(hypervisorType.compatibleFormats), //
            compatibleConversions(hypervisorType.compatibleFormats, criteria));
}

From source file:com.abiquo.server.core.appslibrary.VirtualMachineTemplateDAO.java

License:Open Source License

private static Criterion sameEnterpriseOrShared(final Enterprise enterprise) {
    return Restrictions.or(sameEnterprise(enterprise), sharedVirtualMachineTemplate());
}

From source file:com.abiquo.server.core.appslibrary.VirtualMachineTemplateDAO.java

License:Open Source License

private static Criterion sameEnterpriseOrSharedInRepo(final Enterprise enterprise,
        final com.abiquo.server.core.infrastructure.Repository repository) {
    return Restrictions.and(sameRepositoryAndNotStatefull(repository),
            Restrictions.or(sameEnterprise(enterprise), sharedVirtualMachineTemplate()));
}

From source file:com.abiquo.server.core.appslibrary.VirtualMachineTemplateDAO.java

License:Open Source License

private static Criterion sameEnterpriseOrSharedInRepo(final Enterprise enterprise,
        final com.abiquo.server.core.infrastructure.Repository repository, final String path) {
    Criterion sameEnterpriseOrSharedInRepo = Restrictions.and(sameRepositoryAndNotStatefull(repository),
            Restrictions.or(sameEnterprise(enterprise), sharedVirtualMachineTemplate()));

    return Restrictions.and(Restrictions.eq(VirtualMachineTemplate.PATH_PROPERTY, path),
            sameEnterpriseOrSharedInRepo);
}