List of usage examples for javax.persistence Query executeUpdate
int executeUpdate();
From source file:org.rhq.enterprise.server.cloud.AffinityGroupManagerBean.java
@RequiredPermission(Permission.MANAGE_INVENTORY) public int delete(Subject subject, Integer[] affinityGroupIds) { // A deleted affinity group forces a cloud repartitioning. Note, it is ok to request multiple // cloud repartitions, they will be consolidated by the cloud manager job. for (Integer agId : affinityGroupIds) { AffinityGroup ag = entityManager.find(AffinityGroup.class, agId); partitionEventManager.cloudPartitionEventRequest(subject, PartitionEventType.AFFINITY_GROUP_DELETE, ag.getName());/* ww w .j a va 2s . c o m*/ } Query updateAgentsQuery = entityManager.createNamedQuery(AffinityGroup.QUERY_UPDATE_REMOVE_AGENTS); Query updateServersQuery = entityManager.createNamedQuery(AffinityGroup.QUERY_UPDATE_REMOVE_SERVERS); Query removeQuery = entityManager.createNamedQuery(AffinityGroup.QUERY_DELETE_BY_IDS); List<Integer> affinityGroups = Arrays.asList(affinityGroupIds); updateAgentsQuery.setParameter("affinityGroupIds", affinityGroups); updateServersQuery.setParameter("affinityGroupIds", affinityGroups); removeQuery.setParameter("affinityGroupIds", affinityGroups); int updatedAgents = updateAgentsQuery.executeUpdate(); int updatedServers = updateServersQuery.executeUpdate(); int removedAffinityGroups = removeQuery.executeUpdate(); log.debug("Removed " + removedAffinityGroups + " AffinityGroups: " + updatedAgents + " agents and " + updatedServers + " were updated"); return removedAffinityGroups; }
From source file:org.apache.roller.weblogger.business.jpa.JPAWeblogManagerImpl.java
/** * convenience method for removing contents of a weblog. * TODO BACKEND: use manager methods instead of queries here */// www . ja v a2 s.co m private void removeWebsiteContents(Weblog website) throws WebloggerException { UserManager umgr = roller.getUserManager(); WeblogManager wmgr = roller.getWeblogManager(); WeblogEntryManager emgr = roller.getWeblogEntryManager(); BookmarkManager bmgr = roller.getBookmarkManager(); MediaFileManager mmgr = roller.getMediaFileManager(); //remove theme Assocs Query themeAssocQuery = strategy.getNamedQuery("WeblogThemeAssoc.getThemeAssocsByWeblog"); themeAssocQuery.setParameter(1, website); List assocResults = themeAssocQuery.getResultList(); for (Iterator iter = assocResults.iterator(); iter.hasNext();) { WeblogThemeAssoc themeAssoc = (WeblogThemeAssoc) iter.next(); this.strategy.remove(themeAssoc); } // remove tags Query tagQuery = strategy.getNamedQuery("WeblogEntryTag.getByWeblog"); tagQuery.setParameter(1, website); List results = tagQuery.getResultList(); for (Iterator iter = results.iterator(); iter.hasNext();) { WeblogEntryTag tagData = (WeblogEntryTag) iter.next(); if (tagData.getWeblogEntry() != null) { tagData.getWeblogEntry().getTags().remove(tagData); } this.strategy.remove(tagData); } // remove site tag aggregates List tags = emgr.getTags(website, null, null, 0, -1); updateTagAggregates(tags); // delete all weblog tag aggregates Query removeAggs = strategy.getNamedUpdate("WeblogEntryTagAggregate.removeByWeblog"); removeAggs.setParameter(1, website); removeAggs.executeUpdate(); // delete all bad counts Query removeCounts = strategy.getNamedUpdate("WeblogEntryTagAggregate.removeByTotalLessEqual"); removeCounts.setParameter(1, new Integer(0)); removeCounts.executeUpdate(); // Remove the website's ping queue entries Query q = strategy.getNamedQuery("PingQueueEntry.getByWebsite"); q.setParameter(1, website); List queueEntries = q.getResultList(); Iterator it = queueEntries.iterator(); while (it.hasNext()) { this.strategy.remove((PingQueueEntry) it.next()); } // Remove the website's auto ping configurations AutoPingManager autoPingMgr = roller.getAutopingManager(); List autopings = autoPingMgr.getAutoPingsByWebsite(website); it = autopings.iterator(); while (it.hasNext()) { this.strategy.remove((AutoPing) it.next()); } // Remove the website's custom ping targets PingTargetManager pingTargetMgr = roller.getPingTargetManager(); List pingtargets = pingTargetMgr.getCustomPingTargets(website); it = pingtargets.iterator(); while (it.hasNext()) { this.strategy.remove((PingTarget) it.next()); } // remove associated referers Query refQuery2 = strategy.getNamedQuery("WeblogReferrer.getByWebsite"); refQuery2.setParameter(1, website); List referers = refQuery2.getResultList(); for (Iterator iter = referers.iterator(); iter.hasNext();) { WeblogReferrer referer = (WeblogReferrer) iter.next(); this.strategy.remove(referer.getClass(), referer.getId()); } // TODO: can we eliminate this unnecessary flush with OpenJPA 1.0 this.strategy.flush(); // remove associated pages Query pageQuery = strategy.getNamedQuery("WeblogTemplate.getByWebsite"); pageQuery.setParameter(1, website); List pages = pageQuery.getResultList(); for (Iterator iter = pages.iterator(); iter.hasNext();) { WeblogTemplate page = (WeblogTemplate) iter.next(); //remove associated templateCode objects this.removeTemplateCodeObjs(page); this.strategy.remove(page); } // remove folders (including bookmarks) WeblogBookmarkFolder rootFolder = bmgr.getRootFolder(website); if (null != rootFolder) { this.strategy.remove(rootFolder); } this.strategy.flush(); // remove mediafile metadata // remove uploaded files MediaFileManager mfmgr = WebloggerFactory.getWeblogger().getMediaFileManager(); mfmgr.removeAllFiles(website); //List<MediaFileDirectory> dirs = mmgr.getMediaFileDirectories(website); //for (MediaFileDirectory dir : dirs) { //this.strategy.remove(dir); //} this.strategy.flush(); // remove entries Query refQuery = strategy.getNamedQuery("WeblogEntry.getByWebsite"); refQuery.setParameter(1, website); List entries = refQuery.getResultList(); for (Iterator iter = entries.iterator(); iter.hasNext();) { WeblogEntry entry = (WeblogEntry) iter.next(); emgr.removeWeblogEntry(entry); } this.strategy.flush(); // remove categories WeblogCategory rootCat = emgr.getRootWeblogCategory(website); if (null != rootCat) { this.strategy.remove(rootCat); } // remove permissions for (Iterator iterator = umgr.getWeblogPermissions(website).iterator(); iterator.hasNext();) { WeblogPermission perm = (WeblogPermission) iterator.next(); umgr.revokeWeblogPermission(perm.getWeblog(), perm.getUser(), WeblogPermission.ALL_ACTIONS); } // flush the changes before returning. This is required as there is a // circular dependency between WeblogCategory and Weblog this.strategy.flush(); }
From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java
@Override @Transactional// w w w .j a v a2 s . c om @ExcludeFromProfileLastModifiedUpdate public void updateIndexingStatus(String orcid, IndexingStatus indexingStatus) { String queryString = null; if (IndexingStatus.DONE.equals(indexingStatus)) { queryString = "update ProfileEntity set indexingStatus = :indexingStatus, lastIndexedDate = now() where orcid = :orcid"; updateWebhookProfileLastUpdate(orcid); } else { queryString = "update ProfileEntity set indexingStatus = :indexingStatus where orcid = :orcid"; } Query query = entityManager.createQuery(queryString); query.setParameter("orcid", orcid); query.setParameter("indexingStatus", indexingStatus); query.executeUpdate(); }
From source file:eu.planets_project.pp.plato.action.project.LoadPlanAction.java
/** * Loads a project from database that was selected by the user. * * Previously loaded project is unlocked. * * Forwards the user to respective workflowstep by calling the workflow step's * <code>enter</code> method. */// w w w. j a v a2 s.co m @RaiseEvent("reload") public String load() { String id = ""; try { id = ((HttpServletRequest) facesContext.getExternalContext().getRequest()).getSession().getId(); } catch (RuntimeException e) { log.debug("Couldn't get SessionID"); } log.info("Session=" + id + " of user " + user.getUsername() + " is loading project " + selection.getId() + " - " + selection.getName()); // try to lock the project Query q = em.createQuery( "update PlanProperties pp set pp.openHandle = 1, pp.openedByUser = '" + user.getUsername() + "' where (pp.openHandle is null or pp.openHandle = 0) and pp.id = " + selection.getId()); int num = q.executeUpdate(); if (num < 1) { FacesMessages.instance().add(FacesMessage.SEVERITY_INFO, "In the meantime the plan has been loaded by an other user. Please choose another plan."); relist(); log.debug("Locking plan failed"); return null; } List<Plan> list = em.createQuery("select p from Plan p where p.planProperties.id = " + selection.getId()) .getResultList(); // we locked the project before be we now cannot load it. not good. if (list.size() != 1) { FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR, "An unexpected error has occured while loading the plan."); return null; } // ok - the selected project is free - unlock the old project unlockProject(); // load the selected project (and keep the id!) setPlanPropertiesID(selection.getId()); selectedPlan = em.find(Plan.class, list.get(0).getId()); // Strangely enough the outjection doesnt work here, so to be sure we set the member explicitly Contexts.getSessionContext().set("selectedPlan", selectedPlan); this.initializeProject(selectedPlan); log.info("Plan " + selectedPlan.getPlanProperties().getName() + " loaded!"); String msg = "The plan you loaded has reached the state " + selectedPlan.getState().getStateName() + ". Therefore you have been directed to the subsequent workflow step."; FacesMessages.instance().add(FacesMessage.SEVERITY_INFO, msg); if (selectedPlan.isFastTrackEvaluationPlan()) { switch (selectedPlan.getState().getValue()) { case PlanState.FTE_INITIALISED: return FTrequirements.enter(); case PlanState.FTE_REQUIREMENTS_DEFINED: return FTevaluate.enter(); case PlanState.FTE_ALTERNATIVES_EVALUATED: return FTanalyse.enter(); case PlanState.FTE_RESULTS_ANALYSED: return FTanalyse.enter(); } } // redirect to step corresponding to the project's state: switch (selectedPlan.getState().getValue()) { case PlanState.BASIS_DEFINED: return defineSampleRecords.enter(); case PlanState.RECORDS_CHOSEN: return identifyRequirements.enter(); case PlanState.TREE_DEFINED: return defineAlternatives.enter(); case PlanState.ALTERNATIVES_DEFINED: return gonogo.enter(); case PlanState.GO_CHOSEN: return devexperiments.enter(); case PlanState.EXPERIMENT_DEFINED: return runexperiments.enter(); case PlanState.EXPERIMENT_PERFORMED: return evalexperiments.enter(); case PlanState.RESULTS_CAPTURED: return transform.enter(); case PlanState.TRANSFORMATION_DEFINED: return importanceFactors.enter(); case PlanState.WEIGHTS_SET: return analyseResults.enter(); case PlanState.ANALYSED: return createExecutablePlan.enter(); case PlanState.EXECUTEABLE_PLAN_CREATED: return definePlan.enter(); case PlanState.PLAN_DEFINED: return validatePlan.enter(); case PlanState.PLAN_VALIDATED: return validatePlan.enter(); default: return defineBasis.enter(); } }
From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java
@Override @Transactional/* w w w . jav a 2 s . co m*/ public void updateLastModifiedDateWithoutResult(String orcid) { Query query = entityManager .createNativeQuery("update profile set last_modified = now() where orcid = :orcid "); query.setParameter("orcid", orcid); query.executeUpdate(); }
From source file:mx.edu.ittepic.proyectofinal.ejbs.ejbContrasena.java
public String updateUserWithoutPassword(String userid, String username, String phone, String neigborhood, String zipcode, String city, String country, String state, String region, String street, String email, String streetnumber, String photo, String cellphone, String companyid, String roleid, String gender) { Message m = new Message(); Users r = new Users(); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create();/*from w w w . j a v a2 s . c om*/ Company com = entity.find(Company.class, Integer.parseInt(companyid)); Role rol = entity.find(Role.class, Integer.parseInt(roleid)); try { Query q = entity.createNamedQuery("Users.updateUserWithoutPassword").setParameter("username", username) .setParameter("phone", phone).setParameter("neigborhood", neigborhood) .setParameter("zipcode", zipcode).setParameter("city", city).setParameter("country", country) .setParameter("state", state).setParameter("region", region).setParameter("street", street) .setParameter("email", email).setParameter("streetnumber", streetnumber) .setParameter("photo", photo).setParameter("cellphone", cellphone) .setParameter("companyid", com).setParameter("roleid", rol) .setParameter("gender", gender.charAt(0)).setParameter("userid", Integer.parseInt(userid)); if (q.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:org.medici.bia.dao.user.UserDAOJpaImpl.java
/** * {@inheritDoc}//from ww w .j av a 2 s. c o m */ @Override public Integer renameAccount(String originalAccount, String newAccount) throws PersistenceException { String jpql = "UPDATE User SET account=:newAccount WHERE account=:originalAccount"; Query query = getEntityManager().createQuery(jpql); query.setParameter("newAccount", newAccount); query.setParameter("originalAccount", originalAccount); return query.executeUpdate(); }
From source file:org.medici.bia.dao.user.UserDAOJpaImpl.java
/** * {@inheritDoc}/* ww w . j a va2s . co m*/ */ @Override public Integer renameApprovedBy(String originalAccount, String newAccount) throws PersistenceException { String jpql = "UPDATE User SET approvedBy.account=:newAccount WHERE approvedBy.account=:originalAccount"; Query query = getEntityManager().createQuery(jpql); query.setParameter("newAccount", newAccount); query.setParameter("originalAccount", originalAccount); return query.executeUpdate(); }
From source file:org.tolven.analysis.bean.SnapshotBean.java
/** * This function deletes all patients in the echr:cohorts list, * on any change in the cohort properties. *///from w w w . j a va 2 s . c om @Override public void deleteCohortList(Account account, String analysisType, String cohortType) { Query query = em.createQuery("update MenuData md set md.deleted=TRUE WHERE " + "md.account.id = :account and md.string01 =:analysisType and md.string02 = :cohortType and md.path LIKE '%echr:cohort-%'"); query.setParameter("account", account.getId()); query.setParameter("analysisType", analysisType); query.setParameter("cohortType", cohortType); query.executeUpdate(); }
From source file:org.tolven.analysis.bean.SnapshotBean.java
/** * This function deletes the patients (It is generated manually when there is null cohort) * in the echr:cohorts list./*from w w w . ja v a 2s .c om*/ * @author Pinky * Created on 09/28/2010 */ @Override public void deleteFalseCohortList(Account account, String analysisType, String cohortType) { Query query = em.createQuery("update MenuData md set md.deleted=TRUE WHERE " + "md.account.id = :account and md.string08 =:analysisType and md.string02 = :cohortType and md.path LIKE '%echr:cohort-%'"); query.setParameter("account", account.getId()); query.setParameter("analysisType", analysisType); query.setParameter("cohortType", cohortType); query.executeUpdate(); }