@Override protected void markProcessed(Message message) { TransactionStatus status = currentStatus.get(); this.transactionManager.commit(status); }
manager.commit(status);
/** * Commit the transaction to the data source. */ protected void commitTransaction() { if (transactionStatus == null) throw new IllegalStateException("no transaction in progress"); log.debug("commitTransaction"); transactionManager.commit(transactionStatus); this.transactionStatus = null; this.inTransaction = false; log.debug("commit: OK"); }
public void commitTransaction() { if (transactions.isEmpty()) { throw new IllegalStateException("no transaction in progress"); } Txn txn = transactions.pop(); if (txn.doCommit) { log.debug("commitTransaction"); writeTxnManager.commit(txn.status); log.debug("commitTransaction: OK"); } else { log.debug("commitTransaction - skip"); } log.debug("commitTransaction: " + transactions.size()); }
txManager.commit(transactionStatus);
txManager.commit(transactionStatus);
@Override public boolean postNote(Note note, String tagNames) { if (LangUtils.string.isEmpty(tagNames)) { throw new RuntimeException("tagName不能为空!"); } String[] tagNameArray = tagNames.split(","); DefaultTransactionDefinition def = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = tm.getTransaction(def); try { note = noteRepository.save(note); if (note == null) { throw new RuntimeException("发布失败!"); } saveNoteTag(note, tagNameArray); tm.commit(status); return true; } catch (Exception e) { tm.rollback(status); log.error("发布笔记出错,回滚数据...", e); throw new RuntimeException(e); } }
private Customer getCustomer(final DataSourceTransactionManager txMan, final JdbcTemplate t, final String id) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED); TransactionStatus status = txMan.getTransaction(def); Customer c = null; try { c = t.queryForObject(SELECT_CUSTOMER, new CustomerRowMapper(), id); } catch (Exception ex) { txMan.rollback(status); throw ex; } txMan.commit(status); return c; }
@Override public boolean updateNote(Note note, String tagNames) { String[] tagNameArray = tagNames.split(","); DefaultTransactionDefinition def = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = tm.getTransaction(def); try { if (noteRepository.updateById(note) == 1) { tagReferRepository.deleteByReferId(note.getId()); saveNoteTag(note, tagNameArray); tm.commit(status); return true; } else return false; } catch (Exception e) { tm.rollback(status); log.error("发布笔记出错,回滚数据...", e); throw new RuntimeException(e); } }
cnt++; tm.commit(status); return true; } catch (Exception e) {
@Override public boolean updateArticle(Article article, String tagNames) { String[] tagNameArray = tagNames.split(","); DefaultTransactionDefinition def = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status = tm.getTransaction(def); try { article.setModify(now()); getSumByFilterContent(article); if (articleRepository.updateById(article) == 1) { tagReferRepository.deleteByReferId(article.getId()); int cnt = 0; for (String name : Arrays.asList(tagNameArray)) { long tagId; if (tagRepository.countByName(name) == 0) { tagId = tagRepository.save(Tag.builder().name(name).build()).getId(); } else { tagId = tagRepository.findIdByName(name); } tagReferRepository.save(TagRefer.builder().referId(article.getId()).tagId(tagId).show(cnt < 4).type(TagType.article.name()).build()); cnt++; } tm.commit(status); return true; } else return false; } catch (Exception e) { tm.rollback(status); log.error("发布博文出错,回滚数据...", e); throw new RuntimeException(e); } }