Example usage for org.hibernate.criterion Projections projectionList

List of usage examples for org.hibernate.criterion Projections projectionList

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections projectionList.

Prototype

public static ProjectionList projectionList() 

Source Link

Document

Create a new projection list.

Usage

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

@Override
public List<LoanNewType> getAllDataPayrollComponent(Long modelComponentId) {
    ProjectionList subProjection = Projections.projectionList();
    subProjection.add(Projections.groupProperty("modelReffernsil"));

    DetachedCriteria subQuery = DetachedCriteria.forClass(PaySalaryComponent.class);
    subQuery.createAlias("modelComponent", "modelComponent", JoinType.INNER_JOIN);
    subQuery.add(Restrictions.eq("modelComponent.id", modelComponentId));
    subQuery.setProjection(subProjection);

    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Property.forName("id").notIn(subQuery));
    return criteria.list();
}

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

@Override
public List<TempJadwalKaryawan> getByGroupKerjadId(long kerjaId) {
    //        Criteria criteria = getCurrentSession().createCriteria(EmpData.class);

    ProjectionList proList = Projections.projectionList();
    //        proList.add(Property.forName("sequence").max());
    proList.add(Projections.groupProperty("id"));
    DetachedCriteria kelompokData = DetachedCriteria.forClass(EmpData.class).createAlias("wtGroupWorking", "wt")
            .add(Restrictions.eq("wt.id", kerjaId)).setProjection(proList);
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("empData", "em");
    criteria.add(Property.forName("em.id").in(kelompokData));
    return criteria.list();

}

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:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateRepositoryServiceImpl.java

License:Open Source License

@Transactional(propagation = Propagation.REQUIRED)
public List<Long> getResourcesIds(ExecutionContext context, String text, Class type, Class aClass,
        List<SearchFilter> filters, Map<String, SearchFilter> typeSpecificFilters, SearchSorter sorter,
        TransformerFactory transformerFactory, int firstResult, int maxResult) {
    if (transformerFactory == null) {
        throw new IllegalArgumentException("Transformer factory is null.");
    }/*  www  .java  2  s  .  c om*/

    SearchCriteria criteria = getResourcesListCriteria(context, text, type, aClass, filters,
            typeSpecificFilters);

    ProjectionList distinctProperties = Projections.projectionList().add(Projections.id());
    criteria.addProjection(Projections.distinct(distinctProperties));

    if (sorter != null) {
        sorter.applyOrder(type.getName(), context, criteria);
    }

    List list = getHibernateTemplate().findByCriteria(criteria, firstResult, maxResult);

    List<Long> ids = new ArrayList<Long>();
    ResultTransformer transformer = transformerFactory.createTransformer(filters, sorter);
    if (transformer != null) {
        ids.addAll(transformer.transformToIdList(list));
    } else {
        throw new IllegalArgumentException("Result transformer is null.");
    }

    return ids;
}

From source file:com.jaspersoft.jasperserver.api.metadata.tenant.service.impl.TenantServiceImpl.java

License:Open Source License

public Map<String, Integer> getSubTenantsCountMap(List<String> tenantIds) {
    if (tenantIds == null || tenantIds.size() == 0) {
        return Collections.emptyMap();
    }/*from www. j  a  v a2  s.  c o  m*/

    DetachedCriteria criteria = DetachedCriteria.forClass(persistentTenantClass());

    criteria.createAlias("parent", "p");
    criteria.add(Restrictions.in("p.tenantId", tenantIds));

    criteria.setProjection(Projections.projectionList().add(Projections.rowCount())
            .add(Projections.groupProperty("p.tenantId")));
    criteria.getExecutableCriteria(getSession()).setCacheable(true);

    List results = getHibernateTemplate().findByCriteria(criteria);

    Map<String, Integer> subTenantCounts = new HashMap<String, Integer>(tenantIds.size(), 1);
    if (results != null && results.size() > 0) {
        for (Object result : results) {
            String tenantId = (String) ((Object[]) result)[1];
            Integer count = (Integer) ((Object[]) result)[0];

            subTenantCounts.put(tenantId, count);
        }
    }

    for (String tenantId : tenantIds) {
        if (!subTenantCounts.containsKey(tenantId)) {
            subTenantCounts.put(tenantId, 0);
        }
    }

    return subTenantCounts;
}

