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.apache.airavata.persistance.registry.jpa.ResourceUtils.java

/**
 * @param configkey// w  w  w .  j av a 2  s. c o  m
 * @param configValue
 */
public static void removeConfiguration(String configkey, String configValue) throws RegistryException {
    QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION);
    queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey);
    queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_VAL, configValue);
    EntityManager em = null;
    try {
        if (isConfigurationExists(configkey, configValue)) {
            em = getEntityManager();
            em.getTransaction().begin();
            Query q = queryGenerator.deleteQuery(em);
            q.executeUpdate();
            em.getTransaction().commit();
            em.close();
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new RegistryException(e);
    } finally {
        if (em != null && em.isOpen()) {
            if (em.getTransaction().isActive()) {
                em.getTransaction().rollback();
            }
            em.close();
        }
    }
}

From source file:org.eclipse.jubula.client.core.persistence.TestResultPM.java

/**
 * execute delete-test-result of summary without commit
 * @param session Session//w w w .j a v  a  2  s.c  o  m
 * @param resultId id of testresult-summary-entry, or <code>null</code> if 
 *                 all test results should be deleted.
 */
public static final void executeDeleteTestresultOfSummary(EntityManager session, Long resultId) {
    boolean isDeleteAll = resultId == null;

    //delete parameter details of test results
    String paramQueryBaseString = "delete from PARAMETER_DETAILS"; //$NON-NLS-1$
    if (isDeleteAll) {
        session.createNativeQuery(paramQueryBaseString).executeUpdate();
    } else {
        Query paramQuery = session.createNativeQuery(paramQueryBaseString
                + " where FK_TESTRESULT in (select ID from TESTRESULT where INTERNAL_TESTRUN_ID = #summaryId)"); //$NON-NLS-1$
        paramQuery.setParameter("summaryId", resultId); //$NON-NLS-1$
        paramQuery.executeUpdate();
    }

    //delete test result details
    StringBuilder resultQueryBuilder = new StringBuilder();
    resultQueryBuilder.append("delete from TestResultPO testResult"); //$NON-NLS-1$
    if (!isDeleteAll) {
        resultQueryBuilder.append(" where testResult.internalTestResultSummaryID = :id"); //$NON-NLS-1$
    }
    Query resultQuery = session.createQuery(resultQueryBuilder.toString());
    if (!isDeleteAll) {
        resultQuery.setParameter("id", resultId); //$NON-NLS-1$
    }
    resultQuery.executeUpdate();

}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteSummaryDayByDateTime(Long dateTime, int timeout) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("SummaryDay.deleteByDateTime").setParameter("dateTime", dateTime);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }/*from ww w  .  j  a  v a  2 s. c om*/
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteCollectDataByDateTime(Long dateTime, int timeout) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("CollectData.deleteByDateTime").setParameter("dateTime", dateTime);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }/*from   www .  j a v a  2s. com*/
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteSummaryHourByDateTime(Long dateTime, int timeout) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("SummaryHour.deleteByDateTime").setParameter("dateTime", dateTime);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }/*from w ww. j  av a  2s  . co m*/
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteSummaryMonthByDateTime(Long dateTime, int timeout) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("SummaryMonth.deleteByDateTime").setParameter("dateTime", dateTime);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }//from   w w  w  . jav  a 2s.  co m
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteCollectStringDataByDateTime(Long dateTime, int timeout) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("CollectStringData.deleteByDateTime").setParameter("dateTime", dateTime);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }/*from w w  w  .j a v  a2  s .  co m*/
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteEventLogByGenerationDate(Long generationDate, int timeout) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("EventLogEntity.deleteByGenerationDate").setParameter("generationDate",
            generationDate);/*from   ww w .  j ava2  s .  c  o  m*/
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteEventLogByGenerationDateConfigFlg(Long generationDate, int timeout) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("EventLogEntity.deleteByGenerationDateConfigFlg")
            .setParameter("generationDate", generationDate);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }//from  w w  w . ja  v a2  s  .c o m
    return query.executeUpdate();
}

From source file:com.clustercontrol.maintenance.util.QueryUtil.java

public static int deleteSummaryDayByDateTimeAndMonitorId(Long dateTime, int timeout, String monitorId) {
    HinemosEntityManager em = new JpaTransactionManager().getEntityManager();
    Query query = em.createNamedQuery("SummaryDay.deleteByDateTimeAndMonitorId")
            .setParameter("dateTime", dateTime).setParameter("monitorId", monitorId);
    if (timeout > 0) {
        query = query.setHint(JpaPersistenceConfig.JPA_PARAM_QUERY_TIMEOUT, timeout * 1000);
    }//from   w  w w .j  av  a2s . c om
    return query.executeUpdate();
}