Example usage for org.hibernate.criterion Projections property

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

Introduction

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

Prototype

public static PropertyProjection property(String propertyName) 

Source Link

Document

A property value projection

Usage

From source file:com.jaspersoft.jasperserver.search.filter.ScheduleFilter.java

License:Open Source License

private void createCriteria(SearchCriteria criteria, User user, boolean scheduled, boolean scheduledByUser) {
    SearchCriteria uriCriteria = SearchCriteria.forClass(PersistentReportJob.class);
    if (scheduledByUser) {
        addOwnerCriteria(uriCriteria, user);
    }/*  w  w w .j  a va 2s  .  c  o  m*/
    uriCriteria.addProjection(Projections.property("source.reportUnitURI"));
    List uriList = getHibernateTemplate().findByCriteria(uriCriteria);

    if (!uriList.isEmpty()) {
        SearchCriteria idCriteria = SearchCriteria.forClass(RepoResource.class);
        Disjunction disjunction = Restrictions.disjunction();
        String alias = idCriteria.getAlias("parent", "p");
        for (Object o : uriList) {
            String uri = (String) o;

            disjunction.add(getResourceCriterion(alias, uri));
        }

        idCriteria.add(disjunction);
        idCriteria.addProjection(Projections.id());

        List idList = getHibernateTemplate().findByCriteria(idCriteria);

        if (!idList.isEmpty()) {
            if (scheduled) {
                criteria.add(Restrictions.in("id", idList));
            } else {
                criteria.add(Restrictions.not(Restrictions.in("id", idList)));
            }
        } else {
            throw new RuntimeException("No resources found for URI list " + uriList);
        }
    } else {
        if (scheduled || scheduledByUser) {
            criteria.add(Restrictions.isNull("id"));
        }
    }
}

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

License:Open Source License

@Override
protected void addProjection(String type, ExecutionContext context, SearchCriteria criteria) {
    criteria.addProjection(Projections.property("creationDate"));
}

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

License:Open Source License

@Override
protected void addProjection(String type, ExecutionContext context, SearchCriteria criteria) {
    criteria.addProjection(Projections.property("updateDate"));
}

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

License:Open Source License

@Override
protected void addProjection(String type, ExecutionContext context, SearchCriteria criteria) {
    criteria.addProjection(Projections.property("description"));
}

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

License:Open Source License

@Override
protected void addProjection(String type, ExecutionContext context, SearchCriteria criteria) {
    criteria.addProjection(Projections.property("label"));
}

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

License:Open Source License

@Override
protected void addProjection(String type, ExecutionContext context, SearchCriteria criteria) {
    criteria.addProjection(Projections.property("resourceType"));
}

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

License:Open Source License

@Override
protected void addProjection(String type, ExecutionContext context, SearchCriteria criteria) {
    criteria.addProjection(Projections.property("parent")).addProjection(Projections.property("name"));
}

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

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<String> fetchProductNames(String name) {
    session = getSessionFactory().getCurrentSession();
    return session.createCriteria(Products.class)
            .setProjection(Projections.projectionList().add(Projections.property("name")))
            .add(Restrictions.ilike("name", name, MatchMode.START))
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).list();

}

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

@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<String> fetchCampaignNames(String name) {
    session = getSessionFactory().getCurrentSession();
    return session.createCriteria(Campaigns.class)
            .setProjection(Projections.projectionList().add(Projections.property("name")))
            .add(Restrictions.ilike("name", name, MatchMode.START))
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).list();
}

From source file:com.klistret.cmdb.dao.ElementDAOImpl.java

License:Open Source License

/**
 * Necessary to use the Projections to limit the selected columns to only
 * those defined to the Element tables (otherwise the returned columns
 * contains all columns for all associations).
 * //from   ww  w .  j  a  v a 2 s  .  co m
 * @see com.klistret.cmdb.dao.ElementDAO.findByCriteria
 * @return Collection
 */
public List<Element> find(List<String> expressions, int start, int limit) {
    try {
        logger.debug("Finding elements by expression from start position [{}] with limit [{}] for session [{}]",
                new Object[] { start, limit, getSession().hashCode() });

        if (expressions == null)
            throw new ApplicationException("Expressions parameter is null", new IllegalArgumentException());

        Criteria criteria = new XPathCriteria(expressions, getSession()).getCriteria();

        criteria.setProjection(Projections.projectionList().add(Projections.property("id"))
                .add(Projections.property("type")).add(Projections.property("name"))
                .add(Projections.property("fromTimeStamp")).add(Projections.property("toTimeStamp"))
                .add(Projections.property("createId")).add(Projections.property("createTimeStamp"))
                .add(Projections.property("updateTimeStamp")).add(Projections.property("version"))
                .add(Projections.property("configuration")));

        criteria.addOrder(Order.asc("name"));

        criteria.setFirstResult(start);
        criteria.setFetchSize(limit);
        criteria.setMaxResults(limit);

        Object[] results = criteria.list().toArray();

        List<Element> elements = new ArrayList<Element>(results.length);
        logger.debug("Results length [{}]", results.length);

        for (int index = 0; index < results.length; index++) {
            Object[] row = (Object[]) results[index];

            Element element = new Element();
            element.setId((Long) row[0]);
            element.setType((ElementType) row[1]);
            element.setName((String) row[2]);
            element.setFromTimeStamp((Date) row[3]);
            element.setToTimeStamp((Date) row[4]);
            element.setCreateId((String) row[5]);
            element.setCreateTimeStamp((Date) row[6]);
            element.setUpdateTimeStamp((Date) row[7]);
            element.setVersion((Long) row[8]);
            element.setConfiguration((com.klistret.cmdb.ci.commons.Element) row[9]);

            elements.add(element);
        }

        results = null;

        return elements;
    } catch (StaleStateException e) {
        throw new ApplicationException("Element(s) found are stale which means newer version exists.");
    } catch (HibernateException e) {
        throw new InfrastructureException(e.getMessage(), e);
    }
}