Example usage for org.hibernate SQLQuery setParameter

List of usage examples for org.hibernate SQLQuery setParameter

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setParameter.

Prototype

@Override
    NativeQuery<T> setParameter(int position, Object val);

Source Link

Usage

From source file:com.sysware.customize.hd.investment.engineeringProject.executiveManagement.EngineeringProjectExecutiveManagementDaoImp.java

/**
 * ajax,?,,?/*  w ww  .j a va 2 s .  co  m*/
 * @param vo
 * @return
 */
@Transactional
public String saveModel(FixedAssetAcceptanceApplyModelVo vo) {
    String returnString = "no";
    /*try{
       FixedAssetAcceptanceApplyModel model = new FixedAssetAcceptanceApplyModel();
       model.setApplyAcceptanceTime(FormatDate.strToDate(vo.getApplyAcceptanceTime(),"yyyy-MM-dd"));
       //BeanUtils.copyProperties(model,vo);//??,
       PropertyUtils.copyProperties(model,vo);
       fixedAssetAcceptanceApplyDao.save(model);//???,??ID ID
       returnString = "yes";
    }catch(Exception e){
       e.printStackTrace();
    }*/

    String applyAcceptanceTime = StringUtils.isBlank(vo.getApplyAcceptanceTime()) ? ""
            : vo.getApplyAcceptanceTime();
    if (!applyAcceptanceTime.equals("")) {
        //applyAcceptanceTime = "to_date('"+applyAcceptanceTime+"','yyyy-mm-dd')";
    }
    String projectManagerName = StringUtils.isBlank(vo.getProjectManagerName()) ? ""
            : vo.getProjectManagerName();
    String tel = StringUtils.isBlank(vo.getTel()) ? "" : vo.getTel();
    String contractmanuFacturers = StringUtils.isBlank(vo.getContractmanuFacturers()) ? ""
            : vo.getContractmanuFacturers();
    String contractmanuFacturersTel = StringUtils.isBlank(vo.getContractmanuFacturersTel()) ? ""
            : vo.getContractmanuFacturersTel();
    String contactPerson = StringUtils.isBlank(vo.getContactPerson()) ? "" : vo.getContactPerson();
    String opinion = StringUtils.isBlank(vo.getOpinion()) ? "" : vo.getOpinion();
    String status = StringUtils.isBlank(vo.getStatus()) ? "" : vo.getStatus();
    String civilRegistId = StringUtils.isBlank(vo.getCivilregistId()) ? "" : vo.getCivilregistId();

    //?
    String dateString = FormatDate.getNowYMD();
    String sql = "INSERT INTO TB_FIXEDASSETACCEPTANCEAPPLY VALUES (?,?,to_date(?,'yyyy-mm-dd'),?,?,?,?,?,?,?) \n";
    SQLQuery query = engineeringProjectExecutiveManagementDaoImp.getHibernateSession().createSQLQuery(sql);
    query.setParameter(0, UtilForHD.GetNowTimeForId());
    query.setParameter(1, civilRegistId);
    query.setParameter(2, applyAcceptanceTime);
    query.setParameter(3, projectManagerName);
    query.setParameter(4, tel);
    query.setParameter(5, contractmanuFacturers);
    query.setParameter(6, contractmanuFacturersTel);
    query.setParameter(7, contactPerson);
    query.setParameter(8, opinion);
    query.setParameter(9, status);
    query.executeUpdate();
    returnString = "yes";
    return returnString;
}

From source file:com.sysware.customize.hd.investment.engineeringProject.executiveManagement.EngineeringProjectExecutiveManagementDaoImp.java

/**
 * ?/*from   ww w .j a  v  a2 s .c om*/
 * @param id
 * @param flag
 */
