Example usage for org.hibernate.criterion Subqueries propertiesIn

List of usage examples for org.hibernate.criterion Subqueries propertiesIn

Introduction

In this page you can find the example usage for org.hibernate.criterion Subqueries propertiesIn.

Prototype

public static Criterion propertiesIn(String[] propertyNames, DetachedCriteria dc) 

Source Link

Document

Creates a criterion which checks that the value of multiple given properties as being in to the set of values in the subquery result.

Usage

From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java

@Override
public List<EmpCareerHistory> getByParamReport(ReportEmpMutationParameter searchParameter, int firstResult,
        int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    criteria.createAlias("jabatan", "jabatan", JoinType.INNER_JOIN);
    doSearchEmpRotasiByParamReport(searchParameter, criteria);

    DetachedCriteria maxTglPengangkatanQuery = DetachedCriteria.forClass(getEntityClass());
    ProjectionList proj = Projections.projectionList();
    proj.add(Projections.max("tglPenganngkatan"));
    proj.add(Projections.groupProperty("nik"));
    maxTglPengangkatanQuery.setProjection(proj);

    criteria.add(Subqueries.propertiesIn(new String[] { "tglPenganngkatan", "nik" }, maxTglPengangkatanQuery));
    criteria.addOrder(order);//from   w  w w .j av a  2s  .c  om
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);

    List<EmpCareerHistory> listEmpCareerHistorys = criteria.list();

    //Set Jabatan Lama/sebelumnya dari masing - masing record
    for (EmpCareerHistory ech : listEmpCareerHistorys) {
        Criteria criteriaOldPosition = getCurrentSession().createCriteria(getEntityClass());
        criteriaOldPosition.setFetchMode("jabatan", FetchMode.JOIN);
        criteriaOldPosition.add(Restrictions.eq("nik", ech.getNik()));
        criteriaOldPosition.add(Restrictions.lt("tglPenganngkatan", ech.getTglPenganngkatan()));
        criteriaOldPosition.addOrder(Order.desc("tglPenganngkatan"));
        criteriaOldPosition.setMaxResults(1);
        EmpCareerHistory prevPosition = (EmpCareerHistory) criteriaOldPosition.uniqueResult();

        //jika sebelumnya dia sudah pernah menjabat di posisi lain maka set oldJabatan dengan posisi tersebut
        if (null != prevPosition) {
            ech.setJabatanOldCode(prevPosition.getJabatan().getCode());
            ech.setJabatanOldName(prevPosition.getJabatan().getName());
        } else {
            ech.setJabatanOldCode("-");
        }
    }

    return listEmpCareerHistorys;
}

From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java

@Override
public Long getTotalEmpCareerHistoryDataByParamReport(ReportEmpMutationParameter searchParameter) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchEmpRotasiByParamReport(searchParameter, criteria);
    DetachedCriteria maxTglPengangkatanQuery = DetachedCriteria.forClass(getEntityClass());
    ProjectionList proj = Projections.projectionList();
    proj.add(Projections.max("tglPenganngkatan"));
    proj.add(Projections.groupProperty("nik"));
    maxTglPengangkatanQuery.setProjection(proj);
    criteria.add(Subqueries.propertiesIn(new String[] { "tglPenganngkatan", "nik" }, maxTglPengangkatanQuery));
    return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();
}

From source file:com.inkubator.hrm.dao.impl.TempJadwalKaryawanDaoImpl.java

@Override
public List<TempJadwalKaryawan> getAllByMaxEndDate(Date date) {
    ProjectionList proList = Projections.projectionList();
    proList.add(Property.forName("tanggalWaktuKerja").max());
    proList.add(Projections.groupProperty("empData"));
    DetachedCriteria data = DetachedCriteria.forClass(getEntityClass()).setProjection(proList);
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    String[] var = { "tanggalWaktuKerja", "empData" };
    criteria.add(Subqueries.propertiesIn(var, data));
    criteria.add(Restrictions.le("tanggalWaktuKerja", date));
    return criteria.list();

}

