List of usage examples for javax.persistence Query executeUpdate
int executeUpdate();
From source file:com.softwarecorporativo.monitoriaifpe.funcionais.atividade.TesteAtividade.java
@Test public void testeAprovarAtividadesDeMonitoria() { Query query = super.entityManager .createQuery("UPDATE Atividade AS a SET a.situacao = ?1 WHERE a.situacao = ?2"); query.setParameter(1, SituacaoAtividade.APROVADA); query.setParameter(2, SituacaoAtividade.AGUARDANDO_APROVACAO); query.executeUpdate(); TypedQuery<Long> typedQuery = super.entityManager .createQuery("SELECT COUNT(a) FROM Atividade a where a.situacao = :situacao", Long.class); typedQuery.setParameter("situacao", SituacaoAtividade.AGUARDANDO_APROVACAO); Long quantidadeEsperada = 0L; Long quantidade = typedQuery.getSingleResult(); assertEquals(quantidadeEsperada, quantidade); }
From source file:org.rhq.enterprise.server.cloud.FailoverListManagerBean.java
public void deleteServerListDetailsForServer(int serverId) { Query query = entityManager.createNamedQuery(FailoverListDetails.QUERY_DELETE_VIA_SERVER); query.setParameter("serverId", serverId); query.executeUpdate(); }
From source file:org.apache.falcon.state.store.jdbc.JDBCStateStore.java
@Override public void deleteExecutionInstance(InstanceID instanceID) throws StateStoreException { String instanceKey = instanceID.toString(); if (!executionInstanceExists(instanceID)) { throw new StateStoreException("Instance with key, " + instanceKey + " does not exist."); }//from w w w. ja va2 s . c om EntityManager entityManager = getEntityManager(); beginTransaction(entityManager); Query q = entityManager.createNamedQuery(PersistenceConstants.DELETE_INSTANCE); q.setParameter("id", instanceKey); q.executeUpdate(); commitAndCloseTransaction(entityManager); }
From source file:org.apache.falcon.state.store.jdbc.JDBCStateStore.java
@Override public void deleteEntity(EntityID entityID) throws StateStoreException { if (!entityExists(entityID)) { throw new StateStoreException("Entity with key, " + entityID.getKey() + " does not exist."); }// w w w . j a v a 2 s .c om EntityManager entityManager = getEntityManager(); beginTransaction(entityManager); Query q = entityManager.createNamedQuery(PersistenceConstants.DELETE_ENTITY); q.setParameter("id", entityID.getKey()); q.executeUpdate(); commitAndCloseTransaction(entityManager); }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaRiverDao.java
/** * @see {@link RiverDao#removeDrop(Long, Long)} *//*from w ww.j av a 2s. co m*/ public boolean removeDrop(Long id, Long dropId) { String sql = "DELETE FROM RiverDrop rd " + "WHERE rd.id = :dropId " + "AND rd.river.id = :riverId"; Query query = em.createQuery(sql); query.setParameter("riverId", id); query.setParameter("dropId", dropId); return query.executeUpdate() == 1; }
From source file:ca.uhn.fhir.jpa.dao.BaseHapiFhirSystemDao.java
private void markResourceAsIndexingFailed(final long theId) { TransactionTemplate txTemplate = new TransactionTemplate(myTxManager); txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW); txTemplate.execute(new TransactionCallback<Void>() { @Override//from w w w .ja va 2 s . com public Void doInTransaction(TransactionStatus theStatus) { ourLog.info("Marking resource with PID {} as indexing_failed", new Object[] { theId }); Query q = myEntityManager .createQuery("UPDATE ResourceTable t SET t.myIndexStatus = :status WHERE t.myId = :id"); q.setParameter("status", INDEX_STATUS_INDEXING_FAILED); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager.createQuery("DELETE FROM ResourceTag t WHERE t.myResourceId = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamCoords t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamDate t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamNumber t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager.createQuery( "DELETE FROM ResourceIndexedSearchParamQuantity t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamString t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamToken t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager .createQuery("DELETE FROM ResourceIndexedSearchParamUri t WHERE t.myResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager.createQuery("DELETE FROM ResourceLink t WHERE t.mySourceResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); q = myEntityManager.createQuery("DELETE FROM ResourceLink t WHERE t.myTargetResourcePid = :id"); q.setParameter("id", theId); q.executeUpdate(); return null; } }); }
From source file:org.apache.falcon.state.store.jdbc.JDBCStateStore.java
@Override public void deleteExecutionInstances(EntityID entityID) { String entityKey = entityID.getKey(); EntityManager entityManager = getEntityManager(); beginTransaction(entityManager);//from w ww .j av a 2s.c om Query q = entityManager.createNamedQuery(PersistenceConstants.DELETE_INSTANCE_FOR_ENTITY); q.setParameter("entityId", entityKey); q.executeUpdate(); commitAndCloseTransaction(entityManager); }
From source file:org.kuali.mobility.push.dao.DeviceDaoImpl.java
@Transactional public boolean removeAllDevicesByType(String type) { boolean result = true; List<Device> devices = this.findAllDevices(type); LOG.info("****** Found " + devices.size() + " Android devices to delete."); Query query = entityManager.createQuery("delete from Device where type = :type"); query.setParameter("type", type); result = (query.executeUpdate() > 0) ? true : false; LOG.info("****** Deleted " + result + " " + type + " devices."); return result; }
From source file:org.easyj.orm.jpa.SingleJPAEntityDao.java
@Override protected int executeUpdate(String query, Map<String, Object> params, QueryType queryType) { Query q; int result = -1; try {/*from w ww . j a v a 2 s.com*/ if (query.toLowerCase().startsWith("update ") || query.toLowerCase().startsWith("insert into") || query.toLowerCase().startsWith("delete from ")) { q = getEm().createNativeQuery(query); } else { q = getEm().createNamedQuery(query); } if (setParameters(q, params)) { result = q.executeUpdate(); } } finally { closeEm(); } return result; }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAAlbum.java
@Override @Transactional//from ww w .jav a 2 s .c o m public void setNullGenre(MDOGenre genre) { // ((a.owner.login = :userName) AND ( Query query = entityManager.createQuery( "UPDATE MDOAlbum a set a.genre = null WHERE a.owner.sid= :userSid AND a.genre.sid = :genreSid"); // query.setParameter( "userName", genre.getOwner().getLogin() ); query.setParameter("genreSid", genre.getSid()); query.setParameter("userSid", genre.getOwner().getSid()); query.executeUpdate(); }