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:de.berlios.jhelpdesk.dao.jpa.TicketFilterDAOJpa.java

private void deleteFilterItems(EntityManager em, Long filterId) {
    for (String table : tables) {
        Query query = em
                .createNativeQuery("DELETE FROM ticket_filters_" + table + " WHERE ticket_filter_id=?1");
        query.setParameter(1, filterId);
        query.executeUpdate();
    }/*from  w  w  w .j  a  v  a 2 s .c  o m*/
}

From source file:com.jd.survey.dao.security.UserDAOImpl.java

@SuppressWarnings("unchecked")
@Transactional/*  ww w.  j  a va  2s .  com*/
public int deleteByDepartmentId(Long id) throws DataAccessException {
    Query query = createNamedQuery("deleteByDepartmentId", 0, 0, id);
    return query.executeUpdate();

}

From source file:me.ronghai.sa.dao.impl.AbstractModelDAOWithEMImpl.java

@Override
public int update(String sql) {
    Query query = entityManager.createNativeQuery(sql);
    return query.executeUpdate();
}

From source file:com.ny.apps.dao.BaseDaoImpl.java

@Override
@Transactional/* w ww  .  ja  v  a 2s .c o  m*/
public int update(String queryStr, Object... params) {
    Query query = (prepareParameterizedQuery(entityManager.createQuery(queryStr), params));
    int result = query.executeUpdate();
    return result;
}

From source file:com.ewcms.publication.PublishIntegratedTest.java

private void updateResourceStutas() {
    JpaTemplate template = createJpaTemplate();
    template.execute(new JpaCallback<Object>() {
        @Override//from   ww  w  .j av  a2s.c o  m
        public Object doInJpa(EntityManager em) throws PersistenceException {
            em.getTransaction().begin();
            String hql = "Update Resource o Set o.status= ?1 Where o.status = ?2";
            Query query = em.createQuery(hql);
            query.setParameter(1, Resource.Status.NORMAL);
            query.setParameter(2, Resource.Status.RELEASED);
            query.executeUpdate();
            em.getTransaction().commit();
            return null;
        }
    });
}

From source file:com.ewcms.publication.PublishIntegratedTest.java

private void updateArticleStutas() {
    JpaTemplate template = createJpaTemplate();
    template.execute(new JpaCallback<Object>() {
        @Override/*w w  w  . j  a  va 2 s  .  c  om*/
        public Object doInJpa(EntityManager em) throws PersistenceException {
            em.getTransaction().begin();
            String hql = "Update Article o Set o.status=?1 Where o.status = ?2";
            Query query = em.createQuery(hql);
            query.setParameter(1, Article.Status.PRERELEASE);
            query.setParameter(2, Article.Status.RELEASE);
            query.executeUpdate();
            em.getTransaction().commit();
            return null;
        }
    });
}

From source file:org.apache.openmeetings.db.dao.user.PrivateMessageDao.java

public int delete(Collection<Long> ids) {
    Query query = em.createNamedQuery("deletePrivateMessages");
    query.setParameter("ids", ids);
    return query.executeUpdate();
}

From source file:fr.univlorraine.ecandidat.controllers.DemoController.java

/** Lance un script sql
 * @param script/*from  www  . j a  va  2 s.  c  om*/
 */
@Transactional
private void launchSqlScript(String script) {
    EntityManager em = entityManagerFactoryEcandidat.createEntityManager();
    em.getTransaction().begin();
    try {
        final InputStream inputStream = this.getClass().getResourceAsStream("/db/demo/" + script);
        final InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        final BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        while (bufferedReader.ready()) {
            Query query = em.createNativeQuery(bufferedReader.readLine());
            query.executeUpdate();
        }

    } catch (Exception e) {
        em.getTransaction().rollback();
        em.close();
    }
    em.getTransaction().commit();
    em.close();
}

From source file:utilities.internal.CopyOfDatabaseUtil.java

public int executeUpdate(String line) {
    int result;/*from ww w  .j a  va  2s.co m*/
    Query query;

    query = entityManager.createQuery(line);
    result = query.executeUpdate();

    return result;
}

From source file:es.ucm.fdi.dalgs.module.repository.ModuleRepository.java

public boolean deleteModulesForDegree(Degree d) {
    try {//ww w .j av a2 s .  co  m
        Query query = em.createQuery("UPDATE Module m SET m.isDeleted = true where m.degree=?1");

        query.setParameter(1, d);
        query.executeUpdate();

    } catch (Exception e) {
        logger.error(e.getMessage());
        return false;
    }
    return true;
}