Example usage for org.hibernate Criteria addOrder

List of usage examples for org.hibernate Criteria addOrder

Introduction

In this page you can find the example usage for org.hibernate Criteria addOrder.

Prototype

public Criteria addOrder(Order order);

Source Link

Document

Add an Order ordering to the result set.

Usage

From source file:com.abiquo.server.core.enterprise.RoleLdapDAO.java

License:Open Source License

private Criteria createCriteria(final String filter, final String orderBy, final boolean desc) {
    Criteria criteria = createCriteria();

    if (!StringUtils.isEmpty(filter)) {
        criteria.add(filterBy(filter));//from  ww w  .  j  ava  2 s.c  o  m
    }

    if (!StringUtils.isEmpty(orderBy)) {
        Order order = Order.asc(orderBy);
        if (desc) {
            order = Order.desc(orderBy);
        }
        criteria.addOrder(order);
    }

    return criteria;
}

From source file:com.abiquo.server.core.enterprise.UserDAO.java

License:Open Source License

public User findByEnterprise(final Integer userId, final Enterprise enterprise) {
    Criteria criteria = createCriteria(sameId(userId), sameEnterprise(enterprise));
    criteria.addOrder(Order.asc(VirtualDatacenter.NAME_PROPERTY));

    return (User) criteria.uniqueResult();
}

From source file:com.abiquo.server.core.enterprise.UserDAO.java

License:Open Source License

private Criteria createCriteria(final Enterprise enterprise, final Role role, final String[] filters,
        final String orderBy, final boolean desc, final boolean connected) {
    Criteria criteria = createCriteria();

    if (enterprise != null) {
        criteria.add(sameEnterprise(enterprise));
    }/*www.j av a  2s .c o  m*/

    if (role != null) {
        criteria.add(sameRole(role));
    }
    if (!ArrayUtils.isEmpty(filters)) {
        for (String filter : filters) {
            if (!StringUtils.isEmpty(filter)) {
                criteria.add(filterBy(filter));
            }
        }
    }

    if (!StringUtils.isEmpty(orderBy)) {
        Order order = Order.asc(orderBy);
        if (desc) {
            order = Order.desc(orderBy);
        }
        criteria.addOrder(order);
    }

    if (connected) {
        criteria.createCriteria("sessions").add(Restrictions.gt("expireDate", new Date()));
        criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    }
    return criteria;
}

From source file:com.abiquo.server.core.infrastructure.DatastoreDAO.java

License:Open Source License

public List<Datastore> findMachineDatastores(final Machine machine) {
    assert machine != null;
    assert isManaged2(machine);

    Criteria criteria = inMachine(machine);
    // createCriteria().createCriteria(Datastore.MACHINES_PROPERTY).add(
    // Restrictions.in(Machine.ID_PROPERTY, new Integer[] {machine.getId()}));

    criteria.addOrder(Order.asc(Datastore.NAME_PROPERTY));
    List<Datastore> result = getResultList(criteria);
    return result;
}

From source file:com.abiquo.server.core.infrastructure.MachineDAO.java

License:Open Source License

public List<Machine> findMachines(final Datacenter datacenter) {
    Criteria criteria = createCriteria(sameDatacenter(datacenter));
    criteria.addOrder(Order.asc(Machine.NAME_PROPERTY));
    List<Machine> result = getResultList(criteria);
    return result;
}

From source file:com.abiquo.server.core.infrastructure.MachineDAO.java

License:Open Source License

public List<Machine> findRackMachines(final Rack rack, final String filter) {
    assert rack != null;
    assert isManaged2(rack);

    Criteria criteria = createCriteria(sameRack(rack));
    if (filter != null && !filter.isEmpty()) {
        criteria.add(filterBy(filter));/*w  w  w  .  j  a va 2  s  . c o m*/
    }
    criteria.addOrder(Order.asc(Machine.NAME_PROPERTY));
    List<Machine> result = getResultList(criteria);
    return result;
}

From source file:com.abiquo.server.core.infrastructure.MachineDAO.java

License:Open Source License

public List<Machine> findMachinesWithHAInProgress() {
    Criteria criteria = createCriteria(sameState(MachineState.HA_IN_PROGRESS));
    criteria.createAlias(Machine.HYPERVISOR_PROPERTY, "hypervisor");

    // Order by name
    criteria.addOrder(Order.asc(Machine.NAME_PROPERTY));

    return getResultList(criteria);
}

From source file:com.abiquo.server.core.infrastructure.MachineDAO.java

License:Open Source License

public List<Machine> findRackEnabledForHAMachines(final Rack rack) {
    if (rack instanceof UcsRack) {
        return findRackEnabledForHAMachinesInUcs((UcsRack) rack);
    }//  www.  j av  a  2  s  .  c o  m
    Criteria criteria = createCriteria(sameRack(rack));
    criteria.createAlias(Machine.HYPERVISOR_PROPERTY, "hypervisor");

    // Is a managed one
    criteria.add(Restrictions.eq(Machine.STATE_PROPERTY, MachineState.MANAGED));

    // Has fencing capabilities
    criteria.add(Restrictions.isNotNull(Machine.IPMI_IP_PROPERTY));
    criteria.add(Restrictions.isNotNull(Machine.IPMI_USER_PROPERTY));
    criteria.add(Restrictions.isNotNull(Machine.IPMI_PASSWORD_PROPERTY));

    // XenServer does not support HA
    criteria.add(Restrictions.ne("hypervisor." + Hypervisor.TYPE_PROPERTY, HypervisorType.XENSERVER));

    // Order by name
    criteria.addOrder(Order.asc(Machine.NAME_PROPERTY));

    return getResultList(criteria);
}

From source file:com.abiquo.server.core.infrastructure.MachineDAO.java

License:Open Source License

public List<Machine> findRackEnabledForHAMachinesInUcs(final UcsRack rack) {
    Criteria criteria = createCriteria(sameRack(rack));
    criteria.createAlias(Machine.HYPERVISOR_PROPERTY, "hypervisor");

    // Is a managed one
    criteria.add(Restrictions.eq(Machine.STATE_PROPERTY, MachineState.MANAGED));

    // XenServer does not support HA
    criteria.add(Restrictions.ne("hypervisor." + Hypervisor.TYPE_PROPERTY, HypervisorType.XENSERVER));

    // Order by name
    criteria.addOrder(Order.asc(Machine.NAME_PROPERTY));

    return getResultList(criteria);
}

From source file:com.abiquo.server.core.infrastructure.MachineDAO.java

License:Open Source License

public List<Machine> findReservedMachines(final Enterprise enterprise) {
    Criteria criteria = createCriteria(sameEnterprise(enterprise));
    criteria.addOrder(Order.asc(Machine.NAME_PROPERTY));
    List<Machine> result = getResultList(criteria);
    return result;
}