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:net.longfalcon.newsj.persistence.hibernate.BinaryDAOImpl.java

License:Open Source License

@Override
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<MatchedReleaseQuery> findBinariesByProcStatAndTotalParts(int procstat) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Binary.class);
    criteria.add(Restrictions.eq("procStat", procstat));
    criteria.setProjection(Projections.projectionList().add(Projections.rowCount(), "numberOfBinaries")
            .add(Projections.groupProperty("groupId").as("group"))
            .add(Projections.groupProperty("reqId").as("reqId"))
            .add(Projections.groupProperty("relName").as("releaseName"))
            .add(Projections.groupProperty("relTotalPart").as("releaseTotalParts"))
            .add(Projections.groupProperty("fromName").as("fromName")));
    criteria.setResultTransformer(Transformers.aliasToBean(MatchedReleaseQuery.class));
    return criteria.list();
}

From source file:net.longfalcon.newsj.persistence.hibernate.PartDAOImpl.java

License:Open Source License

/**
 * findDistinctMessageIdSizeAndPartNumberByBinaryId
 * @param binaryId//  w  w  w  .  j  a  v  a2s  .  c o  m
 * @return list of {String,Long,Integer}
 */
@Override
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<Object[]> findDistinctMessageIdSizeAndPartNumberByBinaryId(long binaryId) {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Part.class);
    criteria.add(Restrictions.eq("binaryId", binaryId));
    criteria.setProjection(
            Projections.projectionList().add(Projections.distinct(Projections.property("messageId")))
                    .add(Projections.property("size")).add(Projections.property("partNumber")));
    criteria.addOrder(Order.desc("partNumber"));

    return criteria.list();
}

From source file:net.longfalcon.newsj.persistence.hibernate.ReleaseDAOImpl.java

License:Open Source License

/**
 *
 * @return List of Object[] = {Category,long}
 *///from w ww .  j av  a2 s.c om
@Override
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<Object[]> findRecentlyAddedReleaseCategories() {
    Date oneWeekAgo = DateTime.now().minusWeeks(1).toDate();
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Release.class);
    criteria.add(Restrictions.ge("addDate", oneWeekAgo));
    criteria.setProjection(
            Projections.projectionList().add(Projections.groupProperty("category").as("category"))
                    .add(Projections.count("id").as("count")));
    criteria.addOrder(Order.desc("count"));
    criteria.setMaxResults(10);

    return criteria.list();
}

From source file:net.neurowork.cenatic.centraldir.dao.impl.HibernateOrganizacionDaoImpl.java

License:Apache License

@SuppressWarnings("rawtypes")
@Override//www . jav a2s. c o  m
public Integer getTotalOrganizaciones() throws DaoException {
    if (logger.isTraceEnabled())
        logger.trace("Hibernate Searching Total Organizaciones");
    DetachedCriteria criteria = DetachedCriteria.forClass(Organizacion.class);

    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.rowCount());
    criteria.setProjection(projList);

    List result = getHibernateTemplate().findByCriteria(criteria);
    if (result != null)
        return (Integer) result.get(0);
    return 0;
}

From source file:net.neurowork.cenatic.centraldir.dao.impl.HibernateSateliteDaoImpl.java

License:Apache License

@SuppressWarnings("rawtypes")
@Override/*  w  ww  . j a  va 2 s .  co  m*/
public Integer getOrganizacionesCount(Satelite satelite) throws DaoException {
    if (logger.isTraceEnabled())
        logger.trace("Hibernate Searching Total Organizaciones");
    DetachedCriteria criteria = DetachedCriteria.forClass(OrganizacionSatelite.class);

    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.rowCount());
    criteria.setProjection(projList);
    criteria.add(Restrictions.eq("satelite", satelite));

    List result = getHibernateTemplate().findByCriteria(criteria);
    if (result != null)
        return (Integer) result.get(0);
    return 0;

}

From source file:net.purnama.pureff.dao.WarehouseDao.java

public List<WarehouseEntity> getWarehouse_IdCode_List() {
    Session session = this.sessionFactory.getCurrentSession();
    Criteria cr = session.createCriteria(WarehouseEntity.class);

    cr.add(Restrictions.eq("status", true));

    cr.setProjection(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("code"), "code"))
            .setResultTransformer(Transformers.aliasToBean(WarehouseEntity.class));

    List<WarehouseEntity> list = cr.list();

    return list;/*from w  w  w  . j  av  a  2 s . c om*/
}

From source file:net.thackbarth.sparrow.DatabaseCleaner.java

License:Apache License

void removeDoubleFiles(Session session) {
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty(PROPERTY_FILE_PATH).as(PROPERTY_FILE_PATH))
            .add(Projections.count(PROPERTY_FILE_PATH).as(PROPERTY_AMOUNT));
    Criteria doubleCriteria = session.createCriteria(MusicTrack.class).setProjection(projectionList)
            .setMaxResults(configuration.getBatchSize()).addOrder(Order.desc(PROPERTY_AMOUNT));

    boolean uniqueFileFound = false;
    do {//from w w w . j  a  va 2 s. c  o  m
        progress.info("Delete double files from database.");
        List doubleList = doubleCriteria.list();
        if (doubleList.isEmpty()) {
            uniqueFileFound = true;
        } else {
            for (Object obj : doubleList) {
                uniqueFileFound = checkDoubleFiles(session, (Object[]) obj) || uniqueFileFound;
            }
        }
        session.flush();
    } while (!uniqueFileFound);
}

