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:it.geosolutions.geofence.core.dao.impl.RuleDAOImpl.java

@Override
public int shift(long priorityStart, long offset) {
    if (offset <= 0) {
        throw new IllegalArgumentException("Positive offset required");
    }/*  w  w w.ja v  a 2 s. c om*/

    Search search = new Search(Rule.class);
    search.addFilterGreaterOrEqual("priority", priorityStart);
    search.addFilterLessThan("priority", priorityStart + offset);
    if (super.count(search) == 0) {
        return -1;
    }

    String hql = "UPDATE Rule SET priority=priority+ :offset WHERE priority >= :priorityStart";

    Query query = em().createQuery(hql);
    query.setParameter("offset", offset);
    query.setParameter("priorityStart", priorityStart);

    return query.executeUpdate();
}

From source file:org.apereo.portal.portlet.dao.jpa.JpaMarketplaceRatingDao.java

@Override
@PortalTransactional/*from   ww  w.jav  a2  s  .c om*/
public void clearRatingsForPortlet(IPortletDefinition portletDefinition) {
    Validate.notNull(portletDefinition, "portletDefinition can not be null");
    final EntityManager em = getEntityManager();
    final Query query = em.createQuery(CLEAR_RATINGS_JPQL);
    query.setParameter("portletDefinition", portletDefinition);
    final int deleteCount = query.executeUpdate();
    logger.info("Cleared {} ratings from portlet {}", deleteCount, portletDefinition.getFName());
}

From source file:com.epam.ipodromproject.repository.jpa.JPAUserRepository.java

@Override
public void cancelBetsByCompetition(Long competitionID) {
    Query queryForUsers = entityManager.createNamedQuery("User.findMoneyBetByUsersByCompetition");
    queryForUsers.setParameter("competitionID", competitionID);
    queryForUsers.setParameter("betResult", BetResult.NOT_CONSIDERED);
    List<Object> result = queryForUsers.getResultList();
    Query query = entityManager.createNamedQuery("Person.returnMoneyToPerson");
    for (Object objects : result) {
        Object[] resultRow = (Object[]) objects;
        query.setParameter("id", (Long) resultRow[0]);
        query.setParameter("moneyReturned", (Double) resultRow[1]);
        query.executeUpdate();
    }//from  w  w w  . java2s.  c  o m

}

From source file:org.medici.bia.dao.usermessage.UserMessageDAOJpaImpl.java

/**
 * {@inheritDoc}/*from  ww w .j a va  2  s .com*/
 */
@Override
public Integer removeApprovationMessages(User user) throws PersistenceException {
    String queryString = new String("DELETE FROM UserMessage WHERE sender LIKE :account");

    Query query = getEntityManager().createQuery(queryString);
    query.setParameter("account", user.getAccount());

    return query.executeUpdate();
}

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

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

    /*//w  w  w .  ja va2 s .  c  om
     * this is informational debugging only - do NOT change the status bits here
     */
    if (log.isDebugEnabled()) {
        MeasurementBaseline baseline = entityManager.find(MeasurementBaseline.class, baselineId);
        Agent agent = baseline.getSchedule().getResource().getAgent();
        log.debug("Marking status, agent[id=" + agent.getId() + ", status=" + agent.getStatus()
                + "] for measurementBaseline[id=" + baselineId + "]");
    }
}

From source file:org.medici.bia.dao.usermessage.UserMessageDAOJpaImpl.java

/**
 * {@inheritDoc}//from  ww  w.ja  v  a 2  s . c o  m
 */
@Override
public Integer removeUnlockedMessages(User user) throws PersistenceException {
    String queryString = new String("DELETE FROM UserMessage WHERE sender LIKE :account AND messageSubject = '"
            + ApplicationPropertyManager.getApplicationProperty("message.lockedUser.subject",
                    new String[] { user.getAccount() }, "{", "}")
            + "'");

    Query query = getEntityManager().createQuery(queryString);
    query.setParameter("account", user.getAccount());

    return query.executeUpdate();
}

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

/**
 * Create other name for the specified account
 * @param orcid/*from w w  w  .ja v a  2s.  co  m*/
 * @param displayName
 * @return
 *          true if the other name was successfully created, false otherwise 
 * */
@Override
@Transactional
public boolean addOtherName(String orcid, String displayName) {
    Query query = entityManager.createNativeQuery(
            "INSERT INTO other_name (other_name_id, date_created, last_modified, display_name, orcid) VALUES (nextval('other_name_seq'), now(), now(), :displayName, :orcid)");
    query.setParameter("orcid", orcid);
    query.setParameter("displayName", displayName);
    return query.executeUpdate() > 0 ? true : false;
}

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

@Override
@Transactional/*www  .j  a  va  2s.  com*/
public boolean updateKeywordsVisibility(String orcid, Visibility visibility) {
    Query query = entityManager.createNativeQuery(
            "update profile set last_modified=now(), keywords_visibility=:keywords_visibility, indexing_status='PENDING' where orcid=:orcid");
    query.setParameter("keywords_visibility", StringUtils.upperCase(visibility.value()));
    query.setParameter("orcid", orcid);
    boolean result = query.executeUpdate() > 0 ? true : false;
    return result;
}

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

public boolean closePoll(Long room_id) {
    try {/* w  ww .  j  ava2s .  c o m*/
        log.debug(" :: closePoll :: ");
        Query q = em.createQuery(
                "UPDATE RoomPoll rp SET rp.archived = :archived WHERE rp.room.rooms_id = :rooms_id");
        q.setParameter("rooms_id", room_id);
        q.setParameter("archived", true);
        return q.executeUpdate() > 0;
    } catch (Exception err) {
        log.error("[closePoll]", err);
    }
    return false;
}

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

@Override
@ExcludeFromProfileLastModifiedUpdate// ww w .  ja  va  2s.  co m
public void removeByRefreshTokenValue(String refreshTokenValue) {
    Query query = entityManager
            .createQuery("delete from OrcidOauth2TokenDetail where refreshTokenValue = " + ":refreshToken");
    query.setParameter("refreshToken", refreshTokenValue);
    int i = query.executeUpdate();
    if (i == 0) {
        LOGGER.info("Attempted to delete refresh token {0} but it was not present in the database",
                refreshTokenValue);
    }
}