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.maydesk.base.table.PDPageableFactory.java

License:Mozilla Public License

public Projection getProjectionList() {
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.id(), "id");
    projectionList.add(Projections.property("cachedTitle"), "title"); // Model must be of type MBaseWithTitle!
    projectionList.add(Projections.property("cachedDescription"), "description"); // Model must be of type MBaseWithTitle!
    return Projections.distinct(projectionList);
}

From source file:com.metropolitan.formulasport727.dao.KorpaArtikalDAOImpl.java

@Override
public List<KorpaArtikal> getListaSvihJedinstvenihKorpaArtikalaKorpe(Korpa korpa) {
    return session.createCriteria(KorpaArtikal.class).add(Restrictions.eq("korId", korpa))
            .setProjection(Projections.projectionList().add(Projections.property("id").as("id"))
                    .add(Projections.property("korId").as("korId"))
                    .add(Projections.groupProperty("artId").as("artId")))
            .setResultTransformer(Transformers.aliasToBean(KorpaArtikal.class)).list();
}

From source file:com.muslim.family.dao.impl.QuestionDAOImpl.java

public List<Question_tbl> getPaginatedQuestionsDao(int start, int length) {

    Criteria cr = sessionFactory.getCurrentSession().createCriteria(Question_tbl.class)
            .setProjection(Projections.projectionList().add(Projections.property("id"), "id")
                    .add(Projections.property("subject"), "Subject")
                    .add(Projections.property("views"), "Views"))
            .setResultTransformer(Transformers.aliasToBean(Question_tbl.class));
    cr.setFirstResult(start);//from w w w.j a  va  2 s  .  com
    cr.setMaxResults(length);

    return cr.list();

}

From source file:com.myimage.business.ProfileImpl.java

@Override
public Properties profileActives() {

    List<Object> objects = null;
    Properties prop = new Properties();
    Criteria criteria = this.session.createCriteria(User.class);
    criteria.setProjection(/*from w  w  w. j a v  a2  s.  c  o  m*/
            Projections.projectionList().add(Projections.rowCount()).add(Projections.groupProperty("active")));

    objects = criteria.list();

    for (Object o : objects) {
        Object[] objArr = (Object[]) o;
        // chave: active, valor: quantidade
        prop.setProperty(objArr[1].toString(), objArr[0].toString());
    }
    return prop;
}

From source file:com.myimage.model.dao.ProfileDaoImpl.java

public Properties profileActives() {
    List<Object> objects = null;
    Properties prop = new Properties();
    Criteria criteria = this.session.createCriteria(User.class);
    criteria.setProjection(/* w ww.ja v a  2  s  . com*/
            Projections.projectionList().add(Projections.rowCount()).add(Projections.groupProperty("active")));

    objects = criteria.list();

    for (Object o : objects) {
        Object[] objArr = (Object[]) o;
        // chave: active, valor: quantidade
        prop.setProperty(objArr[1].toString(), objArr[0].toString());
    }
    return prop;
}

