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.rhq.enterprise.server.measurement.AvailabilityManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void updateLastAvailabilityReport(int agentId) {
    // should we catch exceptions here, or allow them to bubble up and be caught?

    /*/*  w  ww.  java 2  s  . co m*/
     * since we already know we have to update the agent row with the last avail report time, might as well
     * set the backfilled to false here (as opposed to called agentManager.setBackfilled(agentId, false)
     */
    String updateStatement = "" //
            + "UPDATE Agent " //
            + "   SET lastAvailabilityReport = :reportTime, backFilled = FALSE " //
            + " WHERE id = :agentId ";

    Query query = entityManager.createQuery(updateStatement);
    query.setParameter("reportTime", System.currentTimeMillis());
    query.setParameter("agentId", agentId);

    query.executeUpdate();
}

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

@Override
@Transactional//w  w  w  . ja  va  2s  .  co  m
public boolean deprecateProfile(String deprecatedOrcid, String primaryOrcid) {
    Query query = entityManager.createNativeQuery(
            "update profile set last_modified=now(), indexing_status='PENDING', primary_record=:primary_record, deprecated_date=now() where orcid=:orcid");
    query.setParameter("orcid", deprecatedOrcid);
    query.setParameter("primary_record", primaryOrcid);

    boolean result = query.executeUpdate() > 0 ? true : false;

    return result;
}

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

@Override
@Transactional/* w w  w . j a  v a 2  s . c o  m*/
public void updateLastModifiedDateAndIndexingStatusWithoutResult(String orcid, Date lastModified,
        IndexingStatus indexingStatus) {
    Query query = entityManager.createNativeQuery(
            "update profile set last_modified = :lastModified, indexing_status = :indexingStatus where orcid = :orcid ");
    query.setParameter("orcid", orcid);
    query.setParameter("lastModified", lastModified);
    query.setParameter("indexingStatus", indexingStatus.name());
    query.executeUpdate();
}

From source file:org.eclipse.smila.connectivity.deltaindexing.jpa.impl.DeltaIndexingManagerImpl.java

/**
 * {@inheritDoc}//from  w  w w  . java  2s. co  m
 * 
 * @see org.eclipse.smila.connectivity.deltaindexing.DeltaIndexingManager#unlockDatasource(String)
 */
@Override
public void unlockDatasource(final String dataSourceID) throws DeltaIndexingException {
    _lock.readLock().lock();
    try {
        final EntityManager em = createEntityManager();
        final EntityTransaction transaction = em.getTransaction();
        try {
            transaction.begin();
            final Query query = em.createNamedQuery(DataSourceDao.NAMED_QUERY_KILL_SESSION);
            query.setParameter(DeltaIndexingDao.NAMED_QUERY_PARAM_SOURCE, dataSourceID);
            query.executeUpdate();
            transaction.commit();
            if (_log.isInfoEnabled()) {
                _log.info("removed delta indexing sessions and unlocked data source " + dataSourceID);
            }
        } catch (final Exception e) {
            if (transaction.isActive()) {
                transaction.rollback();
            }
            throw new DeltaIndexingException("error unlocking delta indexing data source " + dataSourceID, e);
        } finally {
            closeEntityManager(em);
        }
    } finally {
        _lock.readLock().unlock();
    }
}

From source file:org.rhq.enterprise.server.measurement.AvailabilityManagerBean.java

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@TransactionTimeout(6 * 60 * 60)/*w w  w.  j  av  a2  s. c o  m*/
public int purgeAvailabilities(long oldest) {
    try {
        Query purgeQuery = entityManager.createNativeQuery(Availability.NATIVE_QUERY_PURGE);
        purgeQuery.setParameter(1, oldest);
        long startTime = System.currentTimeMillis();
        int deleted = purgeQuery.executeUpdate();
        MeasurementMonitor.getMBean().incrementPurgeTime(System.currentTimeMillis() - startTime);
        MeasurementMonitor.getMBean().setPurgedAvailabilities(deleted);
        return deleted;
    } catch (Exception e) {
        throw new RuntimeException("Failed to purge availabilities older than [" + oldest + "]", e);
    }
}

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

@Override
@Transactional/*  w w  w  .  j a  v a  2 s.c  o m*/
public boolean updateResearcherUrlsVisibility(String orcid, Visibility visibility) {
    Query query = entityManager.createNativeQuery(
            "update profile set last_modified=now(), researcher_urls_visibility=:researcher_urls_visibility, indexing_status='PENDING' where orcid=:orcid");
    query.setParameter("researcher_urls_visibility", StringUtils.upperCase(visibility.value()));
    query.setParameter("orcid", orcid);

    boolean result = query.executeUpdate() > 0 ? true : false;

    return result;
}

From source file:com.htm.db.DatabaseAccessProviderJPA.java

protected boolean executeUpdate(Query query) throws DatabaseException {

    try {/*from   w w w  . j  a  v  a 2 s . co  m*/
        /*
        * executeUpdate returns the number of tuples that were deleted. If
        * there was at least one tuple deleted return true
        */

        if (tx.isActive()) {
            return query.executeUpdate() > 0 ? true : false;
        } else {
            throw new DatabaseException(NO_ACTIVE_TX_ERROR);
        }
    } catch (Exception e) {
        throw new DatabaseException(e);
    }
}

From source file:portal.api.impl.PortalJpaController.java

public void deleteAllUsers() {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();//from   ww  w  .j  a v  a2s.  co  m

    Query q = entityManager.createQuery("DELETE FROM PortalUser ");
    q.executeUpdate();
    entityManager.flush();

    entityTransaction.commit();

}

From source file:portal.api.impl.PortalJpaController.java

public void deleteAllInstalledVxFs() {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();/* w ww . j  a va 2  s. c o  m*/

    Query q = entityManager.createQuery("DELETE FROM InstalledVxF ");
    q.executeUpdate();
    entityManager.flush();

    entityTransaction.commit();
}

From source file:portal.api.impl.PortalJpaController.java

public void deleteAllMANOplatforms() {
    EntityManager entityManager = entityManagerFactory.createEntityManager();

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();//from  w w  w.  j  a  v a 2  s . c  o m

    Query q = entityManager.createQuery("DELETE FROM MANOplatform");
    q.executeUpdate();
    entityManager.flush();

    entityTransaction.commit();

}