Java Code Examples for org.hibernate.SQLQuery#executeUpdate()
The following examples show how to use
org.hibernate.SQLQuery#executeUpdate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmpDaoImpl.java From ignite-book-code-samples with GNU General Public License v3.0 | 7 votes |
@Override @CacheEvict(value = "exchangeRate", key = "#e.region") public void updateExchange(ExchangeRate e) { Session session = sessionFactory.openSession(); session.getTransaction().begin(); SQLQuery query = session.createSQLQuery("update exchangerate \n" + " set usdollar = :usdollar" + " where region = :region and ratedate = TO_DATE('2015-05-02','YYYY-MM-DD')") ; query.setParameter("region", e.getRegion()); query.setParameter("usdollar", e.getUsdollar()); query.addEntity(ExchangeRate.class); query.executeUpdate(); session.getTransaction().commit(); session.close(); }
Example 2
Source File: UnlimitedMessageColumnsMigration.java From sailfish-core with Apache License 2.0 | 6 votes |
public void migrate() throws Exception { if (nativeDbQueries == NativeDbQueries.NOT_SUPPORTED_DB) { logger.warn("Could not migrate database to set unlimited raw/json/human " + "message columns. Reason: migration supported for mysql and postgres only"); return; } if (nativeDbQueries.isMigrationNeeded(session, databaseName)) { Transaction transaction = session.beginTransaction(); try(AutoCloseable closeable = transaction::commit) { SQLQuery migrateSqlQuery = session.createSQLQuery(nativeDbQueries.getMigrationQuery()); migrateSqlQuery.executeUpdate(); } catch (Exception e) { transaction.rollback(); throw e; } } }
Example 3
Source File: BaseHibernateDao.java From framework with Apache License 2.0 | 6 votes |
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param sql * @param param * @return * @throws DaoException <br> */ @Override public int excuteSql(final String sql, final DataParam param) throws DaoException { try { SQlCheckUtil.checkSql(sql); Session session = getSession(); session.flush(); SQLQuery query = session.createSQLQuery(sql); setParamMap(param.getParamMap(), query); return query.executeUpdate(); } catch (Exception e) { logger.error(e.getMessage(), e); throw new DaoException(ErrorCodeDef.EXECUTE_ERROR_10011, e); } }
Example 4
Source File: BaseHibernateDao.java From framework with Apache License 2.0 | 6 votes |
/** * Description: <br> * * @author 王伟<br> * @taskId <br> * @param sqls * @param param * @return * @throws DaoException <br> */ @Override public int[] batchExcuteSql(final String[] sqls, final DataParam param) throws DaoException { try { Session session = getSession(); session.flush(); int[] result = new int[sqls.length]; SQLQuery query; for (int i = 0; i < sqls.length; i++) { query = session.createSQLQuery(sqls[i]); setParamMap(param.getParamMap(), query); result[i] = query.executeUpdate(); } return result; } catch (Exception e) { logger.error(e.getMessage(), e); throw new DaoException(ErrorCodeDef.BATCH_EXECUTE_ERROR_10012, e); } }
Example 5
Source File: NativeDbOperations.java From sailfish-core with Apache License 2.0 | 5 votes |
public void createTagGroupTempTable(Session session, Collection<Long> tagIds) { String query = DROP_TAG_GROUP_TEMP_TABLE; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.executeUpdate(); query = CREATE_TAG_GROUP_TEMP_TABLE.replace(":tagIds", tagIds.stream() .map(String::valueOf) .collect(Collectors.joining(","))); sqlQuery = session.createSQLQuery(query); sqlQuery.executeUpdate(); }
Example 6
Source File: QuestionDaoImpl.java From DWSurvey with GNU Affero General Public License v3.0 | 5 votes |
/** * 更新orderbyId * 属性 belongId所有题目,只要大于等于orderById+1 * @param belongId * @param orderById */ private void quOrderByIdAdd1(String belongId,Integer orderById){ if(belongId!=null && !"".equals(belongId)){ String sql="update t_question set order_by_id=order_by_id+1 where belong_id=? and order_by_id>=?"; //更新排序号 SQLQuery query=this.getSession().createSQLQuery(sql); query.setString(0, belongId); query.setInteger(1, orderById); query.executeUpdate(); } }
Example 7
Source File: QuestionDaoImpl.java From DWSurvey with GNU Affero General Public License v3.0 | 5 votes |
public void quOrderByIdDel1(String belongId,Integer orderById){ if(belongId!=null && !"".equals(belongId)){ String sql="update t_question set order_by_id=order_by_id-1 where belong_id=? and order_by_id>=?"; //更新排序号 SQLQuery query=this.getSession().createSQLQuery(sql); query.setString(0, belongId); query.setInteger(1, orderById); query.executeUpdate(); } }
Example 8
Source File: QuRadioDaoImpl.java From DWSurvey with GNU Affero General Public License v3.0 | 5 votes |
public void quOrderByIdDel1(String quId,Integer orderById){ if(quId!=null && !"".equals(quId)){ String sql="update t_qu_radio set order_by_id=order_by_id-1 where qu_id=? and order_by_id>=?"; //更新排序号 SQLQuery query=this.getSession().createSQLQuery(sql); query.setString(0, quId); query.setInteger(1, orderById); query.executeUpdate(); } }
Example 9
Source File: BaseDaoImpl.java From xmu-2016-MrCode with GNU General Public License v2.0 | 5 votes |
public int executeBySql(String sql, Map<String, Object> map) { SQLQuery query = hibernateTemplate.getSessionFactory() .getCurrentSession().createSQLQuery(sql); if (map != null) { setQuery(map, query); } return query.executeUpdate(); }
Example 10
Source File: PipelineRepository.java From gocd with Apache License 2.0 | 5 votes |
public static int updateNaturalOrderForPipeline(Session session, Long pipelineId, double naturalOrder) { String sql = "UPDATE pipelines SET naturalOrder = :naturalOrder WHERE id = :pipelineId"; SQLQuery query = session.createSQLQuery(sql); query.setLong("pipelineId", pipelineId); query.setDouble("naturalOrder", naturalOrder); return query.executeUpdate(); }