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.simbasecurity.core.domain.repository.SessionDatabaseRepository.java

public void removeAllBut(SSOToken ssoToken) {
    Query query = entityManager.createQuery("DELETE FROM SessionEntity s WHERE s.ssoToken != :ssoToken");
    query.setParameter("ssoToken", ssoToken.getToken());
    query.executeUpdate();
}

From source file:org.kuali.mobility.configparams.dao.ConfigParamDaoImpl.java

public void deleteConfigParamById(Long id) {
    Query query = entityManager.createQuery("delete from ConfigParam cp where cp.configParamId = :id");
    query.setParameter("id", id);
    query.executeUpdate();
}

From source file:bq.jpa.demo.version.service.VersionService.java

/**
 * batch way by query language cannot change version
 *///from w w w  .  j av  a  2 s  .  c o  m
@Transactional
public void doUpdateByQL() {
    Query update = em.createQuery("UPDATE jpa_version_employee e SET e.name= CONCAT('new',e.name)");
    update.executeUpdate();
}

From source file:ea.ejb.PostFacade.java

public void deletePost(BigDecimal id_post) {
    Query q;

    q = em.createQuery("DELETE FROM Post p WHERE p.idPost=:ID");
    q.setParameter("ID", id_post);

    q.executeUpdate();
}

From source file:org.eurekastreams.server.persistence.mappers.db.ReorderStreamsDbMapper.java

/**
 * Update the order of streams in the db.
 * /*  w ww. ja  v a  2 s.c o  m*/
 * @param userId
 *            The user id to find followed groups for.
 * @param streams
 *            The newly ordered list of streams.
 * @param newHiddenLineIndex
 *            the new hidden line index.
 */
public void execute(final long userId, final List<PersonStream> streams, final int newHiddenLineIndex) {
    // there's a constraint on the indexed column, so temporarily make all indexes available by going negative
    getEntityManager()
            .createQuery("UPDATE PersonStream SET streamIndex = -1 - streamIndex WHERE pk.personId = :personId")
            .setParameter("personId", userId).executeUpdate();

    // set the new order
    for (int streamIndex = 0; streamIndex < streams.size(); streamIndex++) {
        PersonStream ps = streams.get(streamIndex);
        log.info("Setting stream index to " + streamIndex + " for stream id #" + ps.getStreamId()
                + " for person #" + userId);

        // have to update in real time, rather than wait for flush - the constraints make this tough
        getEntityManager()
                .createQuery("UPDATE PersonStream SET streamIndex = :streamIndex "
                        + "WHERE pk.personId = :personId AND streamId = :streamId")
                .setParameter("streamIndex", streamIndex).setParameter("personId", ps.getPersonId())
                .setParameter("streamId", ps.getStreamId()).executeUpdate();
    }

    // Update hidden line index
    String queryString = "update versioned Person set streamViewHiddenLineIndex = :newIndex where id = :id";

    log.debug("New hidden line index: " + newHiddenLineIndex);
    Query q = getEntityManager().createQuery(queryString).setParameter("newIndex", newHiddenLineIndex)
            .setParameter("id", userId);
    q.executeUpdate();
}

From source file:eu.domibus.common.dao.MessagingDao.java

public void delete(String messageId) {
    Query payloadsQuery = em.createNamedQuery("Messaging.findPartInfosForMessage");
    payloadsQuery.setParameter("MESSAGE_ID", messageId);

    Query emptyQuery = em.createNamedQuery("Messaging.emptyPayloads");
    emptyQuery.setParameter("PARTINFOS", payloadsQuery.getResultList());
    emptyQuery.executeUpdate();

    final Query messageStatusQuery = this.em.createNamedQuery("MessageLogEntry.setMessageStatus");
    messageStatusQuery.setParameter("MESSAGE_ID", messageId);
    messageStatusQuery.setParameter("TIMESTAMP", new Date());
    messageStatusQuery.setParameter("MESSAGE_STATUS", MessageStatus.DELETED);
    messageStatusQuery.executeUpdate();/*from  ww w.  j ava  2  s  .  c o m*/
}

From source file:org.simbasecurity.core.config.store.DatabaseConfigurationStore.java

public String setValue(ConfigurationParameter parameter, String value) {
    String oldValue = getValue(parameter);

    Query query = entityManager.createNativeQuery(SQL_SET);
    query.setParameter(1, value);/*from  ww w  .  ja v  a2s  .c om*/
    query.setParameter(2, String.valueOf(parameter));
    query.executeUpdate();

    return oldValue;
}

From source file:org.apache.roller.weblogger.business.jpa.JPAPingTargetManagerImpl.java

public void removeAllCustomPingTargets() throws WebloggerException {
    Query q = strategy.getNamedUpdate("PingTarget.removeByWebsiteNotNull");
    q.executeUpdate();
}

From source file:eu.optimis.trustedinstance.DBStorage.java

@SuppressWarnings("finally")
public boolean delete(String resourceKey) throws Exception {

    boolean result = true;
    EntityManager em = emf.createEntityManager();

    try {//www  .j  ava 2 s. c o m
        String jpql = "delete from DBStorageEntry se where se.key=\"" + resourceKey + "\"";
        em.getTransaction().begin();
        Query query = em.createQuery(jpql);
        int row = query.executeUpdate();
        em.getTransaction().commit();
        if (row == 0) {
            result = false;
        }
    } catch (Exception e) {
        result = false;
        throw e;
    } finally {
        em.close();
        return result;
    }
}

From source file:com.ebiz.modules.persistence.repository.support.MyRepositoryImpl.java

@Override
@Transactional//from ww  w  .  j a  v a  2  s .c  o  m
public void delete(ID[] ids) {
    logger.trace("----->MyRepositoryImpl.delete(ID[] ids)");
    String qlString;
    Class<T> clazz = ei.getJavaType();
    if (clazz.isAnnotationPresent(LogicallyDelete.class)) {
        LogicallyDelete logicallyDelete = clazz.getAnnotation(LogicallyDelete.class);
        Object value = ConvertUtils.convert(logicallyDelete.value(), logicallyDelete.type().getClazz());
        qlString = String.format(STATE_DELETE_QUERY_STRING, ei.getEntityName(), logicallyDelete.name(), value);
    } else {
        qlString = String.format(DELETE_QUERY_STRING, ei.getEntityName());
    }
    logger.debug("......qlString:={}", qlString);
    Query query = em.createQuery(qlString);
    query.setParameter(1, Arrays.asList(ids));
    query.executeUpdate();
}