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.griffinslogistics.db.helpers.BooksHelper.java

public List<BookModel> getBookModelsByTransportation(Transportation transportation) {
    logger.log(Level.SEVERE, "{0}: getBookModelsByTransportation started", CLASS_NAME);

    List<BookModel> resultList = new ArrayList<BookModel>();

    this.session = HibernateUtil.getSessionFactory().openSession();
    Transaction transaction = this.session.beginTransaction();

    try {//from  w w  w. j a va 2s  .  c o m
        Criteria criteria = this.session.createCriteria(Book.class);
        criteria.add(Restrictions.eq("transportation", transportation));
        criteria.setProjection(
                Projections.projectionList().add(Projections.groupProperty("bookNumber"), "bookNumber")
                        .add(Projections.property("title"), "title"))
                .setResultTransformer(Transformers.aliasToBean(BookModel.class));

        resultList = criteria.list();
        Collections.reverse(resultList);
        transaction.commit();
    } catch (HibernateException e) {
        transaction.rollback();
        logger.log(Level.SEVERE, e.getMessage());
    } finally {
        this.session.close();

        logger.log(Level.SEVERE, "{0}: getBookModelsByTransportation finished", CLASS_NAME);
    }

    return resultList;
}

From source file:com.hmsinc.epicenter.model.geography.impl.GeographyRepositoryImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
private <T extends Geography> List<Long> getGeographyMatches(final String name, final Class<T> geographyType) {
    Validate.notNull(name);/* w  w  w .  j  av a2 s . c o  m*/
    Validate.notNull(geographyType);

    return criteriaQuery(entityManager, geographyType).add(Restrictions.ilike("name", name))
            .setProjection(Projections.property("id")).list();
}

From source file:com.hmsinc.epicenter.model.workflow.impl.WorkflowRepositoryImpl.java

License:Open Source License

/**
 * Get the subquery for filtering based on events.
 * /*from   w  ww. jav  a  2s .  co  m*/
 * @param geometry
 * @return
 */
private DetachedCriteria getInvestigationGeometryFilter(final Geometry geometry) {

    final DetachedCriteria dc = DetachedCriteria.forClass(Event.class, "event");
    dc.createCriteria("event.investigations").add(Restrictions.eqProperty("id", "investigation.id"));
    dc.createCriteria("event.geography")
            .add(SpatialRestrictions.withinOrFilter("geometry", geometry, 1000, true));
    dc.setProjection(Projections.property("id"));

    //   dc.setComment(" */ /*+ ORDERED ");
    return dc;
}

From source file:com.hrms.manager.DeductionManager.java

public boolean validateDeductionlist(Deductions p) {
    Session s = HibernateUtil.getSessionFactory().openSession();
    Transaction t = s.beginTransaction();
    List l = new ArrayList();
    List l1 = new ArrayList();
    try {//from w  w  w  .j  a va 2s  .  c o  m
        int empid = p.getEmpId();
        String date = p.getRecordCreationDate();
        DeductionMaster i = new DeductionMaster();
        Date realdate = new Date();
        SimpleDateFormat s1 = new SimpleDateFormat("dd-MM-yy");
        Date d1 = s1.parse(date);
        System.out.println("Date is [[[[[[[[[[[[[[[" + d1);
        Calendar cal = Calendar.getInstance();
        cal.setTime(d1);
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;

        System.out.println("Incentives year year isssssssss" + year);
        System.out.println("Incentives month isssssssss" + month);
        Criteria c = s.createCriteria(DeductionMaster.class);
        c.add(Restrictions.eq("employeeProfileByEmpdId.empId", empid))
                .setProjection(Projections.property("ddate"));
        l = c.list();

        //   .add(Restrictions.eq("year(ddate)",year));
        System.out.println("list in Incentives is';;';';;';'';;'--------" + l);
        for (int i1 = 0; i1 < l.size(); i1++) {
            Date ddd = (Date) l.get(i1);
            System.out.println("Incentives iterator is---------" + ddd);
            cal.setTime(ddd);
            int year8 = cal.get(Calendar.YEAR);
            int month8 = cal.get(Calendar.MONTH) + 1;
            if (year == year8 && month == month8) {
                realdate = ddd;
            }
        }
        System.out.println("real date is..............." + realdate);
        Criteria c1 = s.createCriteria(DeductionMaster.class);
        i = (DeductionMaster) c1.add(Restrictions.eq("ddate", realdate))
                .add(Restrictions.eq("employeeProfileByEmpdId.empId", empid)).uniqueResult();
        l1 = c1.list();

        if (l1.size() > 0) {
            //session.close();
            return true;
        }
        t.commit();
        s.close();
    } catch (Exception e) {
        //session.getTransaction().rollback();
    } finally {
        if (s != null) {
            // session.close();
        }
    }

    return false;
}

