001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.transaction;
018
019import java.util.ArrayList;
020import java.util.Collection;
021import java.util.Collections;
022import java.util.List;
023
024import org.springframework.boot.util.LambdaSafe;
025import org.springframework.transaction.PlatformTransactionManager;
026
027/**
028 * A collection of {@link PlatformTransactionManagerCustomizer}.
029 *
030 * @author Phillip Webb
031 * @since 1.5.0
032 */
033public class TransactionManagerCustomizers {
034
035        private final List<PlatformTransactionManagerCustomizer<?>> customizers;
036
037        public TransactionManagerCustomizers(
038                        Collection<? extends PlatformTransactionManagerCustomizer<?>> customizers) {
039                this.customizers = (customizers != null) ? new ArrayList<>(customizers)
040                                : Collections.emptyList();
041        }
042
043        @SuppressWarnings("unchecked")
044        public void customize(PlatformTransactionManager transactionManager) {
045                LambdaSafe
046                                .callbacks(PlatformTransactionManagerCustomizer.class, this.customizers,
047                                                transactionManager)
048                                .withLogger(TransactionManagerCustomizers.class)
049                                .invoke((customizer) -> customizer.customize(transactionManager));
050        }
051
052}