List of usage examples for javax.persistence Query executeUpdate
int executeUpdate();
From source file:com.lhfs.fsn.dao.testReport.impl.TestReportDaoImpl.java
/** * ????/*www . ja va 2s .c o m*/ * @author ZhangHui 2015/6/7 * @throws DaoException */ @Override public void updateRecordOfSample(Long id, Long sample_id) throws DaoException { try { if (id == null || sample_id == null) { throw new Exception("?"); } String sql = "UPDATE test_result SET sample_id = ?1 WHERE id = ?2"; Query query = entityManager.createNativeQuery(sql); query.setParameter(1, sample_id); query.setParameter(2, id); query.executeUpdate(); } catch (Exception e) { throw new DaoException("TestReportDaoImpl.updateRecordOfSample()-->" + e.getMessage(), e); } }
From source file:com.lhfs.fsn.dao.testReport.impl.TestReportDaoImpl.java
/** * ?????///from ww w . j a va 2 s.c o m * @author ZhangHui 2015/6/7 * @throws DaoException */ @Override public void updateRecordOfTestee(Long id, Long testee_id) throws DaoException { try { if (id == null || testee_id == null) { throw new Exception("?"); } String sql = "UPDATE test_result SET testee_id = ?1 WHERE id = ?2"; Query query = entityManager.createNativeQuery(sql); query.setParameter(1, testee_id); query.setParameter(2, id); query.executeUpdate(); } catch (Exception e) { throw new DaoException("TestReportDaoImpl.updateRecordOfTestee()-->" + e.getMessage(), e); } }
From source file:com.gettec.fsnip.fsn.dao.business.impl.BusinessUnitDAOImpl.java
@Override public void updateBusinessUnit(String strImg, Long id, String url) { try {/*from w ww . j a v a 2s . c o m*/ String sql = "UPDATE business_unit SET " + strImg + "=?1"; sql += " WHERE id = ?2 "; Query query = entityManager.createNativeQuery(sql); query.setParameter(1, url); query.setParameter(2, id); query.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.lhfs.fsn.dao.testReport.impl.TestReportDaoImpl.java
/** * ???id,/??//from w ww . j a v a 2 s . c o m * @param del * 0 ?? * 1 * @author ZhangHui 2015/6/17 * @throws DaoException */ @Override public void updateByDel(Long test_result_id, int del) throws DaoException { try { if (test_result_id == null) { throw new Exception("?"); } String sql = "UPDATE test_result SET del = ?1 WHERE id = ?2"; Query query = entityManager.createNativeQuery(sql); query.setParameter(1, del); query.setParameter(2, test_result_id); query.executeUpdate(); } catch (Exception e) { e.printStackTrace(); throw new DaoException("TestReportDaoImpl.updateByDel()-->" + e.getMessage(), e); } }
From source file:org.rhq.enterprise.server.alert.AlertManagerBean.java
/** * Remove alerts for the specified range of time. *//*w ww.j av a2s.c o m*/ // gonna use bulk delete, make sure we are in new tx to not screw up caller's hibernate session @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) @TransactionTimeout(6 * 60 * 60) public int deleteAlerts(long beginTime, long endTime) { long totalTime = 0; long start = System.currentTimeMillis(); Query query = entityManager.createNamedQuery(AlertConditionLog.QUERY_DELETE_BY_ALERT_CTIME); query.setParameter("begin", beginTime); query.setParameter("end", endTime); int conditionsDeleted = query.executeUpdate(); long end = System.currentTimeMillis(); log.debug("Deleted [" + conditionsDeleted + "] alert condition logs in [" + (end - start) + "]ms"); totalTime += (end - start); start = System.currentTimeMillis(); query = entityManager.createNamedQuery(AlertNotificationLog.QUERY_DELETE_BY_ALERT_CTIME); query.setParameter("begin", beginTime); query.setParameter("end", endTime); int deletedNotifications = query.executeUpdate(); end = System.currentTimeMillis(); log.debug("Deleted [" + deletedNotifications + "] alert notifications in [" + (end - start) + "]ms"); totalTime += (end - start); start = System.currentTimeMillis(); query = entityManager.createNamedQuery(Alert.QUERY_DELETE_BY_CTIME); query.setParameter("begin", beginTime); query.setParameter("end", endTime); int deletedAlerts = query.executeUpdate(); end = System.currentTimeMillis(); log.debug("Deleted [" + deletedAlerts + "] alerts in [" + (end - start) + "]ms"); totalTime += (end - start); MeasurementMonitor.getMBean().incrementPurgeTime(totalTime); MeasurementMonitor.getMBean().setPurgedAlerts(deletedAlerts); MeasurementMonitor.getMBean().setPurgedAlertConditions(conditionsDeleted); MeasurementMonitor.getMBean().setPurgedAlertNotifications(deletedNotifications); log.debug("Deleted [" + (deletedAlerts + conditionsDeleted + deletedNotifications) + "] " + "alert audit records in [" + (totalTime) + "]ms"); return deletedAlerts; }
From source file:com.gettec.fsnip.fsn.dao.business.impl.BusinessUnitDAOImpl.java
@Override public boolean updateSignStatus(String busName, boolean signFlag, boolean passFlag) throws DaoException { try {/*from www . ja v a 2s . c o m*/ String sql = "UPDATE business_unit SET sign_flag = ?1, pass_flag = ?2 WHERE name = ?3"; Query query = entityManager.createNativeQuery(sql); query.setParameter(1, signFlag); query.setParameter(2, passFlag); query.setParameter(3, busName); query.executeUpdate(); return true; } catch (Exception e) { e.printStackTrace(); throw new DaoException("BusinessUnitDAOimpl.updateRecord()-->" + e.getMessage(), e); } }
From source file:com.gettec.fsnip.fsn.dao.member.impl.MemberDAOImpl.java
@Override public boolean deleteMemberById(Long id) throws DaoException { try {/* www. java 2 s. c o m*/ String sql = " DELETE FROM member WHERE id=?1 "; Query query = entityManager.createNativeQuery(sql); query.setParameter(1, id); int success = query.executeUpdate(); if (success > 0) { return true; } else { return false; } } catch (Exception e) { throw new DaoException("MemberDAOImpl.deleteMemberById() ?", e); } }
From source file:com.gettec.fsnip.fsn.dao.member.impl.MemberDAOImpl.java
@Override public boolean deleteBarcodeToQRcode(Long id) throws DaoException { try {//from w w w . j a va 2 s. com String sql = " DELETE FROM member_barcode_to_qrcode WHERE id=?1 "; Query query = entityManager.createNativeQuery(sql); query.setParameter(1, id); int success = query.executeUpdate(); if (success > 0) { return true; } else { return false; } } catch (Exception e) { throw new DaoException("MemberDAOImpl.getBarcodeToQRcode() ?", e); } }
From source file:com.gettec.fsnip.fsn.dao.business.impl.BusinessUnitDAOImpl.java
/** * ?/*w w w. j ava 2 s. co m*/ * ????? * @author ZhangHui 2015/6/5 * @throws DaoException */ @Override public void createNewRecord(String bus_name, String bus_address, String licenseno) throws DaoException { try { if (bus_name != null) { bus_name = bus_name.replace(" ", ""); } if (bus_name == null || "".equals(bus_name)) { throw new Exception("?"); } String sql = "INSERT INTO business_unit(name,address,license_no) VALUES(?1,?2,?3)"; Query query = entityManager.createNativeQuery(sql); query.setParameter(1, bus_name); query.setParameter(2, bus_address); query.setParameter(3, licenseno); query.executeUpdate(); } catch (Exception e) { e.printStackTrace(); throw new DaoException("BusinessUnitDAOimpl.createNewRecord()-->" + e.getMessage(), e); } }
From source file:org.rhq.enterprise.server.measurement.MeasurementScheduleManagerBean.java
public int enableSchedulesForContext(Subject subject, EntityContext context, int[] measurementDefinitionIds) { String measurementScheduleSubQuery = getMeasurementScheduleSubQueryForContext(subject, context, measurementDefinitionIds);/*w w w. j av a 2 s .c o m*/ String updateQuery = "" // + "UPDATE MeasurementSchedule " // + " SET enabled = true " // + " WHERE id IN ( " + measurementScheduleSubQuery + " ) "; Query query = entityManager.createQuery(updateQuery); int affectedRows = query.executeUpdate(); scheduleJobToPushScheduleUpdatesToAgents(context, measurementScheduleSubQuery); return affectedRows; }