From source file:models.db.acentera.impl.ProjectProvidersImpl.java

License:Open Source License

public static Set<ProjectRegions> getRegionsAvailables(Set<ProjectProvidersRegions> regions) {

    Session s = (Session) HibernateSessionFactory.getSession();

    DetachedCriteria msgFromCriteria = DetachedCriteria.forClass(DO_REGIONS.class);
    ProjectionList properties = Projections.projectionList();
    properties.add(Projections.groupProperty("slug"));
    msgFromCriteria.setProjection(properties);

    Criteria criteria = s.createCriteria(DO_REGIONS.class);
    criteria.add(Subqueries.propertiesIn(new String[] { "slug" }, msgFromCriteria));

    List<DO_REGIONS> list = criteria.list();

    HashSet<ProjectRegions> regionsSet = new HashSet<ProjectRegions>();
    Iterator<ProjectProvidersRegions> ppr = regions.iterator();
    while (ppr.hasNext()) {
        ProjectProvidersRegions item = ppr.next();

        boolean bFound = false;
        Iterator<DO_REGIONS> itrReg = list.iterator();
        while (itrReg.hasNext() && !bFound) {
            DO_REGIONS r = itrReg.next();
            try {
                if (r.getSlug().compareTo(item.getProjectRegions().getSlug()) == 0) {
                    bFound = true;//from www  .j a  v a 2s . com
                }
            } catch (Exception ew) {
                ew.printStackTrace();
            }
        }
        if (bFound) {
            regionsSet.add(item.getProjectRegions());
        }
    }
    return regionsSet;

}

From source file:org.candlepin.gutterball.curator.ComplianceSnapshotCurator.java

License:Open Source License

/**
 * Retrieves an iterator over the compliance snapshots on the target date.
 *
 * @param targetDate/*from  w ww.  j  a v  a  2 s  . com*/
 *  The date for which to retrieve compliance snapshots. If null, the current date will be used
 *  instead.
 *
 * @param consumerUuids
 *  A list of consumer UUIDs to use to filter the results. If provided, only compliances for
 *  consumers in the list will be retrieved.
 *
 * @param ownerFilters
 *  A list of owners to use to filter the results. If provided, only compliances for consumers
 *  belonging to the specified owners (orgs) will be retrieved.
 *
 * @param statusFilters
 *  A list of statuses to use to filter the results. If provided, only compliances with a status
 *  matching the list will be retrieved.
 *
 * @param productNameFilters
 *  A list of product names to use to filter compliances. If provided, only compliances for
 *  consumers having installed the specified products will be retrieved.
 *
 * @param subscriptionSkuFilters
 *  A list of subscription skus to use to filter compliances. If provided, only compliances for
 *  the specified subscription skus will be retrieved.
 *
 * @param subscriptionNameFilters
 *  A list of subscription names to use to filter compliances. If provided, only compliances for
 *  the specified subscription names will be retrieved.
 *
 * @param attributeFilters
 *  A map of entitlement attributes to use to filter compliances. If provided, only compliances
 *  for entitlements having the specified values for the given attributes will be retrieved.
 *
 * @param pageRequest
 *  A PageRequest instance containing paging information from the request. If null, no paging
 *  will be performed.
 *
 * @return
 *  A Page instance containing an iterator over the compliance snapshots for the target date and
 *  the paging information for the query.
 */
