Example usage for org.hibernate Query setDate

List of usage examples for org.hibernate Query setDate

Introduction

In this page you can find the example usage for org.hibernate Query setDate.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setDate(String name, Date val) 

Source Link

Document

Bind the val (time is truncated) of a given Date object to a named query parameter.

Usage

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

License:Open Source License

/** {@inheritDoc} */
@Override/*from w ww. j a  v a  2s . com*/
public void updatePettyCash(PettyCashBean pettyCashBean) throws ServiceException {
    if (pettyCashBean == null) {
        throw new IllegalArgumentException("Petty cash must not be null or empty");
    }

    User user = AuthenticatedUserDetails.getUserPrincipal();
    if (user == null) {
        logger.info("You must login to use this function");
        // 
        throw new IllegalArgumentException("You don't have a permission to use this");
    }

    float currentUpdNo = findUpdateNoById(pettyCashBean.getId());

    // ?\r\n\r\n?????????????
    // \r\n??????????
    if (currentUpdNo > pettyCashBean.getUpdNo()) {
        throw new IllegalArgumentException(
                "?\r\n\r\n?????????????"
                        + "\r\n??????????");
    }

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

    try {
        tx = session.beginTransaction();

        // 
        StringBuilder sql = new StringBuilder();
        sql.append(" UPDATE " + TblConstants.TBL_PETTY_CASH);
        sql.append(" SET SrDate=:srDate, CtgCode=:ctgCode, Naiyo=:naiyo, Kingaku=:kingaku, Shito=:shito, ");
        sql.append(
                " UpdNo=:updNo, TanCode=:tanCode, APInf2=:apInf2, StfCodeU=:stfCodeU, PrdNoU=:prdNoU, RecCkbn=1, TimeU=now()");
        sql.append(" WHERE RecID=:recId ");

        // 
        Query query = pettyCashRepository.getSQLQuery(session, sql.toString());

        query.setDate("srDate", pettyCashBean.getDate());
        query.setString("ctgCode", pettyCashBean.getItem());
        query.setString("naiyo", pettyCashBean.getContent());
        query.setDouble("kingaku", pettyCashBean.getAmount());
        query.setString("shito", pettyCashBean.getRemark());
        query.setFloat("updNo", currentUpdNo + 1);
        query.setString("tanCode", user.getUsrCode());
        query.setString("apInf2", user.getUsrCode());
        query.setString("stfCodeU", user.getUsrCode());

        try {
            query.setString("prdNoU", ProductHelper.getProductInfor().getVersion());
        } catch (IOException ex) {
            logger.warn(ex.getMessage(), ex);
        }

        query.setString("recId", pettyCashBean.getId());
        query.executeUpdate();
        tx.commit();
    } catch (SQLGrammarException | GenericJDBCException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("Hibernate runtime exception occur when update a list of petty cashes", ex);
    } finally {
        tx = null;
        HibernateSessionManager.closeSession(session);
    }
}

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

License:Open Source License

