Example usage for org.hibernate Criteria setProjection

List of usage examples for org.hibernate Criteria setProjection

Introduction

In this page you can find the example usage for org.hibernate Criteria setProjection.

Prototype

public Criteria setProjection(Projection projection);

Source Link

Document

Used to specify that the query results will be a projection (scalar in nature).

Usage

From source file:com.court.controller.ProfileFxmlController.java

private List<String> getAlreadyTakenUserNames() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c = session.createCriteria(User.class);
    List<String> uNames = c.setProjection(Projections.property("userName")).list();
    session.close();//from ww w  .j  ava  2 s.co  m
    return uNames;
}

From source file:com.court.controller.ReportFormFxmlController.java

private List<Branch> getBranches(boolean withAll) {
    List<Branch> bList = new ArrayList<>();
    if (withAll) {
        bList.add(new Branch(null, "All"));
    }/*  w  ww .  java 2s. com*/
    Session s = HibernateUtil.getSessionFactory().openSession();
    Criteria c = s.createCriteria(Branch.class);
    c.add(Restrictions.eq("status", true));
    c.setProjection(Projections.projectionList().add(Projections.property("branchCode"), "branchCode")
            .add(Projections.property("branchName"), "branchName"));
    c.setResultTransformer(Transformers.aliasToBean(Branch.class));
    List<Branch> list = c.list();
    bList.addAll(list);
    s.close();
    return bList;
}

From source file:com.court.controller.ReportFormFxmlController.java

private List<Branch> getPaymentOffice() {
    List<Branch> bList = new ArrayList<>();

    Session s = HibernateUtil.getSessionFactory().openSession();
    Criteria c = s.createCriteria(Branch.class);
    c.add(Restrictions.eq("status", true));
    c.add(Restrictions.eq("parentId", 0));
    c.setProjection(Projections.projectionList().add(Projections.property("branchCode"), "branchCode")
            .add(Projections.property("branchName"), "branchName"));
    c.setResultTransformer(Transformers.aliasToBean(Branch.class));
    List<Branch> list = c.list();
    bList.addAll(list);/*from   w  ww . j a  v a 2  s. com*/
    s.close();
    return bList;
}

From source file:com.court.controller.ReportFormFxmlController.java

private List<Member> getMembers(boolean withAll) {
    Session s = HibernateUtil.getSessionFactory().openSession();
    Criteria c = s.createCriteria(Member.class);
    c.setProjection(Projections.projectionList().add(Projections.property("memberId"), "memberId")
            .add(Projections.property("fullName"), "fullName"));
    c.setResultTransformer(Transformers.aliasToBean(Member.class));
    List<Member> list = c.list();
    if (withAll) {
        list.add(new Member("All"));
    }// www.  j av a 2s  .  c  o m
    s.close();
    return list;
}

From source file:com.court.controller.ReportFormFxmlController.java

private List<LoanPayCheque> getCollectionInvoice() {
    Session s = HibernateUtil.getSessionFactory().openSession();
    Criteria c = s.createCriteria(LoanPayCheque.class);
    c.setProjection(Projections.property("invoCode"));
    c.setResultTransformer(Transformers.aliasToBean(LoanPayCheque.class));
    List<LoanPayCheque> list = c.list();
    s.close();/*  ww  w  .j  a va2 s  . co  m*/
    return list;
}

From source file:com.court.controller.ReportFormFxmlController.java

private List<String> getReceiptCodes(String rptType) {

    Session s = HibernateUtil.getSessionFactory().openSession();
    Criteria c = s.createCriteria(ReceiptPay.class);
    c.add(Restrictions.eq("paymentType", rptType));
    c.setProjection(Projections.property("receiptCode"));
    List<String> list = c.list();
    return list;/* w  w w .  j  a va  2  s .c om*/

}

From source file:com.court.controller.UserManageFxmlController.java

private List<String> getAvailableUserRoles() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c = session.createCriteria(UserRole.class);
    List<String> roles = c.setProjection(Projections.property("roleName")).list();
    session.close();/*from  w  w w.  j  a v a 2s.  c om*/
    return roles;
}

From source file:com.court.controller.UserManageFxmlController.java

private List<String> getAvailableUserFullNames() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria c = session.createCriteria(User.class);
    List<String> uFullNames = c.setProjection(Projections.property("fullName")).list();
    session.close();//from w w w . ja  va  2s. c  o m
    return uFullNames;
}

From source file:com.cubeia.backoffice.accounting.core.dao.AccountingDAOImpl.java

License:Open Source License

@Override
public long countEntries(Long accountId) {
    Criteria c = createFindEntriesCriteria(accountId, 0, Integer.MAX_VALUE, null);
    c.setProjection(Projections.rowCount());
    Number count = (Number) c.uniqueResult();
    return count == null ? 0L : count.longValue();
}

From source file:com.cubeia.backoffice.users.dao.UserDAOImpl.java

License:Open Source License

@Override
public int countUsers(Long userId, Long operatorId, String name, Collection<UserStatus> includedStatuses) {
    Criteria c = createFindUserCriteria(userId, operatorId, name, includedStatuses, 0, Integer.MAX_VALUE, null,
            true);//w  w  w  . j  av  a  2 s .  c om
    c.setProjection(Projections.rowCount());
    return ((Number) c.uniqueResult()).intValue();
}