List of usage examples for javax.persistence Query executeUpdate
int executeUpdate();
From source file:org.openmeetings.app.data.user.dao.PrivateMessagesDaoImpl.java
public int deletePrivateMessages(List<Long> privateMessageIds) { try {/*from www . j a v a 2 s.co m*/ String hql = "DELETE FROM PrivateMessages c " + "where c.privateMessageId IN (:privateMessageIds) "; Query query = em.createQuery(hql); query.setParameter("privateMessageIds", privateMessageIds); int updatedEntities = query.executeUpdate(); return updatedEntities; } catch (Exception e) { log.error("[updatePrivateMessagesReadStatus]", e); } return -1; }
From source file:org.apache.syncope.core.persistence.jpa.dao.JPAGroupDAO.java
@Override public Set<String> removeDynMemberships(final User user) { List<Group> dynGroups = userDAO().findDynGroups(user.getKey()); Query delete = entityManager().createNativeQuery("DELETE FROM " + UDYNMEMB_TABLE + " WHERE any_id=?"); delete.setParameter(1, user.getKey()); delete.executeUpdate(); Set<String> before = new HashSet<>(); dynGroups.forEach(group -> {/* ww w . j a v a 2 s.c om*/ before.add(group.getKey()); publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, group, AuthContextUtils.getDomain())); }); return before; }
From source file:seava.j4e.business.service.entity.AbstractEntityWriteService.java
/** * Execute a JPQL update statement.//w w w .j a v a 2 s . c o m * * @param jpqlStatement * @param parameters * @return * @throws BusinessException */ @Transactional public int update(String jpqlStatement, Map<String, Object> parameters) throws BusinessException { Query q = this.getEntityManager().createQuery(jpqlStatement); if (parameters != null) { for (Map.Entry<String, Object> p : parameters.entrySet()) { q.setParameter(p.getKey(), p.getValue()); } } return q.executeUpdate(); }
From source file:org.apache.syncope.core.persistence.jpa.dao.JPAGroupDAO.java
@Override public Set<String> removeDynMemberships(final AnyObject anyObject) { List<Group> dynGroups = anyObjectDAO().findDynGroups(anyObject.getKey()); Query delete = entityManager().createNativeQuery("DELETE FROM " + ADYNMEMB_TABLE + " WHERE any_id=?"); delete.setParameter(1, anyObject.getKey()); delete.executeUpdate(); Set<String> before = new HashSet<>(); dynGroups.forEach(group -> {//ww w .j a v a 2 s . c o m before.add(group.getKey()); publisher.publishEvent(new AnyCreatedUpdatedEvent<>(this, group, AuthContextUtils.getDomain())); }); return before; }
From source file:com.doculibre.constellio.services.RecordServicesImpl.java
@Override public void deleteRecords(ConnectorInstance connectorInstance) { String sqlContentMeta = "DELETE FROM Record_ContentMetas WHERE record_id IN" + " (SELECT r.id FROM Record r, ConnectorInstance ci WHERE r.connectorInstance_id=ci.id AND ci.id=?)"; Query contentMetaQuery = getEntityManager().createNativeQuery(sqlContentMeta); contentMetaQuery.setParameter(1, connectorInstance.getId()); contentMetaQuery.executeUpdate(); String sqlExternalMeta = "DELETE FROM Record_ExternalMetas WHERE record_id IN" + " (SELECT r.id FROM Record r, ConnectorInstance ci WHERE r.connectorInstance_id=ci.id AND ci.id=?)"; Query externalMetaQuery = getEntityManager().createNativeQuery(sqlExternalMeta); externalMetaQuery.setParameter(1, connectorInstance.getId()); externalMetaQuery.executeUpdate();/*from ww w .j a v a 2 s .co m*/ String sqlMeta = "DELETE FROM RecordMeta WHERE record_id IN" + " (SELECT r.id FROM Record r, ConnectorInstance ci WHERE r.connectorInstance_id=ci.id AND ci.id=?)"; Query metaQuery = getEntityManager().createNativeQuery(sqlMeta); metaQuery.setParameter(1, connectorInstance.getId()); metaQuery.executeUpdate(); String sqlTag = "DELETE FROM RecordTag WHERE record_id IN" + " (SELECT r.id FROM Record r, ConnectorInstance ci WHERE r.connectorInstance_id=ci.id AND ci.id=?)"; Query tagQuery = getEntityManager().createNativeQuery(sqlTag); tagQuery.setParameter(1, connectorInstance.getId()); tagQuery.executeUpdate(); String sqlRawContent = "DELETE FROM RawContent WHERE record_id" + " IN (SELECT r.id FROM Record r, ConnectorInstance ci WHERE r.connectorInstance_id=ci.id AND ci.id=?)"; Query rawConentQuery = getEntityManager().createNativeQuery(sqlRawContent); rawConentQuery.setParameter(1, connectorInstance.getId()); rawConentQuery.executeUpdate(); String sqlFederationIndexingRequired = "DELETE FROM FederationRecordIndexingRequired WHERE recordId" + " IN (SELECT r.id FROM Record r, ConnectorInstance ci WHERE r.connectorInstance_id=ci.id AND ci.id=?)"; Query rawFederationIndexingRequired = getEntityManager().createNativeQuery(sqlFederationIndexingRequired); rawFederationIndexingRequired.setParameter(1, connectorInstance.getId()); rawFederationIndexingRequired.executeUpdate(); String sqlFederationDeletionRequired = "DELETE FROM FederationRecordDeletionRequired WHERE recordId" + " IN (SELECT r.id FROM Record r, ConnectorInstance ci WHERE r.connectorInstance_id=ci.id AND ci.id=?)"; Query rawFederationDeletionRequired = getEntityManager().createNativeQuery(sqlFederationDeletionRequired); rawFederationDeletionRequired.setParameter(1, connectorInstance.getId()); rawFederationDeletionRequired.executeUpdate(); Query recordQuery = this.getEntityManager() .createQuery("DELETE FROM Record r WHERE r.connectorInstance = :connectorInstance"); recordQuery.setParameter("connectorInstance", connectorInstance); recordQuery.executeUpdate(); }
From source file:org.rhq.enterprise.server.alert.AlertNotificationManagerBean.java
private int cleanseParameterValueForAlertSender(String senderName, String propertyName, String valueToCleanse) { Query query = entityManager .createNamedQuery(AlertNotification.QUERY_CLEANSE_PARAMETER_VALUE_FOR_ALERT_SENDER); query.setParameter("senderName", senderName); query.setParameter("propertyName", propertyName); query.setParameter("paramValue", "|" + valueToCleanse + "|"); // wrap with fence-delimiter for search int affectedRows = query.executeUpdate(); return affectedRows; }
From source file:mx.edu.ittepic.proyectofinal.ejbs.ejbUsers.java
public String updateUser(String userid, String apikey) { Message m = new Message(); Users r = new Users(); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create();/* ww w . ja v a 2 s .c o m*/ try { Query q = entity.createNamedQuery("Users.updateUser"). setParameter("apikey", apikey).setParameter("userid", Integer.parseInt(userid)); String idapi = userid; String md5 = DigestUtils.md5Hex(idapi); Query a = entity.createNamedQuery("Users.updateUserE").setParameter("apikey", md5) .setParameter("userid", Integer.parseInt(userid)); if (q.executeUpdate() == 1 && a.executeUpdate() == 1) { m.setCode(200); m.setMsg("Se actualizo correctamente."); m.setDetail("OK"); } else { m.setCode(404); m.setMsg("No se realizo la actualizacion"); m.setDetail(""); } } catch (IllegalStateException e) { m.setCode(404); m.setMsg("No se realizo la actualizacion"); m.setDetail(e.toString()); } catch (TransactionRequiredException e) { m.setCode(404); m.setMsg("No se realizo la actualizacion"); m.setDetail(e.toString()); } catch (QueryTimeoutException e) { m.setCode(404); m.setMsg("No se realizo la actualizacion"); m.setDetail(e.toString()); } catch (PersistenceException e) { m.setCode(404); m.setMsg("No se realizo la actualizacion"); m.setDetail(e.toString()); } return gson.toJson(m); }
From source file:eu.planets_project.pp.plato.action.project.LoadPlanAction.java
/** * Unlocks certain projects in database (dependent on parameter) * * @param useId If this is true, only project with id {@link #planPropertiesId} will be unlocked; * otherwise, all projects in database will be unlocked *//*from www .j av a 2 s . c om*/ private void unlockQuery(boolean useId) { String where = ""; if (useId) { where = "where pp.id = " + planPropertiesId; } Query q = em.createQuery("update PlanProperties pp set pp.openHandle = 0, pp.openedByUser = ''" + where); try { if (q.executeUpdate() < 1) { log.debug("Unlocking plan failed."); } else { log.debug("Unlocked plan"); } } catch (Throwable e) { log.error("Unlocking plan failed:", e); } planPropertiesId = 0; }
From source file:org.rhq.enterprise.server.measurement.MeasurementBaselineManagerBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) //@TransactionTimeout( 60 * 60 ) public int _calculateAutoBaselinesDELETE(long olderThanTime) throws Exception { Query query = entityManager.createNamedQuery(MeasurementBaseline.QUERY_DELETE_BY_COMPUTE_TIME); query.setParameter("timestamp", olderThanTime); int rowsAffected = query.executeUpdate(); return rowsAffected; }
From source file:com.ge.apm.service.data.DataService.java
public Object postDirectData(String tablename, List<Map> list) { if (tablename == null) return "{\"code\":\"1\",\"msg\":\"please input table_name\"}"; if (list == null || list.isEmpty()) return "{\"code\":\"1\",\"msg\":\"no data post\"}"; String tableName = tablename.toLowerCase(); String talbeClassName = "com.ge.apm.domain." + tabelNameToClassName(tableName); Class<?> table = getDao(talbeClassName); Map<String, String> fields = getFields(table); EntityManagerFactory emf = WebUtil.getBean(EntityManagerFactory.class); EntityManager em = emf.createEntityManager(); int fortimes = list.size() / 50 + 1;// for (int j = 0; j < fortimes; j++) { List<Map> subList = list.subList(j * 50, (j + 1) * 50 < list.size() ? (j + 1) * 50 : list.size()); em.getTransaction().begin();// w w w . java2 s.c o m Query query = null; for (int i = 0; i < subList.size(); i++) { Map<String, Object> map = subList.get(i); String outColumnStr = "insert into " + tableName + " ("; String outValueStr = ") values("; String[] strs = insertColumn(fields, map); outColumnStr += strs[0]; outValueStr += strs[1]; String sql = outColumnStr + outValueStr + ")"; query = em.createNativeQuery(sql); query.executeUpdate(); } try { em.getTransaction().commit(); } catch (Exception ex) { em.getTransaction().rollback(); Logger.getLogger(DataGetAndPushController.class.getName()).log(Level.SEVERE, null, ex); em.close(); return "{\"code\":\"1\",\"msg\":\"save failed\"}";// } } if (em != null) { em.close(); } return "{\"code\":\"0\",\"msg\":\"save success\"}";//? }