@Override
public int updatePurchasesByOrgCodeAndMonth(JSONPurchase[] listPurchase, String usrCode, String monthly,
        String orgCode) throws ServiceException {
    if (ArrayUtils.isEmpty(listPurchase)) {
        throw new IllegalArgumentException("ListPurchase must not be null or empty");
    }//  w  w  w.j a va 2s .c om

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

    int isUpdated = 0;
    try {
        String version = null;
        try {
            Version productVersion = ProductHelper.getProductInfor();
            if (productVersion != null) {
                version = productVersion.getProjectVersion();
            }
        } catch (IOException ex) {
            logger.warn(ex.getMessage());
        }

        tx = session.beginTransaction();
        Query query = repository.getNamedQuery(session, SqlConstants.SQL_UPDATE_PURCHASE_DATA);

        Set<String> setFlagConfirm = new HashSet<String>();
        for (JSONPurchase jsonPurchase : listPurchase) {
            setFlagConfirm.add(jsonPurchase.getSrsCode() + ":" + jsonPurchase.getCtgCode() + ":"
                    + jsonPurchase.getWakuNum() + ":" + jsonPurchase.getGnrKbn1());

            //
            if (jsonPurchase.getSrDate() != null) {
                String kingaku = StringUtils.isEmpty(jsonPurchase.getKingaku()) ? "0"
                        : jsonPurchase.getKingaku();
                query.setString("kingaku", kingaku);
                query.setString("gnrKbn1", jsonPurchase.getGnrKbn1());
                query.setString("tanCode", usrCode);
                query.setString("APInf2", usrCode);
                query.setString("stfCodeU", usrCode);
                query.setString("prdNoU", version);
                query.setString("strCode", orgCode);
                query.setString("getSudo", monthly);
                query.setDate("srDate", jsonPurchase.getSrDate());
                query.setInteger("updNo", jsonPurchase.getUpdNo());
                query.setString("srsCode", jsonPurchase.getSrsCode());
                query.setString("ctgCode", jsonPurchase.getCtgCode());
                query.setString("wakuNum", jsonPurchase.getWakuNum());

                // Updating the record by using SQL for given changed information
                int numberOfRecordUpdated = query.executeUpdate();
                if (numberOfRecordUpdated == 0) { // Save Error CM.UPD.M03
                    Criterion criterion = Restrictions.and(
                            Restrictions.eq("pk.vendor.srsCode", jsonPurchase.getSrsCode()),
                            Restrictions.eq("delKbn", Constants.STATUS_ACTIVE),
                            Restrictions.eq("pk.organization.strCode", orgCode),
                            Restrictions.eq("pk.category.ctgCode", jsonPurchase.getCtgCode()),
                            Restrictions.eq("pk.wakuNum", jsonPurchase.getWakuNum()),
                            Restrictions.eq("pk.getSudo", monthly),
                            Restrictions.eq("pk.srDate", jsonPurchase.getSrDate()));
                    Criteria criteria = repository.getCriteria(session, Purchase.class);
                    criteria.add(criterion);

                    String strErrorMsg = null;
                    List<Purchase> purchase = repository.findByCriteria(criteria);
                    if (purchase.size() == 0) {
                        strErrorMsg = "Update fail !!!!!";
                        isUpdated = 2;
                    } else {
                        strErrorMsg = "Concurrent database update error record has been changed or deleted by another user. Please try again from menu screen.";
                        isUpdated = 1;
                    }
                    logger.warn(strErrorMsg);
                    break;
                }
            }
        }

        // Update flag Confirm
        if (isUpdated == 0) {
            query = repository.getNamedQuery(session, SqlConstants.SQL_UPDATE_FLAGCONFIRM_DATA);
            Iterator<String> iterator = setFlagConfirm.iterator();
            while (iterator.hasNext()) {
                String string = (String) iterator.next();
                String[] purchase = string.split(":");
                query.setParameter("gnrKbn1", purchase[3]);
                query.setParameter("srsCode", purchase[0]);
                query.setParameter("ctgCode", purchase[1]);
                query.setParameter("wakuNum", purchase[2]);
                query.setString("strCode", orgCode);
                query.setString("getSudo", monthly);

                int numberOfRecordUpdated = query.executeUpdate();
                if (numberOfRecordUpdated == 0) {
                    isUpdated = 1;
                    break;
                }
            }
        }

        if (isUpdated == 0) {
            tx.commit();
        } else {
            tx.rollback();
        }
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("Hibernate runtime exception when check data available", ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return isUpdated;
}

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

License:Open Source License

/** {@inheritDoc} */
@Override//from   w w w .ja  v  a  2s.c o m
public double findStampedLackingByOrgCodeAndBusinessDay(String orgCode, Date businessDay)
        throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException("Organization's code must not be null or empty");
    }

    if (businessDay == null) {
        throw new IllegalArgumentException("Business day must not be null or empty");
    }

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

    double isStamped = 0;
    try {
        tx = session.beginTransaction();
        String hql = "SELECT at021.Ninzu FROM at021 WHERE at021.StrCode = :StrCode "
                + " AND at021.SrDate = (SELECT at051.EigDateY FROM at051 WHERE at051.EigDate = :EigDate)"
                + " AND at021.DelKbn = 2 ";
        Query query = repository.getSQLQuery(session, hql);
        query.setString("StrCode", orgCode);
        query.setDate("EigDate", businessDay);

        Object result = query.uniqueResult();
        if (result != null) {
            isStamped = Double.parseDouble(result.toString());
        }
        tx.commit();
    } catch (SQLGrammarException | GenericJDBCException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An error occurred when getting all the number of stamped lacking "
                + "for the organization's code " + orgCode + " of day " + businessDay, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return isStamped;
}

From source file:com.netsteadfast.greenstep.base.dao.BaseDAO.java

License:Apache License

/**
 * for public QueryResult getList... doInHibernate
 * @param query       JPA-Style : from TB_ACCOUNT where account = ?0 
 * @param position   JPA-Style : "0", "1" .....
 * @param params/* w  w w  .  ja  v a  2s  .c o m*/
 */
@SuppressWarnings("rawtypes")
private void setQueryParams(Query query, String position, Object params) {
    if (params instanceof java.lang.String) {
        query.setString(position, (java.lang.String) params);
        return;
    }
    if (params instanceof java.lang.Character) {
        query.setCharacter(position, (java.lang.Character) params);
        return;
    }
    if (params instanceof java.lang.Double) {
        query.setDouble(position, (java.lang.Double) params);
        return;
    }
    if (params instanceof java.lang.Byte) {
        query.setByte(position, (java.lang.Byte) params);
        return;
    }
    if (params instanceof java.lang.Integer) {
        query.setInteger(position, (java.lang.Integer) params);
        return;
    }
    if (params instanceof java.lang.Long) {
        query.setLong(position, (java.lang.Long) params);
        return;
    }
    if (params instanceof java.lang.Boolean) {
        query.setBoolean(position, (java.lang.Boolean) params);
        return;
    }
    if (params instanceof java.math.BigDecimal) {
        query.setBigDecimal(position, (java.math.BigDecimal) params);
        return;
    }
    if (params instanceof java.util.Date) {
        query.setDate(position, (java.util.Date) params);
        return;
    }
    if (params instanceof java.util.List) {
        List listParams = (List) params;
        this.setQueryParamsOfList(query, position, listParams);
        return;
    }
}

From source file:com.ocare.obook.dao.impl.ReservationDaoImpl.java

@Override
public Reservation getLastReservation(final Date day) {
    return getHibernateTemplate().execute(new HibernateCallback<Reservation>() {
        @Override/*from   www  .  j a v a  2  s  . c  o  m*/
        public Reservation doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery(
                    "select r from Reservation r where r.reservationDate = :day order by attendenceTime desc");
            query.setDate("day", day);
            query.setMaxResults(1);
            return (Reservation) query.uniqueResult();
        }
    });
}