From source file:com.jaspersoft.jasperserver.api.search.SearchCriteria.java

License:Open Source License

public SearchCriteria addProjection(Projection projection) {
    Projection oldProjection = ((CriteriaImpl) criteria).getProjection();

    if (projection == null || oldProjection == null) {
        criteria.setProjection(projection);
        return this;
    }// ww w  .ja  va  2s  . c  om

    if (oldProjection instanceof ProjectionList) {
        addProjectionToList(((ProjectionList) oldProjection), projection);
    } else {
        ProjectionList list = Projections.projectionList().add(oldProjection);
        criteria.setProjection(addProjectionToList(list, projection));
    }

    return this;
}

From source file:com.jaspersoft.jasperserver.search.sorter.ByAccessTimeSorter.java

License:Open Source License

@Override
protected void addProjection(String type, ExecutionContext context, SearchCriteria criteria) {
    String alias = criteria.getAlias("accessEvents", "ae");
    criteria.addProjection(Projections.projectionList().add(Projections.max(alias + ".eventDate"), "aed")
            .add(Projections.groupProperty("accessEvents")));

    criteria.addOrder(Order.desc("aed"));
}

From source file:com.jaspersoft.jasperserver.search.sorter.ByPopularitySorter.java

License:Open Source License

@Override
protected void addProjection(String type, ExecutionContext context, SearchCriteria criteria) {
    criteria.addProjection(Projections.projectionList().add(Projections.count("accessEvents"), "aec")
            .add(Projections.groupProperty("accessEvents")));

    criteria.addOrder(Order.desc("aec")).addOrder(Order.asc("id"));
}

From source file:com.jscompany.ebsystem.lazymodels.BaseLazyDataModel.java

@Override
public List<T> load(int first, int pageSize, String sortField, SortOrder sortOrder,
        Map<String, Object> filters) {
    List result = null;/*from   w  w w. j a v a2s.c  om*/
    Criteria cq, dcq;
    try {

        cq = EntityManagerServices.getCurrentSession().createCriteria(this.getEntity(), "entity");
        this.criteriaFilterSetup(cq, filters);
        cq.setProjection(Projections.projectionList().add(Projections.rowCount()));
        dcq = EntityManagerServices.getCurrentSession().createCriteria(this.getEntity(), "entity1");
        this.criteriaFilterSetup(dcq, filters);
        this.criteriaSortSetup(dcq, sortField, sortOrder);
        this.criteriaPageSetup(dcq, first, pageSize);
        rowCount = 0;
        rowCount = ((Long) cq.uniqueResult()).intValue();
        this.setRowCount(rowCount);
        result = dcq.list();
        Hibernate.initialize(result);
    } catch (Exception ex) {
        Logger.getLogger(BaseLazyDataModel.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result;
}

From source file:com.jubination.model.dao.DataAnalyticsDAOImpl.java

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public Object readPropertyByRecency() {
    List<DataAnalytics> list = new ArrayList<>();

    session = getSessionFactory().getCurrentSession();
    List<String> tempList = session.createCriteria(DataAnalytics.class)
            .setProjection(Projections.projectionList().add(Projections.max("requestedTime"))
            //.add(Projections.groupProperty("type"))
            ).list();//from  w  w w .j a v  a  2 s .c  o  m

    if (tempList.size() > 0) {
        list = session.createCriteria(DataAnalytics.class)
                .add(Restrictions.like("requestedTime", tempList.get(0))).list();
    }

    return (T) list;

}