public void updateApprovalState(String id, String flag) {
    try {
        /*String hql = "update CivilRepair t " +
              "set t.approvalstate = '"+flag+"' " +
              "where t.id = '"+id+"'";
        this.getHibernateSession().createQuery(hql).executeUpdate();*/
        String sql = "UPDATE TB_ENGINEERINGEXEMANADETAILS a \n" + "SET a.status = ? \n" + "WHERE a.id = ? \n";
        SQLQuery query = this.getHibernateSession().createSQLQuery(sql);
        query.setParameter(0, flag);
        query.setParameter(1, id);
        query.executeUpdate();
        log.info("TB_ENGINEERINGEXEMANADETAILS ?2()---?!");
    } catch (Exception e) {
        log.info("TB_ENGINEERINGEXEMANADETAILS ?2()---!");
        e.printStackTrace();
    }
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

public Long latestModificationRunByPipeline(final CaseInsensitiveString pipelineName, final Material material) {
    final long materialId = findMaterialInstance(material).getId();
    String key = cacheKeyForLatestPmrForPipelineKey(materialId, pipelineName.toLower());
    Long modificationId = (Long) goCache.get(key);
    if (modificationId == null) {
        synchronized (key) {
            modificationId = (Long) goCache.get(key);
            if (modificationId == null) {
                modificationId = (Long) getHibernateTemplate().execute((HibernateCallback) session -> {
                    SQLQuery sqlQuery = session.createSQLQuery("SELECT  MAX(pmr.toRevisionId) toRevisionId "
                            + "FROM (SELECT torevisionid, pipelineid FROM pipelineMaterialRevisions WHERE materialid = :material_id)  AS pmr\n"
                            + "INNER JOIN pipelines p ON ( p.name = :pipeline_name AND p.id = pmr.pipelineId)");

                    sqlQuery.setParameter("material_id", materialId);
                    sqlQuery.setParameter("pipeline_name", pipelineName.toString());
                    sqlQuery.addScalar("toRevisionId", new LongType());
                    return sqlQuery.uniqueResult();
                });/*from   w  w w. j a  v  a 2s .co m*/
                if (modificationId == null) {
                    modificationId = -1L;
                }
                goCache.put(key, modificationId);
            }
        }
    }
    return modificationId;
}

From source file:com.tim10.glavna_knjiga.dbutils.NaloziUtils.java

public boolean provjeriKontoUKontnomPlanu(int idKonta) {

    int idPreduzeca = UserData.getPreduzece().getIdPreduzece();
    SQLQuery query;

    query = session.createSQLQuery("select kpko.KontniOkvir_id from KontniPlan_has_KontniOkvir kpko "
            + "inner join KontniPlan kp on kpko.KontniPlan_IdKontniPlan = kp.idKOntniPlan "
            + "where kpko.KontniOkvir_id = :idKonta and kp.Preduzece_IdPreduzece = :idPreduzeca");
    query.setParameter("idKonta", idKonta);
    query.setParameter("idPreduzeca", idPreduzeca);

    List<KontniOkvir> result = new ArrayList<KontniOkvir>();

    result = query.list();/*from w ww . ja  v a  2  s  . com*/

    if (result.size() > 0)
        return true;
    else
        return false;
}

From source file:com.ulcs.dao.CustomerDAO.java

public Customer getCustomer(int customerID) {
    try {/*  ww w .j a  va 2  s  . c o  m*/
        //            Connection con=Teledbc.connector();
        String qry = "Select * from customer where customerID=:CsID";
        AnnotationConfiguration config = new AnnotationConfiguration();
        config.addAnnotatedClass(Customer.class);
        config.configure("hibernate.cfg.xml");
        SessionFactory factory = config.buildSessionFactory();
        Session session = factory.getCurrentSession();
        session.beginTransaction();
        SQLQuery query = session.createSQLQuery(qry);
        query.addEntity(Customer.class);
        query.setParameter("CsID", customerID);
        List queryList = query.list();
        session.getTransaction().commit();
        if (queryList != null && queryList.isEmpty()) {
            return null;
        } else {
            return (Customer) queryList.get(0);
        }

        //            PreparedStatement pst= con.prepareStatement(qry);
        //            pst.setInt(1, customerID);
        //            ResultSet rs=pst.executeQuery();
        //            
        //            while(rs.next()){
        //                Customer m=new Customer();
        //                m.setCustomerName(rs.getString("customerName"));
        //                m.setCustomerNumber(rs.getString("customerNumber"));
        //                m.setCustomerAddress(rs.getString("customerAddress"));
        //                m.setCustomerID(rs.getInt("CsID"));
        //                return m;
        //            }
        //            con.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.ulcs.dao.CustomerDAO.java

public void deleteCustomer(int customerID) {
    try {//from  w  ww . ja va 2 s.  c  om
        String qry = "delete from customer where customerID=:CsID";
        AnnotationConfiguration config = new AnnotationConfiguration();
        config.addAnnotatedClass(Customer.class);
        config.configure("hibernate.cfg.xml");
        SessionFactory factory = config.buildSessionFactory();
        Session session = factory.getCurrentSession();
        session.beginTransaction();
        SQLQuery query = session.createSQLQuery(qry);
        query.addEntity(Customer.class);
        query.setParameter("CsID", customerID);
        query.executeUpdate();
        session.getTransaction().commit();
        //            Connection con=Teledbc.connector();
        //            String qry="delete from customer where CsID=?";
        //            PreparedStatement pst=con.prepareStatement(qry);
        //            pst.setInt(1,customerID);
        //            pst.executeUpdate();
        //            con.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.ulcs.dao.CustomerDAO.java

public void updateCustomer(Customer customer) {
    try {//from  w  w  w .j  ava 2s . c  o m
        String qry = "update customer set customerName=:customerName ,customerAddress=:customerAddress,customerNumber=:customerNumber where customerID=:CsID";
        AnnotationConfiguration config = new AnnotationConfiguration();
        config.addAnnotatedClass(Customer.class);
        config.configure("hibernate.cfg.xml");
        SessionFactory factory = config.buildSessionFactory();
        Session session = factory.getCurrentSession();
        session.beginTransaction();
        SQLQuery query = session.createSQLQuery(qry);
        query.addEntity(Customer.class);
        query.setParameter("CsID", customer.getCustomerID());
        query.setParameter("customerName", customer.getCustomerName());
        query.setParameter("customerAddress", customer.getCustomerAddress());
        query.setParameter("customerNumber", customer.getCustomerNumber());
        query.executeUpdate();
        session.getTransaction().commit();
        //            Connection con=Teledbc.connector();
        //            String qry="update customer set customerName=? ,customerAddress=?,customerNumber=? where CsID=?";
        //            PreparedStatement pst=con.prepareStatement(qry);
        //            pst.setString(1,customer.getCustomerName());
        //            pst.setString(2,customer.getCustomerAddress());
        //            pst.setString(3,customer.getCustomerNumber());
        //            pst.setInt(4,customer.getCustomerID());
        //            pst.executeUpdate();
        //            con.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.ulcs.dao.UserDAO.java

public User ValidUser(User user) {
    try {//from w w w . j ava  2s.com

        String qry = "Select * from user where userName =:userName and userPassword =:userPassword";
        AnnotationConfiguration config = new AnnotationConfiguration();
        config.addAnnotatedClass(User.class);
        config.configure("hibernate.cfg.xml");
        SessionFactory factory = config.buildSessionFactory();
        Session session = factory.getCurrentSession();

        session.beginTransaction();
        SQLQuery query = session.createSQLQuery(qry);
        query.addEntity(User.class);
        query.setParameter("userName", user.getUserName());
        query.setParameter("userPassword", user.getUserPassword());
        List rs = query.list();
        session.getTransaction().commit();
        if (rs != null) {
            return user;
            //    return (User) rs;

        } else
            return null;

    } catch (Exception e) {
        e.printStackTrace();

    }
    return null;
}

From source file:com.userweave.domain.service.impl.StudyServiceImpl.java

License:Open Source License

@Override
public void generateStudyResults(Integer studyId) {
    Session session = getCurrentSession();

    // create queries
    String freetextQuery = insertFreeTextAnswer();
    String freenumberQuery = insertFreeNumberAnswer();
    String multipleanswerQuery = insertMultipleAnswer();
    String dimensionQuery = insertSingleDimension();
    String singleanswerQuery = insertSingleAnswer();
    String ratingQuery = insertSingleRating();

    // create query objects.
    SQLQuery freetext = session.createSQLQuery(freetextQuery);
    SQLQuery freenumber = session.createSQLQuery(freenumberQuery);
    SQLQuery multipleanswer = session.createSQLQuery(multipleanswerQuery);
    SQLQuery dimension = session.createSQLQuery(dimensionQuery);
    SQLQuery singleanswer = session.createSQLQuery(singleanswerQuery);
    SQLQuery rating = session.createSQLQuery(ratingQuery);

    // set study id
    freetext.setParameter("studyId", studyId);
    freenumber.setParameter("studyId", studyId);
    multipleanswer.setParameter("studyId", studyId);
    dimension.setParameter("studyId", studyId);
    singleanswer.setParameter("studyId", studyId);
    rating.setParameter("studyId", studyId);

    freetext.executeUpdate();/* w  w  w .j a v  a2  s .  co m*/
    freenumber.executeUpdate();
    multipleanswer.executeUpdate();
    dimension.executeUpdate();
    singleanswer.executeUpdate();
    rating.executeUpdate();
}

From source file:com.vertec.daoimpl.AttendanceDAOImpl.java

public String ApproveLeave(Leaves em) {
    Session session = NewHibernateUtil.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();
    if (session != null) {
        try {/*from  ww w .  j a  va2 s  .  c om*/
            SQLQuery query = session.createSQLQuery(
                    "Update Leaves set remark=:remark,is_pay=:isPay,is_approved=:isApproved where id=:id");
            query.setParameter("remark", em.getRemark());
            query.setParameter("isPay", em.getIsPay());
            query.setParameter("isApproved", em.getIsApproved());
            query.setParameter("id", em.getId());
            query.executeUpdate();
            transaction.commit();
            return VertecConstants.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return VertecConstants.ERROR;
        } finally {
            if (session != null && session.isOpen()) {
                session.close();
            }
        }
    }
    return null;
}