From source file:com.ocare.obook.dao.impl.ReservationDaoImpl.java

@Override
public List<Reservation> getReservationsForShift(final Date day, final Integer shift) {
    return getHibernateTemplate().execute(new HibernateCallback<List<Reservation>>() {
        @Override/*  ww  w  .j av  a 2s  .c o  m*/
        public List<Reservation> doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery(
                    "select r from Reservation r inner join r.workingTime wt where r.reservationDate = :day and wt.id= :shift and r.status= :status order by attendenceTimeTo asc");
            query.setDate("day", day);
            query.setString("status", "WAITING");
            query.setInteger("shift", shift);
            return (List<Reservation>) query.list();
        }
    });
}

From source file:com.ocare.obook.dao.impl.ReservationDaoImpl.java

@Override
public List<Reservation> getReservationsForPatientByDates(final Integer patientId, final Date fromDate,
        final Date toDate) {
    return getHibernateTemplate().execute(new HibernateCallback<List<Reservation>>() {
        @Override//from   w w  w  . ja v a 2 s  .c o  m
        public List<Reservation> doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery(
                    "select r from Reservation r inner join r.patient p where p.id=:patientId and r.reservationDate BETWEEN :fromDate AND :toDate order by r.reservationDate desc");
            query.setInteger("patientId", patientId);
            query.setDate("fromDate", fromDate);
            query.setDate("toDate", toDate);
            return (List<Reservation>) query.list();
        }
    });
}

From source file:com.ocare.obook.dao.impl.ReservationDaoImpl.java

@Override
public List<ReportReservationStatus> getReservationStatusByDates(final Integer patientId, final Date fromDate,
        final Date toDate) {
    return getHibernateTemplate().execute(new HibernateCallback<List<ReportReservationStatus>>() {
        @Override//ww w.  ja va 2 s .c  o  m
        public List<ReportReservationStatus> doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery(
                    "select r.status as statusName , count(r.status) as occuranceNumber from Reservation r inner join r.patient p where p.id=:patientId and r.reservationDate BETWEEN :fromDate AND :toDate group by r.status");
            query.setInteger("patientId", patientId);
            query.setDate("fromDate", fromDate);
            query.setDate("toDate", toDate);
            List<ReportReservationStatus> reportReservationStatuses = query
                    .setResultTransformer(Transformers.aliasToBean(ReportReservationStatus.class)).list();
            // return result List
            return reportReservationStatuses;
        }
    });
}

From source file:com.ocare.obook.dao.impl.ReservationDaoImpl.java

@Override
public List<StatisticReportModule> getTodayReservationReport(final Date today) {
    return getHibernateTemplate().execute(new HibernateCallback<List<StatisticReportModule>>() {
        @Override/*from  www.j a va  2s . co  m*/
        public List<StatisticReportModule> doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery(
                    "select ex.nameEn as moduleName ,count(ex.nameEn) as occuranceNumber , sum(r.paid) as moduleSum from Reservation r inner join r.examineType ex where r.status =:status and r.reservationDate = :today group by ex.nameEn");
            query.setString("status", "CONFIRMED");
            query.setDate("today", today);
            List<StatisticReportModule> reportReservationStatuses = query
                    .setResultTransformer(Transformers.aliasToBean(StatisticReportModule.class)).list();
            // return result List
            return reportReservationStatuses;
        }
    });
}

From source file:com.ocare.obook.dao.impl.ReservationDaoImpl.java

@Override
public List<StatisticReportModule> getTodayInsurranceReport(final Date today) {
    return getHibernateTemplate().execute(new HibernateCallback<List<StatisticReportModule>>() {
        @Override/*from   www  .ja va 2 s  .  c  om*/
        public List<StatisticReportModule> doInHibernate(Session sn) throws HibernateException {
            Query query = sn.createQuery(
                    "select i.nameEn as moduleName ,count(i.nameEn) as occuranceNumber , sum(r.paid) as moduleSum from Reservation r inner join r.patient p inner join p.insuranceCompany i where r.status =:status and r.reservationDate = :today group by i.nameEn");
            query.setString("status", "CONFIRMED");
            query.setDate("today", today);
            List<StatisticReportModule> reportReservationStatuses = query
                    .setResultTransformer(Transformers.aliasToBean(StatisticReportModule.class)).list();
            // return result List
            return reportReservationStatuses;
        }
    });
}