本文整理匯總了Java中org.springframework.transaction.annotation.Isolation.SERIALIZABLE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Isolation.SERIALIZABLE屬性的具體用法?Java Isolation.SERIALIZABLE怎麽用?Java Isolation.SERIALIZABLE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.springframework.transaction.annotation.Isolation
的用法示例。
在下文中一共展示了Isolation.SERIALIZABLE屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mergeSequences
@Transactional(propagation = MANDATORY, isolation = Isolation.SERIALIZABLE)
public Sequence mergeSequences(List<Sequence> sequences) {
Sequence main = sequences.get(0);
if (sequences.size() != 1) {
sequences.forEach(s -> entityManager.refresh(s));
List<BookSequence> bookSequences = sequences.stream().
flatMap(s -> s.getBookSequences().stream()).collect(Collectors.toList());
bookSequences.forEach(bs -> bs.setSequence(main));
main.setBookSequences(bookSequences);
sequenceRepository.save(main);
sequences.stream().skip(1).forEach(s -> {
s.setBookSequences(new ArrayList<>());
sequenceRepository.delete(s);
});
}
return main;
}
示例2: saveKombinationsBerechnung
@Override
@org.springframework.transaction.annotation.Transactional(isolation = Isolation.SERIALIZABLE)
public void saveKombinationsBerechnung(Kombinationsberechnung kombinationsberechnung) {
Kombinationsberechnung kombinationsberechungOld = null;
Integer berechnungsId = kombinationsberechnungDao.getBerechnungsId();
if(null != berechnungsId)
{
try {
kombinationsberechungOld = (Kombinationsberechnung) kombinationsberechnungDao.findOne(berechnungsId);
// Vielleicht in Erstinitialisierungsmethode?
} catch (Exception e) {
log.info("Did not find Combination Calculation, trying inserting...");
}
}
else {
kombinationsberechnungDao.save(kombinationsberechnung);
log.info("Speichere Kombinationsberechnung, weil noch keine ermittelt wurde.");
// log.error("Could neither find or update Combination Calculation from DB: " + e.getLocalizedMessage());
}
// FlushMode flushModeOld = sessionFactory.getCurrentSession().getFlushMode();
// sessionFactory.getCurrentSession().setFlushMode(FlushMode.MANUAL);
// sessionFactory.getCurrentSession().flush();
//// sessionFactory.getCurrentSession().getTransaction().commit();
//// sessionFactory.getCurrentSession().beginTransaction();
// sessionFactory.getCurrentSession().setFlushMode(flushModeOld);
// TODO In Generic-DAO-Methode (?)
}
示例3: newTransaction
@Transactional(propagation = REQUIRES_NEW, isolation = Isolation.SERIALIZABLE)
public void newTransaction(Runnable run){
run.run();
}
示例4: transactionRequired
@Transactional(propagation = REQUIRED, isolation = Isolation.SERIALIZABLE)
public void transactionRequired(Runnable run){
run.run();
}
示例5: virtualPayment
@Transactional(isolation = Isolation.SERIALIZABLE)
@Retryable(value = TransientDataAccessException.class, maxAttempts = 5)
public VirtualPaymentResult virtualPayment(@NonNull ECKey keySender, @NonNull ECKey keyReceiver, long amount, long
requestNonce) throws InvalidNonceException, UserNotFoundException, InvalidAmountException, InsufficientFunds,
InvalidRequestException {
// Sender and receiver must be different entities
if (keySender.getPublicKeyAsHex().equals(keyReceiver.getPublicKeyAsHex()))
throw new InvalidRequestException("The sender and receiver cannot be the same entities");
final Account sender = accountRepository.findByClientPublicKey(keySender.getPubKey());
if (sender == null)
throw new UserNotFoundException(keySender.getPublicKeyAsHex());
// Abort if the nonce is not fresh, we allow only higher nonces than in the database
// The nonce is generated by the client as unix epoch time in milliseconds.
// This prevents possible replay attacks:
// If we receive the same nonce as in the database, the request was probably sent two times
// If the nonce in the database is larger than the request, we probably got an old request sent again.
if (requestNonce <= sender.nonce())
throw new InvalidNonceException("Invalid nonce. Request already processed?");
// Fail if amount is invalid
if (amount < 1)
throw new InvalidAmountException("Invalid amount. Must be 1 or larger.");
// Check for sufficient funds
if (amount > sender.virtualBalance())
throw new InsufficientFunds("Insufficient funds, only " + sender.virtualBalance() + " satoshis available");
// Get receiver from database
final Account receiver = accountRepository.findByClientPublicKey(keyReceiver.getPubKey());
if (receiver == null)
throw new UserNotFoundException(keyReceiver.getPublicKeyAsHex());
// Do the transfer
final long senderOldBalance = sender.virtualBalance();
final long receiverOldBalance = receiver.virtualBalance();
sender.virtualBalance(senderOldBalance - amount);
receiver.virtualBalance(receiverOldBalance + amount);
// Guarantee that this request is only processed once
sender.nonce(requestNonce);
accountRepository.save(sender);
accountRepository.save(receiver);
// Return the new balances and the keys for sender and receiver that can be used for signing
return new VirtualPaymentResult(sender.virtualBalance(), sender.serverPrivateKey(), receiver.virtualBalance(),
receiver.serverPrivateKey());
}
示例6: payOutVirtualBalance
@Transactional(isolation = Isolation.SERIALIZABLE)
public PayoutResponse payOutVirtualBalance(ECKey accountOwner, String addressAsString) throws UserNotFoundException,
InsufficientMoneyException, IOException, BusinessException, InsufficientFunds {
final Address toAddress = Address.fromBase58(appConfig.getNetworkParameters(), addressAsString);
final Account account = accountService.getByClientPublicKey(accountOwner.getPubKey());
if (account == null)
throw new UserNotFoundException(accountOwner.getPublicKeyAsHex());
final Coin virtualBalance = Coin.valueOf(account.virtualBalance());
if (!virtualBalance.isPositive())
throw new InsufficientFunds();
final Coin potValue = getMicroPaymentPotValue();
LOG.info("Micropot value is {}", potValue);
if (potValue.isLessThan(virtualBalance)) {
eventService.warn(MICRO_PAYMENT_POT_EXHAUSTED, "Not enough coin in pot. " + virtualBalance + " needed " +
"but only " + potValue + " available.");
return new PayoutResponse();
}
Address changeAddress = appConfig.getMicroPaymentPotPrivKey().toAddress(appConfig.getNetworkParameters());
// Estimate fee by creating a send request
final Coin feePer1000Bytes = Coin.valueOf(feeService.fee() * 1000);
SendRequest estimateRequest = SendRequest.to(toAddress, virtualBalance);
estimateRequest.feePerKb = feePer1000Bytes;
estimateRequest.changeAddress = changeAddress;
walletService.getWallet().completeTx(estimateRequest);
final Coin requiredFee = estimateRequest.tx.getFee();
// Make actual request which subtracts fee from virtual balance
final Coin coinSendToUser = virtualBalance.minus(requiredFee);
SendRequest actualRequest = SendRequest.to(toAddress, coinSendToUser);
actualRequest.feePerKb = feePer1000Bytes;
actualRequest.changeAddress = changeAddress;
Wallet.SendResult sendResult = walletService.getWallet().sendCoins(actualRequest);
// At this point we must consider the coins to be gone, even in case of failure as it has been transmitted
// to the broadcaster.
account.virtualBalance(0L);
accountRepository.save(account);
// Wait for actual broadcast to succeed
Transaction broadcastedTx;
try {
broadcastedTx = sendResult.broadcastComplete.get();
} catch (InterruptedException | ExecutionException e) {
eventService.error(EventType.MICRO_PAYMENT_PAYOUT_ERROR, "Could not broadcast payout request "
+ "for account " + accountOwner.getPublicKeyAsHex() + ". Transaction: "
+ DTOUtils.toHex(sendResult.tx.bitcoinSerialize()) + " Reason:" + e.toString());
e.printStackTrace();
return new PayoutResponse();
}
PayoutResponse response = new PayoutResponse();
response.transaction = DTOUtils.toHex(broadcastedTx.bitcoinSerialize());
response.valuePaidOut = coinSendToUser.getValue();
return response;
}
示例7: save
@Override
@SuppressWarnings({ CompilerWarnings.UNCHECKED })
@Transactional(isolation = Isolation.SERIALIZABLE)
public V save(V entity) throws Exception {
ByteArraySource contentSrc = new ByteArraySource(entity.getContent().getBytes(StandardCharsets.UTF_8));
XdmDocument contentDoc = this.buildContentDocument(contentSrc);
String content = this.buildContent(contentDoc, true);
if (entity.hasEntityId()) {
V persistentEntity = this.entityManager.find(this.entityImplClass, entity.getEntityId());
this.entityManager.detach(persistentEntity);
if (!content.equals(persistentEntity.getContent())) {
entity = this.entityInstantiator.get();
entity.setId(persistentEntity.getId());
entity.setInstanceId(persistentEntity.getInstanceId());
entity.setPublishedTimestamp(persistentEntity.getPublishedTimestamp());
entity.setType(persistentEntity.getType());
}
}
Long id = entity.getId(), instanceId = entity.getInstanceId(), version = entity.getVersion();
CriteriaQuery<Long> criteriaQuery;
Root<V> criteriaRoot;
if (id == null) {
id = this.entityManager.createNamedQuery(DbQueryNames.RESOURCE_SELECT_ID_NEW, Long.class).getSingleResult();
instanceId = -1L;
version = 1L;
} else if (instanceId == null) {
(criteriaQuery = this.criteriaBuilder.createQuery(Long.class))
.select(this.criteriaBuilder.max((criteriaRoot = ((Root<V>) (criteriaQuery.from(this.entityImplClass)))).get(DbPropertyNames.INSTANCE_ID)));
criteriaQuery.distinct(true);
instanceId = (Optional
.ofNullable(this.buildCriteria(SdcctCriterionUtils.matchId(id), SdcctCriterionUtils.matchInstances(), SdcctCriterionUtils.matchLatestVersion())
.first(this.entityManager, criteriaQuery, criteriaRoot))
.orElse(0L) + 1);
version = 1L;
} else if (version == null) {
(criteriaQuery = this.criteriaBuilder.createQuery(Long.class))
.select(this.criteriaBuilder.max((criteriaRoot = ((Root<V>) (criteriaQuery.from(this.entityImplClass)))).get(DbPropertyNames.VERSION)));
criteriaQuery.distinct(true);
version = (Optional.ofNullable(this.buildCriteria(SdcctCriterionUtils.matchId(id), SdcctCriterionUtils.matchInstanceId(instanceId))
.first(this.entityManager, criteriaQuery, criteriaRoot)).orElse(0L) + 1);
}
entity.setId(id);
entity.setInstanceId(instanceId);
entity.setVersion(version);
Date timestamp = new Date();
entity.setModifiedTimestamp(timestamp);
if (!entity.hasPublishedTimestamp()) {
entity.setPublishedTimestamp(timestamp);
}
this.resourceParamProc
.process((contentDoc = this.buildContentDocument(new ByteArraySource(this.xmlCodec.encode(this.buildBean(contentSrc, entity), null)))), entity);
entity.setContent(this.buildContent(contentDoc, true));
return this.repo.save(entity);
}