@Override protected boolean doIsProcessed(Message message) throws Exception { currentStatus.set(this.transactionManager.getTransaction(new DefaultTransactionAttribute())); return idempotentChecker.doIsProcessed(message); }
manager.setIsolationLevelName(XX); status = manager.getTransaction(Def);
assertTrue("Synchronization not active", !TransactionSynchronizationManager.isSynchronizationActive()); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); final TestTransactionSynchronization synch = new TestTransactionSynchronization(ds, TransactionSynchronization.STATUS_UNKNOWN);
assertTrue("Synchronization not active", !TransactionSynchronizationManager.isSynchronizationActive()); TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition()); TestTransactionSynchronization synch = new TestTransactionSynchronization(ds, TransactionSynchronization.STATUS_ROLLED_BACK);
/** * Start a transaction to the data source. */ protected void startTransaction() { if (transactionStatus != null) throw new IllegalStateException("transaction already in progress"); log.debug("startTransaction"); this.transactionStatus = transactionManager.getTransaction(defaultTransactionDef); this.inTransaction = true; log.debug("startTransaction: OK"); }
DataSource dataSource = getDataSourceFromSomewhere(); DataSourceTransactionManager tm = new DataSourceTransactionManager(dataSource); JdbcTemplate jdbc = new JdbcTemplate(dataSource); TransactionStatus tx = tm.getTransaction(new DefaultTransactionDefinition()); int update1 = jdbc.update("insert into employee..."); int employeeId = jdbc.queryForInt(select id from employee..."); int update2 = jdbc.update("insert into employee_department..."); if (employeeId > 0 && update2 > 0) tm.commit(tx); else tm.rollback(tx);
public void startTransaction() { TransactionDefinition defn; if (transactions.isEmpty()) { log.debug("startTransaction: default"); defn = defaultTxnDef; } else if (writeTxnManager.isNestedTransactionAllowed()) { log.debug("startTransaction: nested"); defn = nested; } else { throw new RuntimeException("nested transactions not supported by current configuration"); } Txn txn = new Txn(writeTxnManager.getTransaction(defn), true); transactions.push(txn); log.debug("startTransaction: " + transactions.size()); }
@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); } }
TransactionStatus status = tm.getTransaction(def); try {
@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); } }