From source file:com.hrms.manager.DeductionRuleManager.java

public List<String> getGradeList() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = session.beginTransaction();
    List<String> le = new ArrayList<>();
    Criteria c = session.createCriteria(EmployeeProfile.class);
    c.setProjection(Projections.distinct(Projections.property("empGrade")));
    List emp = c.list();//from   w  w  w .  j  a  v a  2s . c  om
    System.out.println("--------------->" + emp);
    return emp;
}

From source file:com.hrms.manager.GasManager.java

public List consumerno(Gasdto q) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = session.beginTransaction();
    List<GasConnectionMaster> list1 = null;
    int empId = q.getEmpId();
    String quartertype = null;//  ww w  . j  av a2 s  .  c  om
    String sql = null;
    List quartercode;
    // List l=null;
    List<GasAllotment> list = (List<GasAllotment>) session.createCriteria(GasAllotment.class).list();
    if (list.isEmpty()) {
        Criteria cr = session.createCriteria(GasConnectionMaster.class).setProjection(
                Projections.projectionList().add(Projections.property("consumerNumber"), "consumerNumber"));

        list1 = cr.list();
        System.out.println(list1);
        return list1;
    } else

        sql = "select r.consumer_number from gas_connection_master r where  r.connection_id not in (select connection_id from gas_allotment) ";
    SQLQuery query = session.createSQLQuery(sql);
    //  query.setParameter("quartertype",quartertype);
    quartercode = query.list();

    //     System.out.println(quartercode);
    return quartercode;
}

From source file:com.hrms.manager.HRMSManager.java

public List<String> getQuarters()

{
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = session.beginTransaction();
    Criteria c = session.createCriteria(ResidentialQuarters.class);
    c.setProjection(Projections.distinct(Projections.property("quarterType")));
    List emp = c.list();/*from   w w w  .j  av  a 2  s  .  com*/
    return emp;
}

From source file:com.hrms.manager.IncentivesManager.java

