Example usage for org.hibernate SQLQuery setInteger

List of usage examples for org.hibernate SQLQuery setInteger

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setInteger(int position, int val) 

Source Link

Document

Bind a positional int-valued parameter.

Usage

From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclApplyDefaultDetailsDAO.java

public List getLclDefaultNameList(Integer userId) throws Exception {
    List<LabelValueBean> applyDefaultList = new ArrayList<LabelValueBean>();
    SQLQuery query = getCurrentSession().createSQLQuery(
            "select id, upper(apply_default_name) from lcl_apply_default_details where user_id =:userId");
    query.setInteger("userId", userId);
    List<Object[]> resultList = query.list();
    for (Object[] row : resultList) {
        Integer cid = (Integer) row[0];
        String cname = (String) row[1];
        if (null != row[1] && null != row[0]) {
            applyDefaultList.add(new LabelValueBean(cname, cid.toString()));
        }//  ww  w.jav  a 2  s .c  o m
    }
    return applyDefaultList;
}

From source file:com.liusoft.dlog4j.dao.DlogDAO.java

License:Open Source License

/**
 * ?,(site=-1)//from w  w  w .j  a va2s  .  co  m
 * @param site
 * @param count
 * @return
 */
public static List listHotTags(int site, int count) {
    Session ssn = getSession();
    StringBuffer sql = new StringBuffer("SELECT tag_name,COUNT(*) FROM dlog_tag");
    if (site > 0)
        sql.append(" WHERE site_id=?");
    sql.append(" GROUP BY tag_name ORDER BY 2 DESC");
    SQLQuery query = ssn.createSQLQuery(sql.toString());
    if (site > 0)
        query.setInteger(0, site);
    query.setMaxResults(count);
    List tags = new ArrayList();
    List results = query.list();
    for (int i = 0; results != null && i < results.size(); i++) {
        tags.add(((Object[]) results.get(i))[0]);
    }
    return tags;
}

From source file:com.lp.server.system.automatikjob.AutomatikjobPaternoster.java

License:Open Source License

private void speicherePaternostermenge(org.hibernate.Session session, Integer paternosterIId, String cNr,
        BigDecimal menge, Timestamp ts) {
    String sql = "UPDATE WW_ARTIKELLAGERPLAETZE SET N_LAGERSTANDPATERNOSTER = ?, T_AENDERN = ? "
            + "WHERE I_ID = (SELECT I_ID FROM WW_ARTIKELLAGERPLAETZE "
            + "WHERE LAGERPLATZ_I_ID = (SELECT I_ID FROM WW_LAGERPLATZ "
            + "WHERE PATERNOSTER_I_ID = ? AND ARTIKEL_I_ID = "
            + "(SELECT I_ID FROM WW_ARTIKEL WHERE C_NR = ?)))";

    org.hibernate.SQLQuery sq = session.createSQLQuery(sql);
    sq.setBigDecimal(0, menge);/*from   w  ww.  j  av a 2 s . c om*/
    sq.setTimestamp(1, ts);
    sq.setInteger(2, paternosterIId);
    sq.setString(3, cNr);
    int anzahl = sq.executeUpdate();
    if (anzahl == 0) {
        if (menge.doubleValue() > 0) {
            myLogger.info("Artikel " + cNr + " ist im Paternoster ohne Paternosterlagerplatz mit Menge "
                    + menge.doubleValue());
        }
    }
}

From source file:com.neu.web.phmis.dao.AdminDao.java

public EnterpriseBean addEnterpriseBean(EnterpriseBean enterpriseBean) {

    try {/*w  ww.  j a v  a 2s. c om*/

        session = HibernateUtil.getSessionFactory().openSession();

        session.beginTransaction();
        SQLQuery query = session.createSQLQuery(
                "CALL addEnterprise (:number, :name, :typeId, :countyId, :street, :suite, :city, :state, :zip, :contact, :url)");
        query.setString("number", enterpriseBean.getNumber());
        query.setString("name", enterpriseBean.getName());
        query.setInteger("typeId", enterpriseBean.getTypeId());
        query.setInteger("countyId", enterpriseBean.getCountyId());
        query.setString("street", enterpriseBean.getStreet());
        query.setString("suite", enterpriseBean.getSuite());
        query.setString("city", enterpriseBean.getCity());
        query.setString("state", enterpriseBean.getState());
        query.setString("zip", enterpriseBean.getZipCode());
        query.setString("contact", enterpriseBean.getContact());
        query.setString("url", enterpriseBean.getUrl());

        List<Integer> list = query.list();
        enterpriseBean.setId(list.get(0));
        session.getTransaction().commit();

    } catch (HibernateException e) {
        session.getTransaction().rollback();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
        return enterpriseBean;
    }

}

From source file:com.neu.web.phmis.dao.AdminDao.java

public void editEnterprise(EnterpriseBean enterpriseBean) {

    try {/*from   ww  w  .  j a va2 s  .  co  m*/

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        SQLQuery query = session.createSQLQuery("SELECT creationDate FROM enterprise where id = :id");
        query.setInteger("id", enterpriseBean.getId());
        List list = query.list();
        enterpriseBean.setCreationDate((Date) list.get(0));

        session.update(enterpriseBean);
        session.getTransaction().commit();

    } catch (HibernateException e) {
        session.getTransaction().rollback();
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
    }

}

From source file:com.neu.web.phmis.dao.AdminDao.java

