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.competence.repository.CompetenceRepository.java

public boolean deleteCompetencesForDegree(Degree degree) {

    try {//  w  w w.  ja v  a 2  s  . c o m
        Query query = em.createQuery("UPDATE Competence c SET c.isDeleted = true where c.degree=?1");

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

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

From source file:org.orcid.persistence.dao.impl.OrgDisambiguatedDaoImpl.java

@Override
@Transactional//from  w  w  w. j a va  2 s .c  o  m
public void dropUniqueConstraint() {
    Query query = entityManager.createNativeQuery(
            "ALTER TABLE org_disambiguated DROP CONSTRAINT IF EXISTS org_disambiguated_unique_constraints");
    query.executeUpdate();
}

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

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void updateByAutoBaselineCalculationJob() {
    log.debug("About to mark status by autoBaselineCalculationJob");
    // baselines refer to measurement-based alert conditions, thus only agent statuses need to be set
    Query updateAgentQuery = entityManager.createNamedQuery(Agent.QUERY_UPDATE_STATUS_FOR_ALL);
    updateAgentQuery.executeUpdate();

    /*/*from  www  .  ja  v a 2  s.  c o  m*/
     * this is informational debugging only - do NOT change the status bits here
     */
    if (log.isDebugEnabled()) {
        List<Agent> agents = agentManager.getAllAgents();
        for (Agent agent : agents) {
            log.debug("Marking status, agent[id=" + agent.getId() + ", status=" + agent.getStatus()
                    + "] for AutoBaselineCalculationJob");
        }
    }
}

From source file:es.ucm.fdi.dalgs.topic.repository.TopicRepository.java

public boolean deleteTopicsForModules(Collection<Module> modules) {
    try {// www  . ja  v  a 2 s.  c o m

        Query query = em.createQuery("UPDATE Topic t SET t.isDeleted = true where t.module IN ?1");
        query.setParameter(1, modules);
        query.executeUpdate();
        return true;
    } catch (Exception e) {
        logger.error(e.getMessage());
        return false;
    }

}

From source file:nl.waisda.services.EuropeanaImportServiceTest.java

private void setup() {
    // NOTE: the rollback config is not needed as the service runs in a new transaction and therefor
    // is never rolled back unless an error occurs within the process
    transactionService.runInNewTransaction(new Callable<Void>() {
        @Override/*from w w  w.ja  va2  s .c o  m*/
        public Void call() throws Exception {
            Query query = entityManager.createQuery("delete from Video");
            query.executeUpdate();

            return null;
        }
    });
}

From source file:org.openmeetings.app.data.conference.PollManagement.java

public boolean deletePoll(Long poll_id) {
    try {/*from www  .  ja va2s .  co  m*/
        log.debug(" :: deletePoll :: ");
        Query q = em.createQuery("DELETE FROM RoomPoll rp WHERE rp.roomPollId = :roomPollId");
        q.setParameter("roomPollId", poll_id);
        return q.executeUpdate() > 0;
    } catch (Exception err) {
        log.error("[deletePoll]", err);
    }
    return false;
}

From source file:co.sip.dmesmobile.bs.ScStopDao.java

@Override
@Transactional// www  . j  av a2 s. c  o  m
public int solutionStopMachine(String duration, String responseDate, String idStopMachine, String idMaintenance,
        String idMachine) throws Exception {
    entityManager = Factory.getEntityManagerFactory().createEntityManager();
    entityManager.getTransaction().begin();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    String endDate = calendar.get(Calendar.DAY_OF_MONTH) + "/" + calendar.get(Calendar.MONTH + 1) + "/"
            + calendar.get(Calendar.YEAR) + " " + calendar.get(Calendar.HOUR_OF_DAY) + ":"
            + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND);
    int result = -1;
    String stringQuery = "UPDATE  dmes.sc_stop_machine  SET duration_real = " + duration
            + (!Utilities.isEmpty(idMaintenance) ? ", id_maintenance = " + idMaintenance + "" : " ")
            + ", response_date = TO_TIMESTAMP('" + responseDate + "','DD/MM/YYYY HH24:MI:SS'), state =  " + 3
            + ", end_date = TO_TIMESTAMP('" + endDate + "','DD/MM/YYYY HH24:MI:SS')"
            + " WHERE id_stop_machine = " + idStopMachine;
    try {
        Query query = entityManager.createNativeQuery(stringQuery);
        result = query.executeUpdate();

        if (!Utilities.isEmpty(idMaintenance)) {
            String queryMaintenance = "UPDATE dmes.ot_maintenance SET duration = " + duration
                    + ", id_maintenance_state = " + 2 + ", response_date = TO_TIMESTAMP('" + responseDate
                    + "','DD/MM/YYYY HH24:MI:SS') " + ", end_date = TO_TIMESTAMP('" + endDate
                    + "','DD/MM/YYYY HH24:MI:SS')" + "WHERE id_maintenance = " + idMaintenance;
            query = entityManager.createNativeQuery(queryMaintenance);
            query.executeUpdate();
        }
        String queryMachine = "UPDATE dmes.sc_machine SET id_state = " + 1 + " WHERE " + "id_machine = "
                + idMachine;
        query = entityManager.createNativeQuery(queryMachine);
        query.executeUpdate();
        entityManager.getTransaction().commit();
    } catch (Exception e) {
        log.error("Error intentando actualizar el paro de mquina", e);
        throw e;
    }
    return result;
}

From source file:org.apache.openmeetings.db.dao.user.PrivateMessageDao.java

public int updateReadStatus(Collection<Long> ids, Boolean isRead) {
    Query query = em.createNamedQuery("updatePrivateMessagesReadStatus");
    query.setParameter("isRead", isRead);
    query.setParameter("ids", ids);
    return query.executeUpdate();
}

From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaAccountDao.java

public boolean deleteFollower(Account account, Account follower) {
    String sql = "DELETE FROM AccountFollower " + "WHERE account = :account " + "AND follower = :follower";

    Query query = em.createQuery(sql);
    query.setParameter("account", account);
    query.setParameter("follower", follower);

    return query.executeUpdate() == 1;
}

From source file:org.cleverbus.core.common.dao.MessageOperationDaoJpaImpl.java

@Override
public boolean setPartlyFailedState(Message msg) {
    Assert.notNull(msg, "the msg must not be null");

    // change state to PARTLY_FAILED
    String jSql = "UPDATE " + Message.class.getName() + " SET state = ?1, lastUpdateTimestamp = ?2"
            + " WHERE msgId = ?3 AND state IN (?4)";

    Query q = em.createQuery(jSql);
    q.setParameter(1, MsgStateEnum.PARTLY_FAILED);
    q.setParameter(2, new Date());
    q.setParameter(3, msg.getMsgId());/*from   w  ww .ja v a2  s  . com*/
    q.setParameter(4, Arrays.asList(MsgStateEnum.CANCEL, MsgStateEnum.FAILED));

    return q.executeUpdate() > 0;
}