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.bitsofinfo.util.address.usps.ais.store.jpa.JPAStore.java

@Override
@Transactional(propagation = Propagation.REQUIRED)
public void deleteRecord(String identifier) throws StoreException {
    Class<? extends USPSRecord> clazz = getClassForIdentifier(identifier);

    try {/*www.j ava  2s  . c o m*/
        Query q = this.entityMgr
                .createQuery("delete from " + clazz.getSimpleName() + " o where o.identifier = :idval");
        q.setParameter("idval", identifier);
        int count = q.executeUpdate();

    } catch (Exception e) {
        throw new StoreException("Unexpected error in deleting the given record", e);
    }
}

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

@Override
@Transactional(propagation = Propagation.REQUIRED)
public void replace(long deletedOrgDisambiguatedId, long replacementOrgDisambiguatedId) {
    Query query = entityManager.createQuery(
            "update OrgEntity set orgDisambiguated.id = :replacementOrgDisambiguatedId where orgDisambiguated.id = :deletedOrgDisambiguatedId");
    query.setParameter("deletedOrgDisambiguatedId", deletedOrgDisambiguatedId);
    query.setParameter("replacementOrgDisambiguatedId", replacementOrgDisambiguatedId);
    query.executeUpdate();
}

From source file:org.oscarehr.common.dao.RemoteIntegratedDataCopyDao.java

public void archiveDataCopyExceptThisOne(RemoteIntegratedDataCopy remoteIntegratedDataCopy) {
    String sqlCommand = "Update RemoteIntegratedDataCopy x set x.archived = ?1 where x.id != ?2 and x.dataType = ?3 and x.facilityId = ?4 and x.demographicNo = ?5 ";

    Query query = entityManager.createQuery(sqlCommand);
    query.setParameter(1, Boolean.TRUE);
    query.setParameter(2, remoteIntegratedDataCopy.getId());
    query.setParameter(3, remoteIntegratedDataCopy.getDataType());
    query.setParameter(4, remoteIntegratedDataCopy.getFacilityId());
    query.setParameter(5, remoteIntegratedDataCopy.getDemographicNo());
    int i = query.executeUpdate();
    MiscUtils.getLogger().debug("i was " + i);
}

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

/**
 * Resets the OOB data for the passed schedule
 * @param subject Caller/*www  .ja va 2s.c  o m*/
 * @param sched the schedule for which we want to clean out the data
 */
public void removeOOBsForSchedule(Subject subject, MeasurementSchedule sched) {
    Query q = entityManager.createNamedQuery(MeasurementOOB.DELETE_FOR_SCHEDULE);
    q.setParameter("id", sched.getId());
    q.executeUpdate();
}

From source file:eu.planets_project.pp.plato.application.AdminAction.java

/**
 * Unlocks project with provided projectID.
 * @see #projectID/*w w  w .ja  va  2 s  . c  o  m*/
 */
public String unlockUsingProjectID() {
    Query q = em.createQuery("update PlanProperties pp set pp.openHandle = 0 where pp.id = " + projectID);
    if (q.executeUpdate() < 1) {
        FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR,
                "Unlocking project " + projectID + " failed.");
        log.info("Unlocking project " + projectID + " failed.");
    } else
        FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR, "Unlocked project " + this.projectID);
    log.info("Unlocked project " + projectID);
    return null;
}

From source file:org.kuali.mobility.push.dao.DeviceDaoImpl.java

@Transactional
public boolean removeAllDevices() {
    boolean result = true;
    List<Device> devices = this.findAllDevices();
    LOG.info("****** Found " + devices.size() + " devices to delete.");
    Query query = entityManager.createQuery("delete from Device");
    result = (query.executeUpdate() > 0) ? true : false;

    LOG.info("****** Deleted " + result + " devices.");
    return result;
}

From source file:org.apache.falcon.state.store.jdbc.JDBCStateStore.java

@Override
public void deleteEntities() throws StateStoreException {
    if (!isModeDebug()) {
        throw new UnsupportedOperationException("Delete Entities Table not supported");
    }//  w w w.  j  av  a2 s. c om
    EntityManager entityManager = getEntityManager();
    beginTransaction(entityManager);
    Query q = entityManager.createNamedQuery(PersistenceConstants.DELETE_ENTITIES);
    q.executeUpdate();
    commitAndCloseTransaction(entityManager);
}

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

/**
 * Remove OOBs for schedules that had their baselines calculated after
 * a certain cutoff point. This is used to get rid of outdated OOB data for
 * baselines that got recalculated, as the new baselines will be 'big' enough for
 * what have been OOBs before and we don't have any baseline history.
 * @param subject The caller/* ww w  .  j a  v a2s . com*/
 * @param cutoffTime The reference time to determine new baselines
 */
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public void removeOutdatedOOBs(Subject subject, long cutoffTime) {

    Query q = entityManager.createNamedQuery(MeasurementOOB.DELETE_OUTDATED);
    q.setParameter("cutOff", cutoffTime);
    int count = q.executeUpdate();
    log.info("Removed [" + count + "] outdated OOBs");
}

From source file:ca.uhn.fhir.jpa.dao.FhirResourceDaoSubscriptionDstu2.java

@Override
protected ResourceTable updateEntity(IBaseResource theResource, ResourceTable theEntity,
        Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion,
        Date theUpdateTime) {//from www.j a va 2 s. co  m
    ResourceTable retVal = super.updateEntity(theResource, theEntity, theDeletedTimestampOrNull,
            thePerformIndexing, theUpdateVersion, theUpdateTime);

    Subscription resource = (Subscription) theResource;
    Long resourceId = theEntity.getId();
    if (theDeletedTimestampOrNull != null) {
        Long subscriptionId = getSubscriptionTablePidForSubscriptionResource(theEntity.getIdDt());
        if (subscriptionId != null) {
            mySubscriptionFlaggedResourceDataDao.deleteAllForSubscription(subscriptionId);
            mySubscriptionTableDao.deleteAllForSubscription(subscriptionId);
        }
    } else {
        Query q = myEntityManager.createNamedQuery("Q_HFJ_SUBSCRIPTION_SET_STATUS");
        q.setParameter("res_id", resourceId);
        q.setParameter("status", resource.getStatusElement().getValue());
        if (q.executeUpdate() > 0) {
            ourLog.info("Updated subscription status for subscription {} to {}", resourceId,
                    resource.getStatusElement().getValueAsEnum());
        } else {
            createSubscriptionTable(retVal, resource);
        }
    }
    return retVal;
}

From source file:com.mothsoft.alexis.engine.numeric.President2012DataSetImporter.java

private void deletePoints(final Date after) {
    this.transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override//from   ww w.j a  v  a  2  s  . c o  m
        protected void doInTransactionWithoutResult(final TransactionStatus txStatus) {
            final Set<DataSet> dataSets = new HashSet<DataSet>();

            for (final String choice : CANDIDATE_OPTIONS) {
                final DataSet dataSet = findOrCreateDataSet(choice);
                dataSets.add(dataSet);
            }

            final String queryString = "DELETE FROM DataSetPoint p WHERE p.dataSet IN :dataSets AND p.x >= :after";
            final Query query = President2012DataSetImporter.this.em.createQuery(queryString);
            query.setParameter("dataSets", dataSets);
            query.setParameter("after", after);
            final int affected = query.executeUpdate();
            logger.info("Affected " + affected + " rows");
        }
    });
}