public UserBean addUser(UserBean userBean) {

    try {//from w ww .  j  ava 2s . c om

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        SQLQuery query = session.createSQLQuery(
                "CALL addUser (:number, :userName, :emailId, :roleId, :enterpriseId, :firstName, :lastName)");
        query.setString("number", userBean.getNumber());
        query.setString("userName", userBean.getUsername());
        query.setString("emailId", userBean.getEmailId());
        query.setInteger("roleId", userBean.getRoleBean().getId());
        query.setInteger("enterpriseId", userBean.getEnterpriseBean().getId());
        query.setString("firstName", userBean.getFirstName());
        query.setString("lastName", userBean.getLastName());
        List<Object[]> list = query.list();
        Object[] data = list.get(0);
        userBean.setId(Integer.parseInt(data[0].toString()));
        userBean.setPassword(data[1].toString());
        session.getTransaction().commit();

    } catch (HibernateException e) {
        session.getTransaction().rollback();
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
        return userBean;
    }

}

From source file:com.neu.web.phmis.dao.CommonDao.java

public UserBean activateAccount(UserBean userBean, String key) {

    try {/*from  w ww  .j  a  v  a  2s  . co m*/

        session = HibernateUtil.getSessionFactory().openSession();

        session.beginTransaction();
        SQLQuery query = session.createSQLQuery("CALL activateAccount (:id, :password, :key, :ipAddr)");
        query.setInteger("id", userBean.getId());
        query.setString("password", userBean.getPassword());
        query.setString("key", key);
        query.setString("ipAddr", userBean.getLastAccessedFrom());

        List<UserBean> list = query.addEntity(UserBean.class).list();
        if (!list.isEmpty()) {
            userBean = list.get(0);
            Hibernate.initialize(userBean.getEnterpriseBean());
            Hibernate.initialize(userBean.getRoleBean());
        }

        session.getTransaction().commit();

    } catch (HibernateException e) {
        session.getTransaction().rollback();
        userBean = null;
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
        return userBean;
    }

}

From source file:com.neu.web.phmis.dao.DoctorDao.java

public void createRequest(SurgeryRequestBean surgeryRequestBean) {

    try {//from  w w w.j  a  va  2 s  .  c  om

        surgeryBean = surgeryRequestBean.getSurgeryBean();
        List<ProductBean> requestedProducts = surgeryRequestBean.getRequestedProducts();

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        SQLQuery query = session.createSQLQuery(
                "CALL createSurgeryRequest(:userId, :surgeryType, :patientName, :requestNo, :requestTypeId, :requestStatusId, :dateFrom, :dateTo, :instru, :staff)");
        query.setInteger("userId", surgeryBean.getDoctor().getId());
        query.setString("surgeryType", surgeryBean.getType());
        query.setString("patientName", surgeryBean.getPatientName());
        query.setString("requestNo", surgeryRequestBean.getNumber());
        query.setInteger("requestTypeId", surgeryRequestBean.getTypeId());
        query.setInteger("requestStatusId", surgeryRequestBean.getStatusId());
        query.setDate("dateFrom", surgeryRequestBean.getDateFrom());
        query.setDate("dateTo", surgeryRequestBean.getDateTo());
        query.setString("instru", surgeryRequestBean.getSpecialInstructions());
        query.setInteger("staff", surgeryRequestBean.getStaffCount());

        List<Integer> list = query.list();
        surgeryRequestBean.setId(list.get(0));

        for (ProductBean p : requestedProducts) {
            query = session.createSQLQuery("INSERT INTO productrequested VALUES (:requestId, :productId)");
            query.setInteger("requestId", surgeryRequestBean.getId());
            query.setInteger("productId", p.getId());
            query.executeUpdate();
        }

        session.getTransaction().commit();

    } catch (HibernateException e) {
        session.getTransaction().rollback();
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
    }

}

From source file:com.neu.web.phmis.dao.InventoryDao.java

public DeviceRequestBean processRequest(DeviceRequestBean deviceRequestBean) {

    try {/*from   w w  w.  j  ava2 s.c o m*/

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        SQLQuery query = session.createSQLQuery(
                "UPDATE request SET statusId = :status, processedDate = NOW(), processComment = :comment WHERE id = :id");
        query.setInteger("status", deviceRequestBean.getStatusId());
        query.setString("comment", deviceRequestBean.getProcessComment());
        query.setInteger("id", deviceRequestBean.getId());
        query.executeUpdate();
        deviceRequestBean = (DeviceRequestBean) session.get(DeviceRequestBean.class, deviceRequestBean.getId());
        session.getTransaction().commit();

    } catch (HibernateException e) {
        session.getTransaction().rollback();
        deviceRequestBean = null;
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
        return deviceRequestBean;
    }

}

From source file:com.neu.web.phmis.dao.InventoryDao.java

public void addOrder(List<OrderBean> orderList) {

    try {/*from  www .  ja v a  2 s  .co  m*/

        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        for (OrderBean ob : orderList) {
            SQLQuery query = session.createSQLQuery("CALL addOrder(:1,:2,:3)");
            query.setString("1", ob.getNumber());
            query.setInteger("2", ob.getOrderedBy().getId());
            query.setInteger("3", ob.getOrderedFrom().getId());
            List<OrderItemBean> temp = ob.getOrderItemList();
            ob = (OrderBean) query.addEntity(OrderBean.class).uniqueResult();
            ob.setOrderItemList(temp);
            for (OrderItemBean oib : ob.getOrderItemList()) {
                query = session.createSQLQuery(
                        "INSERT INTO orderitem (orderId, productId, quantity) VALUES (:1, :2, :3)");
                query.setInteger("1", ob.getId());
                query.setInteger("2", oib.getProductBean().getId());
                query.setInteger("3", oib.getQuantity());
                query.executeUpdate();
            }
        }

        session.getTransaction().commit();

    } catch (HibernateException e) {
        session.getTransaction().rollback();
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
    }

}