Java Code Examples for org.springframework.transaction.TransactionDefinition#PROPAGATION_NESTED
The following examples show how to use
org.springframework.transaction.TransactionDefinition#PROPAGATION_NESTED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdminReservationRequestManager.java From alf.io with GNU General Public License v3.0 | 6 votes |
private Result<Triple<TicketReservation, List<Ticket>, Event>> processReservation(AdminReservationRequest request, Event event, User user) { DefaultTransactionDefinition definition = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_NESTED); TransactionTemplate template = new TransactionTemplate(transactionManager, definition); return template.execute(status -> { var savepoint = status.createSavepoint(); try { String eventName = event.getShortName(); String username = user.getUsername(); Result<Triple<TicketReservation, List<Ticket>, Event>> result = adminReservationManager.createReservation(request.getBody(), eventName, username) .flatMap(r -> adminReservationManager.confirmReservation(eventName, r.getLeft().getId(), username, orEmpty(request.getBody().getNotification()))); if(!result.isSuccess()) { status.rollbackToSavepoint(savepoint); } return result; } catch(Exception ex) { status.rollbackToSavepoint(savepoint); return Result.error(singletonList(ErrorCode.custom("", ex.getMessage()))); } }); }
Example 2
Source File: SpringTransactionProvider.java From micronaut-sql with Apache License 2.0 | 5 votes |
@Override public void begin(TransactionContext context) { TransactionDefinition definition = new DefaultTransactionDefinition( TransactionDefinition.PROPAGATION_NESTED); TransactionStatus status = this.transactionManager.getTransaction(definition); context.transaction(new SpringTransaction(status)); }
Example 3
Source File: SpringTransactionManager.java From dalesbred with MIT License | 5 votes |
static int springPropagationCode(@NotNull Propagation propagation) { switch (propagation) { case REQUIRED: return TransactionDefinition.PROPAGATION_REQUIRED; case MANDATORY: return TransactionDefinition.PROPAGATION_MANDATORY; case NESTED: return TransactionDefinition.PROPAGATION_NESTED; case REQUIRES_NEW: return TransactionDefinition.PROPAGATION_REQUIRES_NEW; } throw new IllegalArgumentException("unknown propagation: " + propagation); }
Example 4
Source File: AdminJobManager.java From alf.io with GNU General Public License v3.0 | 5 votes |
public AdminJobManager(List<AdminJobExecutor> jobExecutors, AdminJobQueueRepository adminJobQueueRepository, PlatformTransactionManager transactionManager) { this.executorsByJobId = jobExecutors.stream() .flatMap(je -> je.getJobNames().stream().map(n -> Pair.of(n, je))) .collect(groupingBy(Pair::getLeft, () -> new EnumMap<>(JobName.class), mapping(Pair::getValue, toList()))); this.adminJobQueueRepository = adminJobQueueRepository; this.nestedTransactionTemplate = new TransactionTemplate(transactionManager, new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_NESTED)); var executed = EnumSet.of(EXECUTED); this.executedStatuses = executed.stream().map(Enum::name).collect(toSet()); this.notExecutedStatuses = EnumSet.complementOf(executed).stream().map(Enum::name).collect(toSet()); }
Example 5
Source File: WebSphereUowTransactionManager.java From spring-analysis-note with MIT License | 4 votes |
@Override @Nullable public <T> T execute(@Nullable TransactionDefinition definition, TransactionCallback<T> callback) throws TransactionException { // Use defaults if no transaction definition given. TransactionDefinition def = (definition != null ? definition : TransactionDefinition.withDefaults()); if (def.getTimeout() < TransactionDefinition.TIMEOUT_DEFAULT) { throw new InvalidTimeoutException("Invalid transaction timeout", def.getTimeout()); } UOWManager uowManager = obtainUOWManager(); int pb = def.getPropagationBehavior(); boolean existingTx = (uowManager.getUOWStatus() != UOWSynchronizationRegistry.UOW_STATUS_NONE && uowManager.getUOWType() != UOWSynchronizationRegistry.UOW_TYPE_LOCAL_TRANSACTION); int uowType = UOWSynchronizationRegistry.UOW_TYPE_GLOBAL_TRANSACTION; boolean joinTx = false; boolean newSynch = false; if (existingTx) { if (pb == TransactionDefinition.PROPAGATION_NEVER) { throw new IllegalTransactionStateException( "Transaction propagation 'never' but existing transaction found"); } if (pb == TransactionDefinition.PROPAGATION_NESTED) { throw new NestedTransactionNotSupportedException( "Transaction propagation 'nested' not supported for WebSphere UOW transactions"); } if (pb == TransactionDefinition.PROPAGATION_SUPPORTS || pb == TransactionDefinition.PROPAGATION_REQUIRED || pb == TransactionDefinition.PROPAGATION_MANDATORY) { joinTx = true; newSynch = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER); } else if (pb == TransactionDefinition.PROPAGATION_NOT_SUPPORTED) { uowType = UOWSynchronizationRegistry.UOW_TYPE_LOCAL_TRANSACTION; newSynch = (getTransactionSynchronization() == SYNCHRONIZATION_ALWAYS); } else { newSynch = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER); } } else { if (pb == TransactionDefinition.PROPAGATION_MANDATORY) { throw new IllegalTransactionStateException( "Transaction propagation 'mandatory' but no existing transaction found"); } if (pb == TransactionDefinition.PROPAGATION_SUPPORTS || pb == TransactionDefinition.PROPAGATION_NOT_SUPPORTED || pb == TransactionDefinition.PROPAGATION_NEVER) { uowType = UOWSynchronizationRegistry.UOW_TYPE_LOCAL_TRANSACTION; newSynch = (getTransactionSynchronization() == SYNCHRONIZATION_ALWAYS); } else { newSynch = (getTransactionSynchronization() != SYNCHRONIZATION_NEVER); } } boolean debug = logger.isDebugEnabled(); if (debug) { logger.debug("Creating new transaction with name [" + def.getName() + "]: " + def); } SuspendedResourcesHolder suspendedResources = (!joinTx ? suspend(null) : null); UOWActionAdapter<T> action = null; try { if (def.getTimeout() > TransactionDefinition.TIMEOUT_DEFAULT) { uowManager.setUOWTimeout(uowType, def.getTimeout()); } if (debug) { logger.debug("Invoking WebSphere UOW action: type=" + uowType + ", join=" + joinTx); } action = new UOWActionAdapter<>( def, callback, (uowType == UOWManager.UOW_TYPE_GLOBAL_TRANSACTION), !joinTx, newSynch, debug); uowManager.runUnderUOW(uowType, joinTx, action); if (debug) { logger.debug("Returned from WebSphere UOW action: type=" + uowType + ", join=" + joinTx); } return action.getResult(); } catch (UOWException | UOWActionException ex) { TransactionSystemException tse = new TransactionSystemException("UOWManager transaction processing failed", ex); Throwable appEx = action.getException(); if (appEx != null) { logger.error("Application exception overridden by rollback exception", appEx); tse.initApplicationException(appEx); } throw tse; } finally { if (suspendedResources != null) { resume(null, suspendedResources); } } }
Example 6
Source File: SpringTransactionHandler.java From micronaut-sql with Apache License 2.0 | 4 votes |
@Override public void begin(Handle handle) { TransactionDefinition definition = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_NESTED); TransactionStatus status = this.transactionManager.getTransaction(definition); this.localStuff.putIfAbsent(handle, new LocalStuff(status)); }
Example 7
Source File: NotificationManager.java From alf.io with GNU General Public License v3.0 | 4 votes |
@Autowired public NotificationManager(Mailer mailer, MessageSourceManager messageSourceManager, PlatformTransactionManager transactionManager, EmailMessageRepository emailMessageRepository, EventRepository eventRepository, EventDescriptionRepository eventDescriptionRepository, OrganizationRepository organizationRepository, ConfigurationManager configurationManager, FileUploadManager fileUploadManager, TemplateManager templateManager, TicketReservationRepository ticketReservationRepository, TicketCategoryRepository ticketCategoryRepository, PassKitManager passKitManager, TicketRepository ticketRepository, TicketFieldRepository ticketFieldRepository, AdditionalServiceItemRepository additionalServiceItemRepository, ExtensionManager extensionManager) { this.messageSourceManager = messageSourceManager; this.mailer = mailer; this.emailMessageRepository = emailMessageRepository; this.eventRepository = eventRepository; this.organizationRepository = organizationRepository; this.ticketCategoryRepository = ticketCategoryRepository; DefaultTransactionDefinition definition = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_NESTED); this.tx = new TransactionTemplate(transactionManager, definition); this.configurationManager = configurationManager; GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(Mailer.Attachment.class, new AttachmentConverter()); this.gson = builder.create(); attachmentTransformer = new EnumMap<>(Mailer.AttachmentIdentifier.class); attachmentTransformer.put(Mailer.AttachmentIdentifier.CALENDAR_ICS, generateICS(eventRepository, eventDescriptionRepository, ticketCategoryRepository, organizationRepository, messageSourceManager)); attachmentTransformer.put(Mailer.AttachmentIdentifier.RECEIPT_PDF, receiptOrInvoiceFactory(eventRepository, payload -> TemplateProcessor.buildReceiptPdf(payload.getLeft(), fileUploadManager, payload.getMiddle(), templateManager, payload.getRight(), extensionManager))); attachmentTransformer.put(Mailer.AttachmentIdentifier.INVOICE_PDF, receiptOrInvoiceFactory(eventRepository, payload -> TemplateProcessor.buildInvoicePdf(payload.getLeft(), fileUploadManager, payload.getMiddle(), templateManager, payload.getRight(), extensionManager))); attachmentTransformer.put(Mailer.AttachmentIdentifier.CREDIT_NOTE_PDF, receiptOrInvoiceFactory(eventRepository, payload -> TemplateProcessor.buildCreditNotePdf(payload.getLeft(), fileUploadManager, payload.getMiddle(), templateManager, payload.getRight(), extensionManager))); attachmentTransformer.put(Mailer.AttachmentIdentifier.PASSBOOK, passKitManager::getPass); Function<Ticket, List<TicketFieldConfigurationDescriptionAndValue>> retrieveFieldValues = EventUtil.retrieveFieldValues(ticketRepository, ticketFieldRepository, additionalServiceItemRepository); attachmentTransformer.put(Mailer.AttachmentIdentifier.TICKET_PDF, generateTicketPDF(eventRepository, organizationRepository, configurationManager, fileUploadManager, templateManager, ticketReservationRepository, retrieveFieldValues, extensionManager)); }
Example 8
Source File: TicketReservationManager.java From alf.io with GNU General Public License v3.0 | 4 votes |
public TicketReservationManager(EventRepository eventRepository, OrganizationRepository organizationRepository, TicketRepository ticketRepository, TicketReservationRepository ticketReservationRepository, TicketCategoryRepository ticketCategoryRepository, TicketCategoryDescriptionRepository ticketCategoryDescriptionRepository, ConfigurationManager configurationManager, PaymentManager paymentManager, PromoCodeDiscountRepository promoCodeDiscountRepository, SpecialPriceRepository specialPriceRepository, TransactionRepository transactionRepository, NotificationManager notificationManager, MessageSourceManager messageSourceManager, TemplateManager templateManager, PlatformTransactionManager transactionManager, WaitingQueueManager waitingQueueManager, TicketFieldRepository ticketFieldRepository, AdditionalServiceRepository additionalServiceRepository, AdditionalServiceItemRepository additionalServiceItemRepository, AdditionalServiceTextRepository additionalServiceTextRepository, InvoiceSequencesRepository invoiceSequencesRepository, AuditingRepository auditingRepository, UserRepository userRepository, ExtensionManager extensionManager, TicketSearchRepository ticketSearchRepository, GroupManager groupManager, BillingDocumentRepository billingDocumentRepository, NamedParameterJdbcTemplate jdbcTemplate, Json json, PromoCodeDiscountRepository promoCodeRepository, BillingDocumentManager billingDocumentManager) { this.eventRepository = eventRepository; this.organizationRepository = organizationRepository; this.ticketRepository = ticketRepository; this.ticketReservationRepository = ticketReservationRepository; this.ticketCategoryRepository = ticketCategoryRepository; this.ticketCategoryDescriptionRepository = ticketCategoryDescriptionRepository; this.configurationManager = configurationManager; this.paymentManager = paymentManager; this.promoCodeDiscountRepository = promoCodeDiscountRepository; this.specialPriceRepository = specialPriceRepository; this.transactionRepository = transactionRepository; this.notificationManager = notificationManager; this.messageSourceManager = messageSourceManager; this.templateManager = templateManager; this.waitingQueueManager = waitingQueueManager; this.requiresNewTransactionTemplate = new TransactionTemplate(transactionManager, new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW)); DefaultTransactionDefinition serialized = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW); serialized.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE); this.serializedTransactionTemplate = new TransactionTemplate(transactionManager, serialized); this.nestedTransactionTemplate = new TransactionTemplate(transactionManager, new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_NESTED)); this.ticketFieldRepository = ticketFieldRepository; this.additionalServiceRepository = additionalServiceRepository; this.additionalServiceItemRepository = additionalServiceItemRepository; this.additionalServiceTextRepository = additionalServiceTextRepository; this.invoiceSequencesRepository = invoiceSequencesRepository; this.auditingRepository = auditingRepository; this.userRepository = userRepository; this.extensionManager = extensionManager; this.ticketSearchRepository = ticketSearchRepository; this.groupManager = groupManager; this.billingDocumentRepository = billingDocumentRepository; this.jdbcTemplate = jdbcTemplate; this.json = json; this.promoCodeRepository = promoCodeRepository; this.billingDocumentManager = billingDocumentManager; }