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:eu.forgestore.ws.impl.FStoreJpaController.java

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

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();/*from   w w  w .  j av a 2  s  .  c  om*/

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

    entityTransaction.commit();

}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

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

    EntityTransaction entityTransaction = entityManager.getTransaction();

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

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

    entityTransaction.commit();

}

From source file:org.asqatasun.entity.dao.audit.ContentDAOImpl.java

@Override
public void deleteContentRelationShip(Long relatedContentId) {
    Query query = entityManager.createNativeQuery(DELETE_CONTENT_RELATIONSHIP_QUERY);
    query.setParameter("idContentChild", relatedContentId);
    try {/*from   w  ww  . java 2 s  . c  o  m*/
        query.executeUpdate();
    } catch (NoResultException nre) {
        // do nothing
    }
}

From source file:pl.datamatica.traccar.api.providers.UserProvider.java

public void forceRemoveUser(User user) throws Exception {
    String removedLogin = user.getLogin();

    removeUserSettings(user);/*  w w  w .  j  a  v a  2  s  .c o m*/
    removeUserResources(user);

    Long userSettingsId = user.getUserSettings() != null ? user.getUserSettings().getId() : null;
    Query query = em.createQuery("DELETE FROM User WHERE id = ?");
    query.setParameter(1, user.getId());
    query.executeUpdate();

    if (user.getUserSettings() != null) {
        query = em.createQuery("DELETE FROM UserSettings WHERE id = ?");
        query.setParameter(1, userSettingsId.longValue());
        query.executeUpdate();
    }
    generateAuditLogForCreateRemoveUser(removedLogin, true);
    logger.info("{} removed {} account", requestUser.getLogin(), removedLogin);

    em.flush();
}

From source file:eu.forgestore.ws.impl.FStoreJpaController.java

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

    EntityTransaction entityTransaction = entityManager.getTransaction();

    entityTransaction.begin();/*from   w ww.j  ava2  s . com*/

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

    entityTransaction.commit();

}

From source file:org.kuali.continuity.admin.dao.jpa.UserLoginDAOImpl.java

@Override
public void changePassword(final int userId, final String password, boolean setModApprovedFlag) {
    // get hash//w ww .  j a  v  a2  s .  co m
    final String passwordHash = this.getCaseInsensitivePasswordHash(password);

    // query
    Query query = null;
    if (setModApprovedFlag) {
        query = this.getEntityManager().createNativeQuery(APPROVE_USER_QUERY);
    } else {
        query = this.getEntityManager().createNativeQuery(APPROVE_USER_QUERY_NO_APPROVED);
    }

    query.setParameter("password", passwordHash);
    query.setParameter("userId", userId);

    if (setModApprovedFlag) {
        query.setParameter("isApproved", '1');
    }

    // update
    query.executeUpdate();
}

From source file:org.asqatasun.entity.dao.audit.ContentDAOImpl.java

/**
 *
 * @param idContent/*from ww w .jav  a 2 s.com*/
 * @param idAudit
 */
@Override
public void saveAuditToContent(Long idContent, Long idAudit) {
    if (idContent != null && idAudit != null) {
        Query query = entityManager.createNativeQuery(UPDATE_QUERY);
        query.setParameter("idContent", idContent);
        query.setParameter("idAudit", idAudit);
        query.executeUpdate();
        flushAndCloseEntityManager();
    }
}

From source file:org.broadleafcommerce.core.order.dao.OrderDaoImpl.java

@Override
public boolean releaseLock(final Order order) {
    final boolean[] response = { false };
    try {//  ww w  . j  a  v  a2 s . co m
        transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
            @Override
            public void execute() throws Throwable {
                Query q = em.createNamedQuery("BC_ORDER_LOCK_RELEASE");
                q.setParameter("orderId", order.getId());
                q.setParameter("key", getOrderLockKey());
                q.setHint(QueryHints.HINT_CACHEABLE, false);
                int rowsAffected = q.executeUpdate();
                response[0] = rowsAffected == 1;
            }

            @Override
            public boolean shouldRetryOnTransactionLockAcquisitionFailure() {
                return true;
            }
        }, RuntimeException.class);
    } catch (RuntimeException e) {
        LOG.error(String.format("Could not release order lock (%s)", order.getId()), e);
    }
    return response[0];
}

From source file:org.apache.syncope.core.util.ImportExport.java

@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes atts)
        throws SAXException {

    // skip root element
    if (ROOT_ELEMENT.equals(qName)) {
        return;/*w  w  w . j  a v  a  2 s. co m*/
    }

    StringBuilder queryString = new StringBuilder("INSERT INTO ").append(qName).append('(');

    StringBuilder values = new StringBuilder();

    for (int i = 0; i < atts.getLength(); i++) {
        queryString.append(atts.getQName(i));
        values.append('?');
        if (i < atts.getLength() - 1) {
            queryString.append(',');
            values.append(',');
        }
    }
    queryString.append(") VALUES (").append(values).append(')');

    Query query = entityManager.createNativeQuery(queryString.toString());
    setParameters(qName, atts, query);

    query.executeUpdate();
}

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

public void markStaleServersDown(Subject subject) {
    if (!authorizationManager.isOverlord(subject)) {
        throw new IllegalArgumentException("The markStaleServersDown method must be called by the overlord");
    }/*from ww  w. j av  a 2  s. co m*/

    long staleTime = System.currentTimeMillis() - SERVER_DOWN_INTERVAL;

    String serverName = null;
    try {
        serverName = serverManager.getIdentity();
        if (log.isDebugEnabled()) {
            log.debug(serverName + " is marking stale servers DOWN");
        }
    } catch (Exception e) {
        log.error("Could not determine which instance is marking stale servers DOWN");
    }
    Query query = entityManager.createNamedQuery(Server.QUERY_UPDATE_SET_STALE_DOWN);
    query.setParameter("downMode", Server.OperationMode.DOWN);
    query.setParameter("normalMode", Server.OperationMode.NORMAL);
    query.setParameter("staleTime", staleTime);
    query.setParameter("thisServerName", serverName); // might be null
    int resultCount = query.executeUpdate();

    if (log.isDebugEnabled()) {
        log.debug(String.valueOf(resultCount) + " stale servers were marked DOWN");
    }

    // Perform requested partition events. Note that we only need to execute one cloud partition
    // regardless of the number of pending requests, as the work would be duplicated.
    partitionEventManager.processRequestedPartitionEvents();
}