public void insertIncentive(IncentivesForm form) {
    Session s = HibernateUtil.getSessionFactory().openSession();
    Transaction t = s.beginTransaction();
    try {/*from  www  .j a va  2s .  co m*/
        String dod = form.getDate();
        int days = form.getDays();
        int inc = form.getInc();
        int id = form.getEmpId();
        SimpleDateFormat sf = new SimpleDateFormat("dd-MM-yy");
        Date doj1 = sf.parse(dod);

        Incentives i = new Incentives();
        i.setInc(inc);
        i.setIncentiveCode(form.getIncentiveCode());
        i.setIncentiveId(form.getIncentiveId());
        i.setIncentiveName(form.getIncentiveName());
        i.setDays(days);
        i.setDate(doj1);
        Calendar cal = Calendar.getInstance();
        cal.setTime(doj1);
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        EmployeeProfile e = new EmployeeProfile();
        Criteria c2 = s.createCriteria(EmployeeProfile.class);
        e = (EmployeeProfile) c2.add(Restrictions.eq("empId", id)).uniqueResult();
        i.setEmployeeProfile(e);

        Wages w = new Wages();
        Criteria c = s.createCriteria(Wages.class);

        w = (Wages) c.add(Restrictions.eq("employeeProfile.empId", id)).uniqueResult();
        System.out.println("\n mmmmmmmmmmmmmmm" + c);
        int wage = w.getBasicRate();
        System.out.println("wage is''''''''''''''" + w.getBasicRate());

        int earn = days * wage;
        System.out.println("earn is''''''''''''''" + earn);
        int incamt = inc * days;
        System.out.println("incamt is''''''''''''''" + incamt);
        int gross_sal = incamt + wage;
        List l = null;
        Date realdate = null;
        DeductionMaster d = new DeductionMaster();
        Criteria c3 = s.createCriteria(DeductionMaster.class);
        c3.add(Restrictions.eq("employeeProfileByEmpdId.empId", id))
                .setProjection(Projections.property("ddate"));
        l = c3.list();

        //   .add(Restrictions.eq("year(ddate)",year));
        System.out.println("list in Deductions is';;';';;';'';;'--------");
        for (int i1 = 0; i1 < l.size(); i1++) {
            Date ddd = (Date) l.get(i1);
            System.out.println("iterator is---------" + ddd);
            cal.setTime(ddd);
            int year8 = cal.get(Calendar.YEAR);
            int month8 = cal.get(Calendar.MONTH) + 1;
            if (year == year8 && month == month8) {
                realdate = ddd;
            }
        }
        System.out.println("real date is..............." + realdate);

        Criteria c1 = s.createCriteria(DeductionMaster.class);
        d = (DeductionMaster) c1.add(Restrictions.eq("ddate", realdate))
                .add(Restrictions.eq("employeeProfileByEmpdId.empId", id)).uniqueResult();

        int total_ded = d.getTotalDeductions();
        System.out.println("total deductions is''''''''''''''" + d.getTotalDeductions());
        System.out.println("\n bbbbbbbbbbbbbbbbb" + total_ded);
        int net_sal = gross_sal - total_ded;
        System.out.println("wage is''''''''''''''" + net_sal);

        i.setWage(wage);
        i.setEarn(earn);
        i.setIncAmount(incamt);
        i.setGrossSalary(gross_sal);
        i.setNetSalary(net_sal);
        i.setDeptiId(e.getDepartments());
        s.save(i);
        t.commit();
        System.out.println("\n Incentives inserted successfully");
    } catch (HibernateException h) {
        System.out.println("Hibernate Exception during insertion" + h);
        h.printStackTrace();
    }

    catch (Exception e) {
        System.out.println("Exception during insertion" + e);
        e.printStackTrace();
    } finally {
        s.close();
    }
}

From source file:com.hrms.manager.IncentivesManager.java

public void updateIncentive(IncentivesForm form, int id1) {
    s = HibernateUtil.getSessionFactory().openSession();
    Transaction t = s.beginTransaction();
    try {/*w w w .ja  v  a2  s  .  co m*/
        int days = form.getDays();
        int inc = form.getInc();
        int id = form.getEmpId();
        int incid = form.getIncentiveId();
        System.out.println("----------------->incen update");
        Incentives i = new Incentives();
        i = (Incentives) s.get(Incentives.class, id1);
        i.setInc(inc);
        i.setIncentiveCode(form.getIncentiveCode());
        i.setIncentiveId(form.getIncentiveId());
        i.setIncentiveName(form.getIncentiveName());
        i.setDays(days);
        EmployeeProfile e = new EmployeeProfile();
        Criteria c4 = s.createCriteria(EmployeeProfile.class);
        e = (EmployeeProfile) c4.add(Restrictions.eq("empId", form.getEmpId())).uniqueResult();

        i.setEmployeeProfile(e);
        Wages w = new Wages();
        Criteria c = s.createCriteria(Wages.class);

        w = (Wages) c.add(Restrictions.eq("employeeProfile.empId", id)).uniqueResult();
        System.out.println("\n mmmmmmmmmmmmmmm" + c);
        int wage = w.getBasicRate();
        System.out.println("wage is''''''''''''''" + w.getBasicRate());

        int earn = days * wage;
        System.out.println("earn is''''''''''''''" + earn);
        int incamt = inc * days;
        System.out.println("incamt is''''''''''''''" + incamt);
        int gross_sal = incamt + wage;

        Criteria c1 = s.createCriteria(Incentives.class);
        i = (Incentives) c1.add(Restrictions.eq("incentiveId", incid)).uniqueResult();
        Date ddd = i.getDate();
        Calendar cal = Calendar.getInstance();
        cal.setTime(ddd);
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;

        List l = null;
        Date realdate = null;
        DeductionMaster d = new DeductionMaster();
        Criteria c3 = s.createCriteria(DeductionMaster.class);
        c3.add(Restrictions.eq("employeeProfileByEmpdId.empId", id))
                .setProjection(Projections.property("ddate"));
        l = c3.list();

        for (int i1 = 0; i1 < l.size(); i1++) {
            Date dd = (Date) l.get(i1);
            System.out.println("iterator is---------" + dd);
            cal.setTime(dd);
            int year8 = cal.get(Calendar.YEAR);
            int month8 = cal.get(Calendar.MONTH) + 1;
            if (year == year8 && month == month8) {
                realdate = dd;
            }
        }
        System.out.println("real date is..............." + realdate);

        Criteria c2 = s.createCriteria(DeductionMaster.class);
        d = (DeductionMaster) c2.add(Restrictions.eq("ddate", realdate))
                .add(Restrictions.eq("employeeProfileByEmpdId.empId", id)).uniqueResult();

        int total_ded = d.getTotalDeductions();
        System.out.println("total deductions is''''''''''''''" + d.getTotalDeductions());
        System.out.println("\n bbbbbbbbbbbbbbbbb" + total_ded);
        int net_sal = gross_sal - total_ded;
        System.out.println("wage is''''''''''''''" + net_sal);
        i.setWage(wage);
        i.setEarn(earn);
        i.setIncAmount(incamt);
        i.setGrossSalary(gross_sal);
        i.setNetSalary(net_sal);
        i.setDeptiId(e.getDepartments());
        s.update(i);
        t.commit();
        System.out.println("\n Incentives updated successfully");
    } catch (HibernateException h) {
        System.out.println("Hibernate Exception during update" + h);
        h.printStackTrace();
    } catch (Exception e) {
        System.out.println("Exception during update" + e);
        e.printStackTrace();
    } finally {
        s.close();
    }
}

