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:es.ucm.fdi.dalgs.course.repository.CourseRepository.java

public boolean deleteCourses(Collection<AcademicTerm> academicList) {

    try {//from  www.  j a v a2 s  .  co m
        Query query = em.createQuery("UPDATE Course c SET c.isDeleted = true WHERE c.academicTerm in ?1");
        query.setParameter(1, academicList);
        int n = query.executeUpdate();
        if (n > 0)
            return true;
        else
            return false;

    } catch (Exception e) {
        logger.error(e.getMessage());
        return false;
    }

}

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

/**
 * @see org.wso2.carbon.bpel.b4p.coordination.dao.HTCoordinationDAOConnection#deleteTaskData(String)
 *//*  w  ww .j  a va2  s  .co m*/
@Override
public boolean deleteTaskData(String taskID) {
    Query q = entityManager
            .createQuery("DELETE FROM org.wso2.carbon.bpel.b4p.coordination.dao.jpa.openjpa.entity"
                    + ".HTProtocolHandler t WHERE t.taskID = :taskID");
    q.setParameter("taskID", taskID);
    return q.executeUpdate() == 1;
}

From source file:cn.guoyukun.spring.jpa.repository.RepositoryHelper.java

/**
 * <p>??. insert, update, delete .<br/>
 * ?{@see cn.guoyukun.spring.jpa.repository.UserRepository2ImplIT#testBatchUpdate()}
 *
 * @param ql/*from   w w w .j a v  a 2  s . c  o m*/
 * @param params
 * @return
 */
public int batchUpdate(final String ql, final Object... params) {

    Query query = getEntityManager().createQuery(ql);
    setParameters(query, params);

    return query.executeUpdate();
}

From source file:net.awired.generic.jpa.dao.impl.GenericDaoImpl.java

@Transactional(propagation = Propagation.REQUIRED)
protected void update(Query query) {
    query.executeUpdate();
}

From source file:be.fedict.trust.service.dao.bean.CertificateAuthorityDAOBean.java

public int removeRevokedCertificates(String issuerName) {
    LOG.debug("deleting revoked certificates (issuer=" + issuerName + ")");

    Query query = this.entityManager.createNamedQuery(RevokedCertificateEntity.DELETE_WHERE_ISSUER);
    query.setParameter("issuer", issuerName);
    int deleteResult = query.executeUpdate();
    LOG.debug("delete result: " + deleteResult);
    return deleteResult;
}

From source file:be.fedict.trust.service.dao.bean.CertificateAuthorityDAOBean.java

public void removeCertificateAuthorities(TrustPointEntity trustPoint) {
    LOG.debug("remove CA's for trust point " + trustPoint.getName());
    Query query = this.entityManager.createNamedQuery(CertificateAuthorityEntity.DELETE_WHERE_TRUST_POINT);
    query.setParameter("trustPoint", trustPoint);
    int result = query.executeUpdate();
    LOG.debug("CA's removed: " + result);
}

From source file:org.rhq.enterprise.server.cloud.StatusManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void updateByAgent(int agentId) {
    log.debug("About to mark status by agent");
    Query updateAgentQuery = entityManager.createNamedQuery(Agent.QUERY_UPDATE_STATUS_BY_AGENT);
    updateAgentQuery.setParameter("agentId", agentId);
    updateAgentQuery.executeUpdate();

    /*//w  ww.j ava  2 s  .c om
     * this is informational debugging only - do NOT change the status bits here
     */
    if (log.isDebugEnabled()) {
        Agent agent = entityManager.find(Agent.class, agentId);
        log.debug("Marking status, agent[id=" + agent.getId() + ", status=" + agent.getStatus() + "]");
    }
}

From source file:es.ucm.fdi.dalgs.activity.repository.ActivityRepository.java

public boolean deleteActivitiesFromGroup(Group group) {
    try {//from  w  w w .j  a  va 2 s  .  co  m
        Query query = em.createQuery("UPDATE Activity a SET a.isDeleted = true where a.group = ?1");

        query.setParameter(1, group);
        query.executeUpdate();

    } catch (Exception e) {
        logger.error(e.getMessage());

        return false;
    }
    return true;
}

From source file:com.haulmont.cuba.core.jmx.PersistenceManager.java

@Authenticated
@Override//from w w w.jav a 2s.co m
public String jpqlExecuteUpdate(String queryString, boolean softDeletion) {
    try {
        Transaction tx = persistence.createTransaction();
        try {
            EntityManager em = persistence.getEntityManager();
            em.setSoftDeletion(softDeletion);
            Query query = em.createQuery(queryString);
            int count = query.executeUpdate();
            tx.commit();

            return "Done: " + count + " entities affected, softDeletion=" + softDeletion;
        } finally {
            tx.end();
        }
    } catch (Throwable e) {
        log.error("jpqlExecuteUpdate error", e);
        return ExceptionUtils.getStackTrace(e);
    }
}

From source file:es.ucm.fdi.dalgs.activity.repository.ActivityRepository.java

public boolean deleteActivitiesFromCourse(Course course) {

    try {//from  w ww .  java 2  s.  c o  m
        Query query = em.createQuery("UPDATE Activity a SET a.isDeleted = true where a.course = ?1");

        query.setParameter(1, course);
        query.executeUpdate();

    } catch (Exception e) {
        logger.error(e.getMessage());

        return false;
    }
    return true;
}