@SuppressWarnings("checkstyle:indentation")
public Page<Iterator<Compliance>> getSnapshotIterator(Date targetDate, List<String> consumerUuids,
        List<String> ownerFilters, List<String> statusFilters, List<String> productNameFilters,
        List<String> subscriptionSkuFilters, List<String> subscriptionNameFilters,
        Map<String, String> attributeFilters, PageRequest pageRequest) {

    Page<Iterator<Compliance>> page = new Page<Iterator<Compliance>>();
    page.setPageRequest(pageRequest);

    DetachedCriteria subquery = DetachedCriteria.forClass(Compliance.class);
    subquery.createAlias("consumer", "c");
    subquery.createAlias("c.consumerState", "state");

    // https://hibernate.atlassian.net/browse/HHH-2776
    if (consumerUuids != null && !consumerUuids.isEmpty()) {
        subquery.add(Restrictions.in("c.uuid", consumerUuids));
    }

    Date toCheck = targetDate == null ? new Date() : targetDate;
    subquery.add(
            Restrictions.or(Restrictions.isNull("state.deleted"), Restrictions.gt("state.deleted", toCheck)));
    subquery.add(Restrictions.le("state.created", toCheck));

    if (ownerFilters != null && !ownerFilters.isEmpty()) {
        subquery.createAlias("c.owner", "o");
        subquery.add(Restrictions.in("o.key", ownerFilters));
    }

    subquery.add(Restrictions.le("date", toCheck));

    subquery.setProjection(
            Projections.projectionList().add(Projections.max("date")).add(Projections.groupProperty("c.uuid")));

    Session session = this.currentSession();
    Criteria query = session.createCriteria(Compliance.class, "comp").createAlias("comp.consumer", "cs")
            .add(Subqueries.propertiesIn(new String[] { "comp.date", "cs.uuid" }, subquery))
            .setCacheMode(CacheMode.IGNORE).setReadOnly(true);

    if ((statusFilters != null && !statusFilters.isEmpty())
            || (attributeFilters != null && attributeFilters.containsKey("management_enabled"))
            || (productNameFilters != null && !productNameFilters.isEmpty())) {

        query.createAlias("comp.status", "stat");

        if (statusFilters != null && !statusFilters.isEmpty()) {
            query.add(Restrictions.in("stat.status", statusFilters));
        }

        if (attributeFilters != null && attributeFilters.containsKey("management_enabled")) {
            boolean managementEnabledFilter = PropertyConverter
                    .toBoolean(attributeFilters.get("management_enabled"));
            query.add(Restrictions.eq("stat.managementEnabled", managementEnabledFilter));
        }

        if (productNameFilters != null && !productNameFilters.isEmpty()) {
            query.createAlias("stat.compliantProducts", "cprod", JoinType.LEFT_OUTER_JOIN)
                    .createAlias("stat.partiallyCompliantProducts", "pcprod", JoinType.LEFT_OUTER_JOIN)
                    .createAlias("stat.nonCompliantProducts", "ncprod", JoinType.LEFT_OUTER_JOIN);

            DetachedCriteria prodQuery = DetachedCriteria.forClass(Compliance.class, "comp2");
            prodQuery.createAlias("comp2.consumer", "cons2");
            prodQuery.createAlias("cons2.installedProducts", "installed");
            prodQuery.add(Restrictions.and(Restrictions.in("installed.productName", productNameFilters),
                    Restrictions.eqProperty("comp2.id", "comp.id")));
            prodQuery.setProjection(Projections.property("installed.productId"));

            query.add(Restrictions.or(Property.forName("cprod.productId").in(prodQuery),
                    Property.forName("pcprod.productId").in(prodQuery),
                    Property.forName("ncprod.productId").in(prodQuery)));
        }
    }

    // Add subscription filters, if necessary
    if ((subscriptionSkuFilters != null && !subscriptionSkuFilters.isEmpty())
            || (subscriptionNameFilters != null && !subscriptionNameFilters.isEmpty())) {

        // Impl note: We have to be very careful with alias names, as Hibernate has a tendancy
        // to errorneously truncate "long" ones. Actual property/field names are safe, though.
        query.createAlias("comp.entitlements", "entsnap");

        if (subscriptionSkuFilters != null && !subscriptionSkuFilters.isEmpty()) {
            query.add(Restrictions.in("entsnap.productId", subscriptionSkuFilters));
        }

        if (subscriptionNameFilters != null && !subscriptionNameFilters.isEmpty()) {
            query.add(Restrictions.in("entsnap.productName", subscriptionNameFilters));
        }
    }

    if (pageRequest != null && pageRequest.isPaging()) {
        page.setMaxRecords(this.getRowCount(query));

        query.setFirstResult((pageRequest.getPage() - 1) * pageRequest.getPerPage());
        query.setMaxResults(pageRequest.getPerPage());

        if (pageRequest.getSortBy() != null) {
            query.addOrder(
                    pageRequest.getOrder() == PageRequest.Order.ASCENDING ? Order.asc(pageRequest.getSortBy())
                            : Order.desc(pageRequest.getSortBy()));
        }
    }

    page.setPageData(new AutoEvictingColumnarResultsIterator<Compliance>(session,
            query.scroll(ScrollMode.FORWARD_ONLY), 0));

    return page;
}