From source file:com.hrms.manager.IncentivesManager.java

public boolean validateUserIncentives(IncentivesForm p) {
    System.out.println("---------home----??????????------------");

    System.out.println("-------------------ssssssssssss");
    Session s = HibernateUtil.getSessionFactory().openSession();
    Transaction t = s.beginTransaction();
    List l = new ArrayList();
    List l1 = new ArrayList();
    try {//from w w  w  .  ja va 2  s  .co  m
        int empid = p.getEmpId();
        String date = p.getDate();
        Incentives i = new Incentives();
        Date realdate = new Date();
        SimpleDateFormat s1 = new SimpleDateFormat("dd-MM-yy");
        Date d1 = s1.parse(date);
        System.out.println("Swaaaaaaaaaaaaaathiiiiiiiiiii" + d1);
        Calendar cal = Calendar.getInstance();
        cal.setTime(d1);
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;

        System.out.println("Incentives year year isssssssss" + year);
        System.out.println("Incentives month isssssssss" + month);
        Criteria c = s.createCriteria(Incentives.class);
        c.add(Restrictions.eq("employeeProfileByEmpiId.empId", empid))
                .setProjection(Projections.property("date"));
        l = c.list();

        //   .add(Restrictions.eq("year(ddate)",year));
        System.out.println("list in Incentives is';;';';;';'';;'--------" + l);
        for (int i1 = 0; i1 < l.size(); i1++) {
            Date ddd = (Date) l.get(i1);
            System.out.println("Incentives iterator is---------" + ddd);
            cal.setTime(ddd);
            int year8 = cal.get(Calendar.YEAR);
            int month8 = cal.get(Calendar.MONTH) + 1;
            if (year == year8 && month == month8) {
                realdate = ddd;
            }
        }
        System.out.println("real date is..............." + realdate);
        Criteria c1 = s.createCriteria(Incentives.class);
        i = (Incentives) c1.add(Restrictions.eq("date", realdate))
                .add(Restrictions.eq("employeeProfileByEmpiId.empId", empid)).uniqueResult();
        l1 = c1.list();

        if (l1.size() > 0) {
            //session.close();
            return true;
        }
        t.commit();
        s.close();
    } catch (Exception e) {
        //session.getTransaction().rollback();
    } finally {
        if (s != null) {
            // session.close();
        }
    }

    return false;

}