Example usage for javax.persistence Query executeUpdate

List of usage examples for javax.persistence Query executeUpdate

Introduction

In this page you can find the example usage for javax.persistence Query executeUpdate.

Prototype

int executeUpdate();

Source Link

Document

Execute an update or delete statement.

Usage

From source file:org.wso2.carbon.bpel.b4p.coordination.dao.jpa.hibernate.HTCoordinationDAOConnectionImpl.java

/**
 * @see org.wso2.carbon.bpel.b4p.coordination.dao.HTCoordinationDAOConnection#deleteCoordinationData(String)
 *///from  w w w  .ja  v a  2 s .  c o m
@Override
public boolean deleteCoordinationData(String processInstanceID) {
    Query q = entityManager
            .createQuery("DELETE FROM org.wso2.carbon.bpel.b4p.coordination.dao.jpa.openjpa.entity"
                    + ".HTProtocolHandler t WHERE t.processInstanceID = :processInstanceID");
    q.setParameter("processInstanceID", processInstanceID);
    return q.executeUpdate() == 1;
}

From source file:org.springframework.integration.jpa.core.DefaultJpaOperations.java

@Override
public int executeUpdate(String updateQuery, ParameterSource source) {
    Query query = entityManager.createQuery(updateQuery);
    setParametersIfRequired(updateQuery, source, query);
    return query.executeUpdate();
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.OfferBidRepositoryImplementation.java

@Override
public boolean deleteAllBidsForVacancy(Vacancy vacancy) {
    EntityManager em = entityManagerFactory.createEntityManager();
    boolean success = true;
    try {/* www  . j  a v a2 s .c  o m*/
        em.getTransaction().begin();
        Query query = em.createNamedQuery("OfferBid.deleteByVacancy");
        query.setParameter("vacancy", vacancy);
        query.executeUpdate();
        em.getTransaction().commit();

        success = true;
    } catch (RuntimeException e) {
        Logger.getLogger(OfferBidRepositoryImplementation.class.getName()).info(e);
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
            success = false;
        }
        em.close();
    }

    return success;
}

From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.SecurityGroupDaoJpaImpl.java

public SecurityGroup updateSecurityGroupId(String idSecurityGroup, SecurityGroup securityGroup)
        throws InvalidEntityException {
    Query query = getEntityManager().createQuery("UPDATE SecurityGroup sg "
            + "SET sg.idSecurityGroup= :idSecurityGroup" + "  where sg.name = :name");
    query.setParameter("idSecurityGroup", idSecurityGroup);
    query.setParameter("name", securityGroup.getName());
    SecurityGroup secGroup = null;//  www .ja va  2  s.c  o m
    try {
        query.executeUpdate();
        secGroup = load(securityGroup.getName());
    } catch (NoResultException e) {
        throw new InvalidEntityException(securityGroup);
    } catch (EntityNotFoundException e) {
        throw new InvalidEntityException(securityGroup);
    }
    return secGroup;
}

From source file:org.openmeetings.app.data.user.dao.UserContactsDaoImpl.java

public Integer deleteUserContact(Long userContactDeleteId) {
    try {/*from w ww  .ja  v a2s . c o m*/

        String hql = "delete from UserContacts u where u.userContactId = :userContactDeleteId";

        Query query = em.createQuery(hql);
        query.setParameter("userContactDeleteId", userContactDeleteId);
        int rowCount = query.executeUpdate();

        return rowCount;
    } catch (Exception e) {
        log.error("[deleteUserContact]", e);
    }
    return null;
}

From source file:com.epam.training.taranovski.web.project.repository.implementation.OfferBidRepositoryImplementation.java

@Override
public boolean deleteAllOffersForEmployee(Employee employee) {
    EntityManager em = entityManagerFactory.createEntityManager();
    boolean success = true;
    try {/*from  w w  w . ja  v  a 2 s . c om*/
        em.getTransaction().begin();
        Query query = em.createNamedQuery("OfferBid.deleteByEmployee");
        query.setParameter("employee", employee);
        query.executeUpdate();
        em.getTransaction().commit();

        success = true;
    } catch (RuntimeException e) {
        Logger.getLogger(OfferBidRepositoryImplementation.class.getName()).info(e);
    } finally {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
            success = false;
        }
        em.close();
    }

    return success;
}

From source file:com.katsu.jpa.dao.JpaDao.java

@Override
@Transactional//from  www  . j  a  v a  2s. c  o m
public void updateId(T o, ID id) {
    Query q = em.createQuery(getDAOReflection().getUpdateIdQuery());
    q.setParameter(OLD, (ID) getDAOReflection().getId(o));
    q.setParameter(C_NEW, id);
    q.executeUpdate();
    getDAOReflection().setId(o, id);
}

From source file:org.springframework.integration.jpa.core.DefaultJpaOperations.java

@Override
public int executeUpdateWithNamedQuery(String updateQuery, ParameterSource source) {
    Query query = entityManager.createNamedQuery(updateQuery);
    setParametersIfRequired(updateQuery, source, query);
    return query.executeUpdate();
}

From source file:test.unit.be.fedict.trust.service.PersistenceTest.java

@Test
public void testFindRevokedCertificate() throws Exception {
    // setup/* w  w w  .ja va2  s  .c o m*/
    String issuerName = "CN=Test CA";
    BigInteger serialNumber = new BigInteger("21267647932558966653497436382356969621");
    BigInteger crlNumber = new BigInteger("123465789");
    RevokedCertificateEntity revokedCertificateEntity = new RevokedCertificateEntity(issuerName, serialNumber,
            new Date(), crlNumber);
    this.entityManager.persist(revokedCertificateEntity);

    refresh();

    // operate
    Query query = this.entityManager.createNamedQuery(RevokedCertificateEntity.QUERY_WHERE_ISSUER_SERIAL);
    query.setParameter("issuer", issuerName);
    query.setParameter("serialNumber", serialNumber.toString());
    RevokedCertificateEntity resultRevokedCertificate = (RevokedCertificateEntity) query.getSingleResult();

    // verify
    assertNotNull(resultRevokedCertificate);
    assertEquals(resultRevokedCertificate.getPk().getIssuer(), issuerName);
    assertEquals(resultRevokedCertificate.getPk().getSerialNumber(), serialNumber.toString());
    assertEquals(resultRevokedCertificate.getCrlNumber(), crlNumber);

    refresh();

    Query deleteQuery = this.entityManager
            .createNamedQuery(RevokedCertificateEntity.DELETE_WHERE_ISSUER_OLDER_CRL_NUMBER);
    deleteQuery.setParameter("issuer", issuerName);
    deleteQuery.setParameter("crlNumber", crlNumber);
    int zeroDeleteResult = deleteQuery.executeUpdate();
    assertEquals(0, zeroDeleteResult);

    refresh();

    deleteQuery.setParameter("crlNumber", crlNumber.add(new BigInteger("1")));
    int deleteResult = deleteQuery.executeUpdate();
    assertEquals(1, deleteResult);
}

From source file:eu.planets_project.tb.impl.persistency.ExperimentPersistencyImpl.java

public void removeMeasurement(MeasurementImpl m) {
    log.info("Removing measurement " + m.getId());
    if (m.getId() == -1)
        return;//  w  w w.  j  a  va2 s  . c  om
    // This never seems to work, no matter what I do. Not clear why. Cascade issues?
    //manager.remove( m );
    // So, instead, manually clip it out:
    Query query = manager.createNativeQuery("DELETE FROM MeasurementImpl WHERE id=:id");
    query.setParameter("id", m.getId());
    query.executeUpdate();
}