From source file:com.nec.harvest.service.impl.AccountServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from  w w w .  j  a  v  a2  s  .  c  o  m*/
public List<Account> findByIdoKbn(String idoKbn) throws ServiceException {
    if (StringUtils.isEmpty(idoKbn)) {
        throw new IllegalArgumentException("The Account's idoKbn to search must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<Account> accounts = new ArrayList<>();
    try {
        tx = session.beginTransaction();
        Criteria criteria = repository.getCriteria(session, Account.class)
                .setProjection(Projections.projectionList().add(Projections.property("kmkCode").as("kmkCode"))
                        .add(Projections.property("kmkNameR").as("kmkNameR")))
                .add(Restrictions.eq("idoKbn", idoKbn)).add(Restrictions.eq("delKbn", Constants.STATUS_ACTIVE))
                .addOrder(Order.asc("kmkCode"));

        accounts = repository.findByCriteria(criteria);

        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(accounts)) {
            throw new ObjectNotFoundException("Could not find any account with idoKbn 1");
        }
        return accounts;
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An exception occured while finding account list with idoKbn 1", ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
}

From source file:com.nec.harvest.service.impl.AccountServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from   w w  w  . j a  v  a2  s .  c om*/
public List<Account> findByKoteiKbnAndDelKbn(String koteiKhKbn, String delKbn) throws ServiceException {
    if (StringUtils.isEmpty(koteiKhKbn)) {
        throw new IllegalArgumentException("The Account's koteiKhKbn to search must not be null or empty");
    }
    if (StringUtils.isEmpty(delKbn)) {
        throw new IllegalArgumentException("The Account's delKbn to search must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<Account> accounts = new ArrayList<>();
    try {
        tx = session.beginTransaction();
        Criteria criteria = repository.getCriteria(session, Account.class)
                .setProjection(Projections.projectionList().add(Projections.property("kmkCode").as("kmkCode"))
                        .add(Projections.property("kmkNameR").as("kmkNameR")))
                .add(Restrictions.eq("koteiKhKbn", koteiKhKbn)).add(Restrictions.eq("delKbn", delKbn))
                .addOrder(Order.asc("kmkCode"));

        accounts = repository.findByCriteria(criteria);

        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(accounts)) {
            throw new ObjectNotFoundException("Could not find any account with idoKbn = 1");
        }
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An exception occured while finding account list with idoKbn = 1", ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return accounts;
}

From source file:com.nec.harvest.service.impl.AccountServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override/*ww w  .j a v a 2 s .c om*/
public List<Account> findByHelpKbn(String helpKbn) throws ServiceException {
    if (StringUtils.isEmpty(helpKbn)) {
        throw new IllegalArgumentException("The Account's idoKbn to search must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<Account> accounts = new ArrayList<>();
    try {
        tx = session.beginTransaction();
        Criteria criteria = repository.getCriteria(session, Account.class)
                .setProjection(Projections.projectionList().add(Projections.property("kmkCode").as("kmkCode"))
                        .add(Projections.property("kmkNameR").as("kmkNameR")))
                .add(Restrictions.eq("helpKbn", helpKbn))
                .add(Restrictions.eq("delKbn", Constants.STATUS_ACTIVE)).addOrder(Order.asc("kmkCode"));

        accounts = repository.findByCriteria(criteria);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(accounts)) {
            throw new ObjectNotFoundException("Could not find any account with idoKbn = 1");
        }
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An exception occured while finding account list with idoKbn = 1", ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return accounts;
}

From source file:com.nec.harvest.service.impl.DivisionServiceImpl.java

License:Open Source License

/** {@inheritDoc}*/
@Override/*from  ww  w . ja v a  2  s.co m*/
public List<Division> findByKbnId(String kbnId) throws ServiceException {
    if (StringUtils.isEmpty(kbnId)) {
        throw new IllegalArgumentException("Can not find division with kbnId empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<Division> divisions = new ArrayList<>();
    try {
        tx = session.beginTransaction();
        Criteria criteria = repository.getCriteria(session, Division.class)
                .setProjection(Projections.projectionList().add(Projections.property("kbnCode").as("kbnCode"))
                        .add(Projections.property("kbnName").as("kbnName")))
                .add(Restrictions.eq("kbnID", kbnId)).add(Restrictions.eq("delKbn", Constants.STATUS_ACTIVE))
                .addOrder(Order.asc("kbnCode")).setResultTransformer(Transformers.aliasToBean(Division.class));

        //
        divisions = repository.findByCriteria(criteria);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(divisions)) {
            throw new ObjectNotFoundException("No division object found");
        }
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("Runtime exception occur when get list of division by kbnId " + kbnId, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return divisions;
}

From source file:com.nec.harvest.service.impl.OrganizationServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override//from www .j  av a  2  s.com
public List<Organization> findByKaisoBango(String kaisoBango) throws ServiceException {
    if (StringUtils.isEmpty(kaisoBango)) {
        throw new IllegalArgumentException("The organization's code must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<Organization> organizations = new ArrayList<Organization>();
    try {
        tx = session.beginTransaction();
        Criteria criteria = repository.getCriteria(session, Organization.class)
                .setProjection(Projections.projectionList().add(Projections.property("strCode").as("strCode"))
                        .add(Projections.property("strNameR").as("strNameR")))
                .add(Restrictions.eq("kaisoBango", kaisoBango))
                .add(Restrictions.eq("delKbn", Constants.STATUS_ACTIVE))
                .setResultTransformer(Transformers.aliasToBean(Organization.class));

        // 
        organizations = repository.findByCriteria(criteria);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(organizations)) {
            throw new ObjectNotFoundException("Could not find any Organization with kaisoBango " + kaisoBango);
        }
        // sort organizations by code value
        Collections.sort(organizations);
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException(
                "An exception occured while finding Organization list with kaisoBango " + kaisoBango, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return organizations;
}