List of usage examples for javax.persistence Query executeUpdate
int executeUpdate();
From source file:org.apache.juddi.query.DeletePublisherAssertionByBusinessQuery.java
public static int delete(EntityManager em, List<?> businessKeys) { if ((businessKeys == null) || (businessKeys.size() == 0)) return 0; DynamicQuery dynamicQry = new DynamicQuery(deleteSQL); appendConditions(dynamicQry, businessKeys); log.debug(dynamicQry);//from www .j a va2s .co m Query qry = dynamicQry.buildJPAQuery(em); int result = qry.executeUpdate(); return result; }
From source file:org.sonar.plugins.dbcleaner.api.PurgeUtils.java
/** * Paginate execution of SQL requests to avoid exceeding size of rollback segment *///from w w w. ja v a2 s . c om public static void executeQuery(DatabaseSession session, String description, List<Integer> ids, String hql) { if (ids == null || ids.isEmpty()) { return; } TimeProfiler profiler = new TimeProfiler().setLevelToDebug().start("Execute " + description); int index = 0; while (index < ids.size()) { List<Integer> paginedSids = ids.subList(index, Math.min(ids.size(), index + MAX_IN_ELEMENTS)); Query query = session.createQuery(hql); query.setParameter("ids", paginedSids); query.executeUpdate(); index += MAX_IN_ELEMENTS; session.commit(); } profiler.stop(); }
From source file:org.sonar.plugins.dbcleaner.api.PurgeUtils.java
/** * @since 2.13/*w ww .ja v a 2 s .c o m*/ */ @VisibleForTesting static void executeNativeQuery(DatabaseSession session, String description, List<Integer> ids, String sql) { if (ids == null || ids.isEmpty()) { return; } TimeProfiler profiler = new TimeProfiler().setLevelToDebug().start("Execute " + description); int index = 0; while (index < ids.size()) { List<Integer> paginedSids = ids.subList(index, Math.min(ids.size(), index + MAX_IN_ELEMENTS)); Query query = session.createNativeQuery(sql); query.setParameter("ids", paginedSids); query.executeUpdate(); index += MAX_IN_ELEMENTS; session.commit(); } profiler.stop(); }
From source file:org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils.java
/** * @param gatewayId//from w w w. ja v a 2s . co m * @return */ public static boolean removeGateway(String gatewayId) { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.GATEWAY); generator.setParameter(AbstractExpCatResource.GatewayConstants.GATEWAY_ID, gatewayId); Query q = generator.deleteQuery(em); q.executeUpdate(); em.getTransaction().commit(); em.close(); return true; } catch (Exception e) { logger.error(e.getMessage(), e); return false; } finally { if (em != null && em.isOpen()) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } } }
From source file:org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils.java
/** * @param gatewayResource/* w w w.ja va 2s . co m*/ * @param userResource * @return */ public static boolean removeGatewayWorker(GatewayResource gatewayResource, UserResource userResource) { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); QueryGenerator generator = new QueryGenerator(AbstractExpCatResource.GATEWAY_WORKER); generator.setParameter(AbstractExpCatResource.GatewayWorkerConstants.GATEWAY_ID, gatewayResource.getGatewayName()); generator.setParameter(AbstractExpCatResource.UserConstants.USERNAME, userResource.getUserName()); Query q = generator.deleteQuery(em); q.executeUpdate(); em.getTransaction().commit(); em.close(); return true; } catch (Exception e) { logger.error(e.getMessage(), e); return false; } finally { if (em != null && em.isOpen()) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } } }
From source file:com.ecarride.App.java
public static void ResetDriverWorkStatus() { Iterator<TlcDriver> iterator = tlcDrivers.iterator(); while (iterator.hasNext()) { TlcDriver temp = iterator.next(); if (!temp.isInTrouble()) continue; EntityTransaction updateTransaction = entityManager.getTransaction(); updateTransaction.begin();//from w ww . j a v a 2 s . c om Query query = entityManager .createQuery("UPDATE Driver d SET d.baseApproved = 0, d.status = 0" + "WHERE d.id= :id"); query.setParameter("id", temp.getDriver().getId()); query.executeUpdate(); updateTransaction.commit(); } }
From source file:org.eclipse.jubula.client.core.persistence.TestResultPM.java
/** * deleting monitoring reports by age (days of existence) * or deleting all, if the summaryId is null. * @param session The current session (EntityManager) * @param summaryId The summaryToDelete. * This value can be null, if all test results were deleted. * if summaryId is null, all monitoring reports will also be deleted. *//*from w w w . ja v a2 s.c om*/ private static void deleteMonitoringReports(EntityManager session, Long summaryId) { ITestResultSummaryPO summaryPo = null; if (summaryId != null) { summaryPo = session.find(PoMaker.getTestResultSummaryClass(), summaryId); if (summaryPo != null) { summaryPo.setMonitoringReport(null); summaryPo.setReportWritten(false); } } else { // Optimization: Since all monitoring reports need to be deleted, // we delete them with a JPQL query before removing // them via iteration. This prevents OutOfMemoryErrors // caused by loading all reports in to memory at the // same time. Query deleteMonitoringReportsQuery = session .createQuery("UPDATE " + PoMaker.getMonitoringReportClass().getSimpleName() //$NON-NLS-1$ + " SET report = null"); //$NON-NLS-1$ deleteMonitoringReportsQuery.executeUpdate(); session.flush(); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("SELECT summary FROM ") //$NON-NLS-1$ .append(PoMaker.getTestResultSummaryClass().getSimpleName()) .append(" AS summary where summary.reportWritten = :isReportWritten"); //$NON-NLS-1$ Query q = session.createQuery(queryBuilder.toString()); q.setParameter("isReportWritten", true); //$NON-NLS-1$ @SuppressWarnings("unchecked") List<ITestResultSummaryPO> reportList = q.getResultList(); for (ITestResultSummaryPO summary : reportList) { summary.setMonitoringReport(null); summary.setReportWritten(false); } } }
From source file:org.apache.airavata.persistance.registry.jpa.ResourceUtils.java
/** * @param gatewayName//from w w w.j a v a 2 s . co m * @return */ public static boolean removeGateway(String gatewayName) { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY); generator.setParameter(AbstractResource.GatewayConstants.GATEWAY_NAME, gatewayName); Query q = generator.deleteQuery(em); q.executeUpdate(); em.getTransaction().commit(); em.close(); return true; } catch (Exception e) { logger.error(e.getMessage(), e); return false; } finally { if (em != null && em.isOpen()) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } } }
From source file:org.apache.airavata.persistance.registry.jpa.ResourceUtils.java
/** * @param gatewayResource// w w w.j a v a2 s . c o m * @param userResource * @return */ public static boolean removeGatewayWorker(GatewayResource gatewayResource, UserResource userResource) { EntityManager em = null; try { em = getEntityManager(); em.getTransaction().begin(); QueryGenerator generator = new QueryGenerator(AbstractResource.GATEWAY_WORKER); generator.setParameter(AbstractResource.GatewayWorkerConstants.GATEWAY_NAME, gatewayResource.getGatewayName()); generator.setParameter(AbstractResource.UserConstants.USERNAME, userResource.getUserName()); Query q = generator.deleteQuery(em); q.executeUpdate(); em.getTransaction().commit(); em.close(); return true; } catch (Exception e) { logger.error(e.getMessage(), e); return false; } finally { if (em != null && em.isOpen()) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } em.close(); } } }
From source file:org.apache.airavata.persistance.registry.jpa.ResourceUtils.java
/** * @param configkey/*w ww . j a va 2s .c o m*/ */ public static void removeConfiguration(String configkey) throws RegistryException { QueryGenerator queryGenerator = new QueryGenerator(AbstractResource.CONFIGURATION); queryGenerator.setParameter(AbstractResource.ConfigurationConstants.CONFIG_KEY, configkey); EntityManager em = null; try { if (isConfigurationExist(configkey)) { 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(); } } }