List of usage examples for javax.persistence Query executeUpdate
int executeUpdate();
From source file:org.kuali.mobility.xsl.dao.XslDaoImpl.java
public void deleteXslById(Long id) { Query query = entityManager.createQuery("delete from Xsl x where x.xslId = :id"); query.setParameter("id", id); query.executeUpdate(); }
From source file:cz.swi2.mendeluis.dataaccesslayer.repository.BaseRepository.java
/** * Vymaze vsechny trvale z db. Pouzito pro vycisteni db pred nahranim testovacich dat. *//*from ww w . j a v a 2 s . c o m*/ public void deleteAllPernamently() { String hql = String.format("delete from %s", this.getEntityName()); Query query = this.entityManager.createQuery(hql); query.executeUpdate(); }
From source file:org.cleverbus.core.common.dao.MessageOperationDaoJpaImpl.java
@Override public void removeExtCalls(Message msg, boolean totalRestart) { Assert.notNull(msg, "the msg must not be null"); String jSql = "DELETE " + "FROM " + ExternalCall.class.getName() + " c " + "WHERE c.msgId = ?1 "; if (!totalRestart) { // delete only confirmations jSql += "AND c.operationName = '" + ExternalCall.CONFIRM_OPERATION + "'"; }/*from w w w .j av a 2s . com*/ Query q = em.createQuery(jSql); q.setParameter(1, msg.getMsgId()); int updatedCount = q.executeUpdate(); Log.debug(updatedCount + " external calls were deleted for message with msgID=" + msg.getMsgId()); }
From source file:org.simbasecurity.core.domain.repository.SSOTokenMappingDatabaseRepository.java
public void remove(String token) { Query query = entityManager.createQuery("DELETE FROM SSOTokenMappingEntity tm WHERE tm.token = :token"); query.setParameter("token", token); query.executeUpdate(); }
From source file:org.simbasecurity.core.domain.repository.LoginMappingDatabaseRepository.java
@Override public void remove(String token) { Query query = entityManager.createQuery("DELETE FROM LoginMappingEntity lm WHERE lm.token = :token"); query.setParameter("token", token); query.executeUpdate(); }
From source file:com.impetus.client.oraclenosql.OracleNoSQLTestBase.java
protected int executeDMLQuery(String jpaQuery) { Query query = em.createQuery(jpaQuery); int updateCount = query.executeUpdate(); return updateCount; }
From source file:eu.planets_project.pp.plato.application.UtilAction.java
/** * We need that method here because LoadPlanAction is no longer an EJB which makes * it way simpler but unable to use the EntityManager when the session timed out. * So we create this application bean to enable unlocking the plan locked in * a session that's timed out./*from w w w. j a v a2 s . c o m*/ */ public void unlockPlan(int planPropertiesId) { String where = "where pp.id = " + planPropertiesId; Query q = em.createQuery("update PlanProperties pp set pp.openHandle = 0, pp.openedByUser = ''" + where); try { if (q.executeUpdate() < 1) { log.debug("Unlocking plan failed."); } else { log.debug("Unlocked plan"); } } catch (Throwable e) { log.error("Unlocking plan failed:", e); } //em.getTransaction().commit(); planPropertiesId = 0; }
From source file:me.doshou.admin.monitor.web.controller.JPAQLExecutorController.java
@PageableDefaults(pageNumber = 0, value = 10) @RequestMapping(value = "/ql", method = RequestMethod.POST) public String executeQL(final @RequestParam("ql") String ql, final Model model, final Pageable pageable) { model.addAttribute("sessionFactory", HibernateUtils.getSessionFactory(em)); try {//from w w w .ja v a 2 s.c o m new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { //1?ql try { Query query = em.createQuery(ql); int updateCount = query.executeUpdate(); model.addAttribute("updateCount", updateCount); return null; } catch (Exception e) { } //2 ?ql String findQL = ql; String alias = QueryUtils.detectAlias(findQL); if (StringUtils.isEmpty(alias)) { Pattern pattern = Pattern.compile("^(.*\\s*from\\s+)(.*)(\\s*.*)", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); findQL = pattern.matcher(findQL).replaceFirst("$1$2 o $3"); } String countQL = QueryUtils.createCountQueryFor(findQL); Query countQuery = em.createQuery(countQL); Query findQuery = em.createQuery(findQL); findQuery.setFirstResult(pageable.getOffset()); findQuery.setMaxResults(pageable.getPageSize()); Page page = new PageImpl(findQuery.getResultList(), pageable, (Long) countQuery.getSingleResult()); model.addAttribute("resultPage", page); return null; } }); } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); model.addAttribute(Constants.ERROR, sw.toString()); } return showQLForm(); }
From source file:org.simbasecurity.core.config.store.DatabaseConfigurationStore.java
public List<String> setValueList(ConfigurationParameter parameter, List<String> valueList) { List<String> oldValue = getValueList(parameter); Query query = entityManager.createNativeQuery(SQL_DELETE); query.setParameter(1, String.valueOf(parameter)); query.executeUpdate(); for (String value : valueList) { query = entityManager.createNativeQuery(SQL_INSERT); query.setParameter(1, String.valueOf(parameter)); query.setParameter(2, value);/*from w w w . jav a 2 s . co m*/ query.executeUpdate(); } return oldValue; }
From source file:jchat.test.RestTest.java
@Test public void test() throws Exception { eao.withQuery("DELETE FROM " + MessageEntity.class.getName(), new BaseEAO.ExecutableQuery<Integer>() { @Override//from w w w. ja v a2 s . c o m public Integer execute(Query query) { return query.executeUpdate(); } }); CloseableHttpClient client = HttpClients.custom().build(); // If this fails, don't forget to change you JS code Assert.assertEquals("{\"messageDto\":[]}", getBody(client.execute(new HttpGet(deploymentURL.toURI() + "rest/messages")))); String text = "Hi there! [" + System.currentTimeMillis() + "]"; try { // login post(client, "rest/auth", new BasicNameValuePair("user", "bototaxi")); // post message post(client, "rest/messages", new BasicNameValuePair("message", text)); int tryCounter = 0; while (true) { String json = getBody(client.execute(new HttpGet(deploymentURL.toURI() + "rest/messages"))); if (json.contains(text)) { break; } if (++tryCounter > 10) { Assert.fail("We tried " + tryCounter + " times without success. message: [" + text + "]; JSON: [" + json + "]"); } // Not time enough to process the message. Try it again! Thread.sleep(500); } } finally { client.close(); } }