Example usage for org.hibernate Criteria createAlias

List of usage examples for org.hibernate Criteria createAlias

Introduction

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

Prototype

public Criteria createAlias(String associationPath, String alias) throws HibernateException;

Source Link

Document

Join an association, assigning an alias to the joined association.

Usage

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);
    }/* w w w . j av a  2  s .  com*/
    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 Machine findByIp(final Datacenter datacenter, final String ip) {
    Criteria crit = createCriteria();
    crit.createAlias(Machine.HYPERVISOR_PROPERTY, "hypervisor");

    crit.add(sameDatacenter(datacenter));
    crit.add(Restrictions.eq("hypervisor.ip", ip));

    return (Machine) crit.uniqueResult();
}

From source file:com.abiquo.server.core.infrastructure.management.RasdManagementDAO.java

License:Open Source License

public List<RasdManagement> findDisksAndVolumesByVirtualMachine(final VirtualMachine virtualMachine) {
    Criteria crit = createCriteria();
    crit.createAlias(RasdManagement.RASD_PROPERTY, "rasd");

    // Add disk resource type filter
    crit.add(Restrictions.in(RasdManagement.ID_RESOURCE_TYPE_PROPERTY,
            new String[] { VolumeManagement.DISCRIMINATOR, DiskManagement.DISCRIMINATOR }));

    // Add virtual machine filter
    crit.add(sameVirtualMachine(virtualMachine));

    // Order by generation (attachment order)
    crit.addOrder(Order.asc("sequence"));

    return getResultList(crit);
}

From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java

License:Open Source License

public List<VolumeManagement> getStatefulCandidates(final VirtualDatacenter vdc) {
    // Filters on the VolumeManagement entity
    Criteria crit = createCriteria();
    crit.createAlias(VolumeManagement.STORAGE_POOL_PROPERTY, "pool");
    crit.createAlias("pool." + StoragePool.DEVICE_PROPERTY, "device");

    crit.add(sameVirtualDatacenter(vdc));
    crit.add(Restrictions.isNull(VolumeManagement.VIRTUAL_MACHINE_TEMPLATE_PROPERTY));
    crit.add(Restrictions.eq(VolumeManagement.STATE_PROPERTY, VolumeState.DETACHED));

    crit.add(Restrictions.eq("device." + StorageDevice.STORAGE_TECHNOLOGY_PROPERTY,
            StorageTechnologyType.GENERIC_ISCSI));

    return getResultList(crit);
}

From source file:com.apt.facade.StudentFacade.java

public List<Student> getStudentList(StudentFinder finder, int page, int recordPerPage) {
    List<Student> lst = new ArrayList<>();

    Session session = null;/*from  ww w  . j  av  a2 s.co  m*/
    Transaction trans = null;

    try {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        Criteria crit = session.createCriteria(Student.class);

        crit.add(Restrictions.sqlRestriction("1=1"));
        if (finder.getStudentId() != null) {
            crit.add(Restrictions.and(Restrictions.eq("studentId", finder.getStudentId())));
        }
        if (finder.getStudentName() != null) {
            crit.add(Restrictions.and(Restrictions.ilike("studentName", "%" + finder.getStudentName() + "%")));
        }
        if (finder.getBatch() != null) {
            crit.createAlias("batch", "a");
            Criterion rest = Restrictions.or(Restrictions.eq("a.batchId", finder.getBatch().getBatchId()),
                    Restrictions.eq("a.batchName", finder.getBatch().getBatchName()));
            crit.add(Restrictions.and(rest));
        }
        crit.setFirstResult((page - 1) * recordPerPage);
        crit.setMaxResults(recordPerPage);
        lst = crit.list();
        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }

    return lst;
}

From source file:com.apt.facade.StudentFacade.java

public int getNumberStudent(StudentFinder finder) {
    List<Student> lst = new ArrayList<>();

    Session session = null;/* w w w  .java2s .c  om*/
    Transaction trans = null;

    try {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        Criteria crit = session.createCriteria(Student.class);

        crit.add(Restrictions.sqlRestriction("1=1"));
        if (finder.getStudentId() != null) {
            crit.add(Restrictions.and(Restrictions.eq("studentId", finder.getStudentId())));
        }
        if (finder.getStudentName() != null) {
            crit.add(Restrictions.and(Restrictions.ilike("studentName", "%" + finder.getStudentName() + "%")));
        }
        if (finder.getBatch() != null) {
            crit.createAlias("batch", "a");
            Criterion rest = Restrictions.or(Restrictions.eq("a.batchId", finder.getBatch().getBatchId()),
                    Restrictions.eq("a.batchName", finder.getBatch().getBatchName()));
            crit.add(Restrictions.and(rest));
        }

        lst = crit.list();
        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }

    return lst.size();
}

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

License:Open Source License

/**
 * Instantiates a new dao user content query.
 * /*w  w w.  j a  va  2s  .  c  o m*/
 * @param criteria the criteria to use for this query
 */
protected DaoUserContentQuery(final Criteria criteria) {
    super(criteria);
    criteria.createAlias("member", "m");
    criteria.setReadOnly(true);
}

From source file:com.bookselling.dao.RoleDaoImpl.java

@Override
public PaginationData filter(RoleFilterForm criteriaForm, int first, int items) {
    //parse to neccessary form
    RoleFilterForm form = criteriaForm;/* w w  w.  j  a  va2  s . c o m*/

    Criteria criteria = getSession().createCriteria(Role.class);

    //get data from filter form
    String keyword = form.getKeyword();
    Set<Permission> permissions = form.getPermissions();
    Integer permissionIds[] = new Integer[permissions.size()];
    for (int i = 0; i < permissions.size(); i++)
        permissionIds[i] = permissions.iterator().next().getId();

    //setup criteria
    criteria.createAlias("permissions", "psm").add(Restrictions.like("name", "%" + keyword + "%"))
            .add(Restrictions.in("psm.id", permissionIds));

    //start querying
    List<Role> roles = criteria.list();

    //init proxy obj
    for (Role role : roles)
        HibernateInitSupport.initRole(role);

    //pagination
    PaginationData paginationData = new PaginationData(
            (long) criteria.setProjection(Projections.rowCount()).uniqueResult(), items, first, roles);

    return paginationData;
}