List of usage examples for javax.persistence Query executeUpdate
int executeUpdate();
From source file:me.ronghai.sa.dao.impl.AbstractModelDAOWithEMImpl.java
@Override public int remove(boolean force, Collection<Long> ids, String configure) { if (ids == null || ids.isEmpty()) { return 0; }/* w w w. j a v a 2 s. co m*/ String sql; if (force) { sql = "DELETE FROM " + entityClass.getName() + " e where id in (:ids) "; } else { sql = "UPDATE " + entityClass.getName() + " SET disabled = 1 where id in (:ids) "; } if (org.apache.commons.lang.StringUtils.isNotEmpty(configure)) { sql += " " + configure.replaceAll("'", "''"); } System.out.println(sql); Query query = entityManager.createQuery(sql); query.setParameter("ids", ids); int s = query.executeUpdate(); return s; }
From source file:org.cleverbus.core.common.dao.MessageOperationDaoJpaImpl.java
@Override public boolean setCancelState(Message msg) { Assert.notNull(msg, "the msg must not be null"); String jSql = "UPDATE " + Message.class.getName() + " SET state = ?1 " + " WHERE msgId = ?2 AND state IN (?3)"; Query q = em.createQuery(jSql); q.setParameter(1, MsgStateEnum.CANCEL); q.setParameter(2, msg.getMsgId());//from ww w . j ava2 s . c o m q.setParameter(3, Arrays.asList(MsgStateEnum.NEW, MsgStateEnum.PARTLY_FAILED, MsgStateEnum.POSTPONED)); return q.executeUpdate() > 0; }
From source file:org.apache.syncope.core.persistence.jpa.dao.JPAAccessTokenDAO.java
@Override public int deleteExpired() { Query query = entityManager().createQuery( "DELETE FROM " + JPAAccessToken.class.getSimpleName() + " e " + "WHERE e.expiryTime < :now"); query.setParameter("now", new Date()); return query.executeUpdate(); }
From source file:org.dragoneronca.nlp.wol.domain.WolDomainContext.java
public void updateScore(int id, double score) { WolDomainContext domainContext = WolDomainContext.getInstance(); EntityManager entityManager = domainContext.getEntityManager(); SemanticEdge edge = entityManager.find(SemanticEdge.class, id); if (edge == null || edge instanceof TermSemanticEdge) { Query q = entityManager.createNamedQuery("updateScoreTermSemanticEdge"); q.setParameter(1, score).setParameter(2, id); q.executeUpdate(); } else {//from ww w .j a v a 2s . com Query q = entityManager.createNamedQuery("updateScoreSemanticEdge"); q.setParameter(1, score).setParameter(2, id); q.executeUpdate(); } }
From source file:co.sip.dmesmobile.bs.ScStopDao.java
@Override @Transactional/*from w ww . j av a2 s . c o m*/ public int updateStopMachineState(String duration, String responseDate, String idStopMachine, String idMaintenance) throws Exception { entityManager = Factory.getEntityManagerFactory().createEntityManager(); entityManager.getTransaction().begin(); int result = -1; String stringQuery = "UPDATE dmes.sc_stop_machine SET duration_real = " + duration + (!Utilities.isEmpty(idMaintenance) ? ", id_maintenance = (" + idMaintenance + ")" : " ") + ", response_date = TO_TIMESTAMP('" + responseDate + "','DD/MM/YYYY HH24:MI:SS') " + " WHERE id_stop_machine = " + idStopMachine; try { Query query = entityManager.createNativeQuery(stringQuery); result = query.executeUpdate(); if (!Utilities.isEmpty(idMaintenance)) { String queryMaintenance = "UPDATE dmes.ot_maintenance SET duration = " + duration + ", response_date = TO_TIMESTAMP('" + responseDate + "','DD/MM/YYYY HH24:MI:SS') " + "WHERE id_maintenance = " + idMaintenance; query = entityManager.createNativeQuery(stringQuery); query.executeUpdate(); } entityManager.getTransaction().commit(); } catch (Exception e) { log.error("Error intentando actualizar el paro de mquina", e); throw e; } return result; }
From source file:org.rhq.enterprise.server.content.DistributionManagerBean.java
/** * deletes list of available distribution files for requested distribution * @param distId/*from w w w . ja v a 2 s . co m*/ */ public void deleteDistributionFilesByDistId(Subject user, int distId) { log.debug("User [" + user + "] is deleting distribution file from distribution [" + distId + "]"); entityManager.flush(); entityManager.clear(); Query querydel = entityManager.createNamedQuery(DistributionFile.SELECT_BY_DIST_ID); querydel.setParameter("distId", distId); querydel.executeUpdate(); DistributionFile distFile = entityManager.find(DistributionFile.class, distId); if (distFile != null) { entityManager.remove(distFile); log.debug("User [" + user + "] deleted distribution file [" + distFile + "]"); } else { log.debug("Distribution file [" + distFile + "] doesn't exist - nothing to delete"); } }
From source file:org.apache.openmeetings.db.dao.user.PrivateMessageDao.java
public int moveMailsToFolder(Collection<Long> ids, Long folderId) { Query query = em.createNamedQuery("moveMailsToFolder"); query.setParameter("folderId", folderId); query.setParameter("ids", ids); return query.executeUpdate(); }
From source file:org.apache.falcon.jdbc.BacklogMetricStore.java
public void deleteEntityBackLogInstances(String entityName, String entityType) { EntityManager entityManager = getEntityManager(); beginTransaction(entityManager);/*from w w w. jav a2 s . co m*/ Query q = entityManager.createNamedQuery(PersistenceConstants.DELETE_ALL_BACKLOG_ENTITY_INSTANCES); q.setParameter("entityName", entityName); q.setParameter("entityType", entityType); try { q.executeUpdate(); } finally { commitAndCloseTransaction(entityManager); } }
From source file:es.ucm.fdi.dalgs.topic.repository.TopicRepository.java
public boolean deleteTopicsForModule(Module module) { try {/*from w ww. jav a2 s . c om*/ Query query = em.createQuery("UPDATE Topic t SET t.isDeleted = true where t.module = ?1"); query.setParameter(1, module); query.executeUpdate(); return true; } catch (Exception e) { logger.error(e.getMessage()); return false; } }
From source file:com.easyjf.core.dao.impl.GenericDAOImpl.java
public int executeNativeSQL(final String nnq) { Object ret = this.getJpaTemplate().execute(new JpaCallback() { public Object doInJpa(EntityManager em) throws PersistenceException { Query query = em.createNativeQuery(nnq); return query.executeUpdate(); }//from w ww .j a v a 2s.c o m }); return (Integer) ret; }