From source file:org.ambraproject.admin.service.impl.AdminRolesServiceImpl.java

License:Apache License

/**
 * Get all the available user roles.  If the passed in user has the mentioned role, it will be
 * noted as such in the view/*ww w  .  ja  v  a  2  s  .  c o m*/
 * @return
 */
@SuppressWarnings("unchecked")
public List<UserRoleView> getAllRoles(final Long userProfileID) {
    return (List<UserRoleView>) hibernateTemplate.execute(new HibernateCallback() {
        @Override
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            UserProfile profile = (UserProfile) session.load(UserProfile.class, userProfileID);
            List<Object[]> results = (List<Object[]>) session.createCriteria(UserRole.class)
                    .setProjection(Projections.projectionList().add(Projections.property("ID"))
                            .add(Projections.property("roleName")))
                    .list();

            List<UserRoleView> roleViews = new ArrayList<UserRoleView>();

            for (Object[] row : results) {
                boolean assigned = false;

                for (UserRole role : profile.getRoles()) {
                    if (role.getID().equals((Long) row[0])) {
                        assigned = true;
                        break;
                    }
                }

                roleViews.add(new UserRoleView((Long) row[0], (String) row[1], assigned));
            }

            return roleViews;
        }
    });
}

From source file:org.ambraproject.admin.service.impl.AdminServiceImpl.java

License:Apache License

@Override
@Transactional(readOnly = true)//from w  w w .  ja  va 2  s .c  om
@SuppressWarnings("unchecked")
public List<ArticleInfo> getPublishableArticles(String eIssn, String orderField, boolean isOrderAscending)
        throws ApplicationException {

    List<ArticleInfo> articlesInfo = new ArrayList<ArticleInfo>();
    Order order = isOrderAscending ? Order.asc(orderField) : Order.desc(orderField);
    List<Object[]> results = hibernateTemplate.findByCriteria(DetachedCriteria.forClass(Article.class)
            .add(Restrictions.eq("eIssn", eIssn)).add(Restrictions.eq("state", Article.STATE_UNPUBLISHED))
            .addOrder(order).setProjection(Projections.projectionList().add(Projections.property("doi"))
                    .add(Projections.property("date"))));

    for (Object[] rows : results) {
        ArticleInfo articleInfo = new ArticleInfo();
        articleInfo.setDoi(rows[0].toString());
        articleInfo.setDate((Date) rows[1]);
        articlesInfo.add(articleInfo);
    }

    return articlesInfo;
}

From source file:org.ambraproject.admin.service.impl.AdminServiceImpl.java

License:Apache License

@Override
@Transactional//from  w ww  .j  av  a 2s  .  c om
public void addIssueToVolume(final String volumeUri, final Issue issue) {
    if (StringUtils.isEmpty(issue.getIssueUri())) {
        throw new IllegalArgumentException("Must specify an Issue URI");
    }
    log.debug("Creating an issue with uri: '{}' and adding it to volume: '{}'", issue.getIssueUri(), volumeUri);
    if (((Number) hibernateTemplate.findByCriteria(DetachedCriteria.forClass(Issue.class)
            .add(Restrictions.eq("issueUri", issue.getIssueUri())).setProjection(Projections.rowCount()))
            .get(0)).intValue() > 0) {
        throw new IllegalArgumentException("An issue with uri '" + issue.getIssueUri() + "' already exists");
    }
    Volume storedVolume;
    try {
        storedVolume = (Volume) hibernateTemplate.findByCriteria(DetachedCriteria.forClass(Volume.class)
                .add(Restrictions.eq("volumeUri", volumeUri)).setFetchMode("issues", FetchMode.JOIN)
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)).get(0);
    } catch (IndexOutOfBoundsException e) {
        throw new IllegalArgumentException("Volume '" + volumeUri + "' doesn't exist");
    }
    if (StringUtils.isEmpty(issue.getTitle()) || StringUtils.isEmpty(issue.getDescription())) {
        try {
            Object[] titleAndDescription = (Object[]) hibernateTemplate.findByCriteria(
                    DetachedCriteria.forClass(Article.class).add(Restrictions.eq("doi", issue.getImageUri()))
                            .setProjection(Projections.projectionList().add(Projections.property("title"))
                                    .add(Projections.property("description"))))
                    .get(0);
            issue.setTitle(
                    StringUtils.isEmpty(issue.getTitle()) ? (String) titleAndDescription[0] : issue.getTitle());
            issue.setDescription(StringUtils.isEmpty(issue.getDescription()) ? (String) titleAndDescription[1]
                    : issue.getDescription());
        } catch (IndexOutOfBoundsException e) {
            //it's fine if the image article doesn't exist
        }
    }
    storedVolume.getIssues().add(issue);
    hibernateTemplate.update(storedVolume);
}