List of usage examples for javax.persistence Query executeUpdate
int executeUpdate();
From source file:org.apache.falcon.state.store.jdbc.JDBCStateStore.java
@Override public void deleteExecutionInstances() { if (!isModeDebug()) { throw new UnsupportedOperationException("Delete Instances Table not supported"); }/*from w ww . jav a 2 s . c o m*/ EntityManager entityManager = getEntityManager(); beginTransaction(entityManager); Query q = entityManager.createNamedQuery(PersistenceConstants.DELETE_INSTANCES_TABLE); q.executeUpdate(); commitAndCloseTransaction(entityManager); }
From source file:org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.hibernate.AttachmentMgtDAOFactoryImpl.java
@Override public boolean removeAttachment(final String id) throws AttachmentMgtException { try {/*from w w w. j a v a 2s . co m*/ boolean isRemoved = false; isRemoved = jobExecutor.execTransaction(new Callable<Boolean>() { @Override public Boolean call() throws Exception { Query query = entityManager .createQuery("DELETE FROM org.wso2.carbon.attachment.mgt.core.dao.impl" + ".jpa.openjpa.entity.AttachmentDAOImpl x WHERE x.id = " + ":attachmentID"); query.setParameter("attachmentID", Long.parseLong(id)); int noOfRowsUpdated = query.executeUpdate(); //entityManager.remove(getAttachmentInfo(id)); if (noOfRowsUpdated == 1) { return true; } else { return false; } } }); return isRemoved; } catch (Exception e) { String errorMsg = "org.wso2.carbon.attachment.mgt.core.dao.impl.hibernate.AttachmentMgtDAOFactoryImpl.removeAttachment operation failed. " + "Reason: " + e.getLocalizedMessage(); log.error(errorMsg, e); throw new AttachmentMgtException(errorMsg, e); } }
From source file:org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.AttachmentMgtDAOFactoryImpl.java
@Override public boolean removeAttachment(final String id) throws AttachmentMgtException { try {/*from w w w . ja va 2 s. co m*/ boolean isRemoved = false; isRemoved = jobExecutor.execTransaction(new Callable<Boolean>() { @Override public Boolean call() throws Exception { Query query = entityManager .createQuery("DELETE FROM org.wso2.carbon.attachment.mgt.core.dao.impl" + ".jpa.openjpa.entity.AttachmentDAOImpl x WHERE x.id = " + ":attachmentID"); query.setParameter("attachmentID", Long.parseLong(id)); int noOfRowsUpdated = query.executeUpdate(); //entityManager.remove(getAttachmentInfo(id)); if (noOfRowsUpdated == 1) { return true; } else { return false; } } }); return isRemoved; } catch (Exception e) { String errorMsg = "org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.AttachmentMgtDAOFactoryImpl.removeAttachment operation failed. " + "Reason: " + e.getLocalizedMessage(); log.error(errorMsg, e); throw new AttachmentMgtException(errorMsg, e); } }
From source file:org.rhq.enterprise.server.resource.ResourceAvailabilityManagerBean.java
public void updateAgentResourcesLatestAvailability(int agentId, AvailabilityType availabilityType, boolean isPlatform) { Query query = entityManager.createNamedQuery((isPlatform) ? ResourceAvailability.UPDATE_PLATFORM_BY_AGENT_ID : ResourceAvailability.UPDATE_CHILD_BY_AGENT_ID); query.setParameter("availabilityType", availabilityType); query.setParameter("agentId", agentId); if (!isPlatform) { query.setParameter("disabled", AvailabilityType.DISABLED); }/*from w ww.j a va 2 s . com*/ query.executeUpdate(); }
From source file:ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoSubscriptionDstu3.java
@Override protected ResourceTable updateEntity(IBaseResource theResource, ResourceTable theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime) {/*w ww .ja v a2 s . co m*/ ResourceTable retVal = super.updateEntity(theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime); Subscription resource = (Subscription) theResource; Long resourceId = theEntity.getId(); if (theDeletedTimestampOrNull != null) { Long subscriptionId = getSubscriptionTablePidForSubscriptionResource(theEntity.getIdDt()); if (subscriptionId != null) { mySubscriptionFlaggedResourceDataDao.deleteAllForSubscription(subscriptionId); mySubscriptionTableDao.deleteAllForSubscription(subscriptionId); } } else { Query q = myEntityManager.createNamedQuery("Q_HFJ_SUBSCRIPTION_SET_STATUS"); q.setParameter("res_id", resourceId); q.setParameter("status", resource.getStatusElement().getValueAsString()); if (q.executeUpdate() > 0) { ourLog.info("Updated subscription status for subscription {} to {}", resourceId, resource.getStatus()); } else { createSubscriptionTable(retVal, resource); } } return retVal; }
From source file:com.exp.tracker.services.impl.JpaExpenseService.java
@Transactional public int saveExpense(ExpenseDetail ed) { int result = 0; ExpenseEntity ex;//w w w . j a v a2 s .c o m if (null == ed.getSettlementId()) { // calculate shares if not calculated yet. if (!ed.isOverrideSharesFlag()) { ed.calculateShareAmounts(); } // we need to merge if the user is editing this record if (ed.isEditMode()) { ex = em.find(ExpenseEntity.class, ed.getId()); // now put back field by field ex.setAmount(ed.getAmount()); ex.setCategory(ed.getCategory()); ex.setCreatedBy(ed.getCreatedBy()); ex.setDate(ed.getDate()); ex.setDescription(ed.getDescription()); ex.setPaidBy(ed.getPaidBy()); ex.setSettlementId(ed.getSettlementId()); // you can not do any of these below. JPA does not support // ex.setUserExpenseSet(null); // ex.setUserExpenseSet(new ArrayList<UserExpenseEntity>()); // first delete all children Query deleteUserExpenseEntitiesForExpense = em .createNamedQuery("deleteUserExpenseEntitiesForExpense"); deleteUserExpenseEntitiesForExpense.setParameter("expense_id", ex.getId()); deleteUserExpenseEntitiesForExpense.executeUpdate(); // children deleted ex.setUserExpenseSet(null); em.merge(ex); } else { ex = ed.getExpenseEntity(); em.persist(ex); // em.flush(); } // now merge children Long id = ex.getId(); Set<UserExpenseEntity> userExpenseSet = new HashSet<UserExpenseEntity>(); for (UserShare us : ed.getUserShares()) { if (us.isParticipationFlag()) { UserExpenseEntity uee = new UserExpenseEntity(); uee.setUsername(us.getName()); uee.setExpense_id(id); uee.setShareAmount(us.getShareAmount()); uee.setDiscountPercent(us.getDiscountPercent()); userExpenseSet.add(uee); } } ex.setUserExpenseSet(userExpenseSet); em.merge(ex); em.flush(); } else { // you cant edit a settled record result = 1; } return result; }
From source file:org.rhq.enterprise.server.alert.GroupAlertDefinitionManagerBean.java
public int removeGroupAlertDefinitions(Subject subject, Integer[] groupAlertDefinitionIds) { if (groupAlertDefinitionIds == null || groupAlertDefinitionIds.length == 0) { return 0; }/* w w w . j a v a 2s .c o m*/ int modified = 0; List<Integer> allChildDefinitionIds = new ArrayList<Integer>(); Subject overlord = subjectManager.getOverlord(); for (Integer groupAlertDefinitionId : groupAlertDefinitionIds) { List<Integer> childDefinitions = getChildrenAlertDefinitionIds(subject, groupAlertDefinitionId); allChildDefinitionIds.addAll(childDefinitions); modified += alertDefinitionManager.removeAlertDefinitions(subject, new int[] { groupAlertDefinitionId }); alertDefinitionManager.removeAlertDefinitions(overlord, ArrayUtils.unwrapCollection(childDefinitions)); } /* * break the Hibernate relationships used for navigating between the groupAlertDefinition and the * children alertDefinitions so that the async deletion mechanism can delete without FK violations */ if (allChildDefinitionIds.size() > 0) { Query breakLinksQuery = entityManager.createNamedQuery(AlertDefinition.QUERY_UPDATE_SET_PARENTS_NULL); breakLinksQuery.setParameter("childrenDefinitionIds", allChildDefinitionIds); breakLinksQuery.executeUpdate(); } return modified; }
From source file:org.rhq.enterprise.server.alert.GroupAlertDefinitionManagerBean.java
public void removeGroupAlertDefinitions(Subject subject, int resourceGroupId, int[] resourceIdsToRemove) { if (resourceIdsToRemove == null || resourceIdsToRemove.length == 0) { return;/*w w w . j a va 2 s. co m*/ } Integer[] groupAlertDefinitionIdsForResourceGroup = findGroupAlertDefinitionIds(resourceGroupId); List<Integer> allChildrenDefinitionIds = new ArrayList<Integer>(); Subject overlord = subjectManager.getOverlord(); for (Integer nextGroupAlertDefinitionId : groupAlertDefinitionIdsForResourceGroup) { List<Integer> childDefinitions = getChildrenAlertDefinitionIds(subject, nextGroupAlertDefinitionId); allChildrenDefinitionIds.addAll(childDefinitions); alertDefinitionManager.removeAlertDefinitions(overlord, ArrayUtils.unwrapCollection(childDefinitions)); } /* * break the Hibernate relationships used for navigating between the groupAlertDefinition and the * children alertDefinitions so that the async deletion mechanism can delete without FK violations */ if (allChildrenDefinitionIds.size() > 0) { Query breakLinksQuery = entityManager.createNamedQuery(AlertDefinition.QUERY_UPDATE_SET_PARENTS_NULL); breakLinksQuery.setParameter("childrenDefinitionIds", allChildrenDefinitionIds); breakLinksQuery.executeUpdate(); } }
From source file:com.easyjf.core.dao.impl.GenericDAOImpl.java
public int batchUpdate(final String jpql, final Object[] params) { Object ret = this.getJpaTemplate().execute(new JpaCallback() { public Object doInJpa(EntityManager em) throws PersistenceException { Query query = em.createQuery(jpql); int parameterIndex = 1; if (params != null && params.length > 0) { for (Object obj : params) { query.setParameter(parameterIndex++, obj); }/* w w w . j av a 2 s.co m*/ } return query.executeUpdate(); } }); return (Integer) ret; }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaBucketDao.java
/** * @see {@link BucketDao#deleteDrop(Long, Long)} *//* ww w.ja v a2 s. c o m*/ public boolean deleteDrop(Long id, Long dropId) { String sql = "DELETE FROM buckets_droplets " + "WHERE bucket_id = :bucketId " + "AND droplet_id = :dropId"; Query query = this.em.createNativeQuery(sql); query.setParameter("bucketId", id); query.setParameter("dropId", dropId); return query.executeUpdate() == 1; }