From source file:org.jasig.ssp.dao.PersonDao.java

License:Apache License

public PagingWrapper<Person> getAllAssignedCoaches(SortingAndPaging sAndP) {

    DetachedCriteria coach_ids = DetachedCriteria.forClass(Person.class, "coach_ids");
    final ProjectionList projections = Projections.projectionList();
    projections.add(Projections.distinct(Projections.property("coach.id")));
    coach_ids.setProjection(projections);
    coach_ids.add(Restrictions.isNotNull("coach"));

    Criteria criteria = createCriteria().add(Subqueries.propertiesIn(new String[] { "id" }, coach_ids));

    if (sAndP != null && sAndP.isFilteredByStatus()) {
        sAndP.addStatusFilterToCriteria(criteria);
    }//from w  w w.j  av a 2 s  .  c om

    // item count
    Long totalRows = 0L;
    if ((sAndP != null) && sAndP.isPaged()) {
        totalRows = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();
    }

    criteria.setProjection(null);

    if (sAndP == null || !(sAndP.isSorted())) {
        criteria.addOrder(Order.asc("lastName")).addOrder(Order.asc("firstName"));
    } else {
        if (sAndP.isSorted()) {
            sAndP.addSortingToCriteria(criteria);
        }
        sAndP.addPagingToCriteria(criteria);
    }

    return new PagingWrapper<Person>(totalRows, criteria.list());

}

From source file:org.jasig.ssp.dao.PersonDao.java

License:Apache License

public PagingWrapper<CoachPersonLiteTO> getAllAssignedCoachesLite(SortingAndPaging sAndP,
        String homeDepartment) {//from  w ww.  j  a  v a2  s  .c o m

    DetachedCriteria coach_ids = DetachedCriteria.forClass(Person.class, "coach_ids");
    final ProjectionList projections = Projections.projectionList();
    projections.add(Projections.distinct(Projections.property("coach.id")));
    coach_ids.setProjection(projections);
    coach_ids.add(Restrictions.isNotNull("coach"));

    Criteria criteria = createCriteria().add(Subqueries.propertiesIn(new String[] { "id" }, coach_ids));

    if (sAndP != null && sAndP.isFilteredByStatus()) {
        sAndP.addStatusFilterToCriteria(criteria);
    }

    if (homeDepartment != null && homeDepartment.length() >= 0) {
        criteria.createAlias("staffDetails", "personStaffDetails");
        criteria.add(Restrictions.eq("personStaffDetails.departmentName", homeDepartment));
    } else {
        criteria.createAlias("staffDetails", "personStaffDetails", JoinType.LEFT_OUTER_JOIN);
    }

    // item count
    Long totalRows = 0L;
    if ((sAndP != null) && sAndP.isPaged()) {
        totalRows = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();
    }

    criteria.setProjection(null);
    criteria.setProjection(Projections.projectionList().add(Projections.property("id").as("person_id"))
            .add(Projections.property("firstName").as("person_firstName"))
            .add(Projections.property("lastName").as("person_lastName"))
            .add(Projections.property("primaryEmailAddress").as("person_primaryEmailAddress"))
            .add(Projections.property("workPhone").as("person_workPhone"))
            .add(Projections.property("personStaffDetails.departmentName").as("person_departmentName")))
            .setResultTransformer(
                    new NamespacedAliasToBeanResultTransformer(CoachPersonLiteTO.class, "person_"));

    return new PagingWrapper<CoachPersonLiteTO>(totalRows, criteria.list());

}