/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package leap.spring.boot;

import leap.core.transaction.TransactionProvider;
import leap.core.transaction.TransactionProviderFactory;
import leap.lang.annotation.Init;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

public class LeapTransactionProviderFactory implements TransactionProviderFactory {

    private PlatformTransactionManager txm;

    @Init
    private void init() {
        txm = Global.context.getBean(PlatformTransactionManager.class);
    }

    @Override
    public TransactionProvider getTransactionProvider(DataSource dataSource) {
        return new LeapTransactionProvider(txm,dataSource);
    }

}
@@ -641,16 +641,78 @@
 .boot;%0A%0A
+import leap.core.transaction.LocalTransactionProviderFactory;%0A
 import l
@@ -844,16 +844,155 @@
 n.Init;%0A
+import leap.lang.logging.Log;%0Aimport leap.lang.logging.LogFactory;%0Aimport org.springframework.beans.factory.NoSuchBeanDefinitionException;%0A
 import o
@@ -1125,16 +1125,56 @@
 Factory 
+extends LocalTransactionProviderFactory 
 implemen
@@ -1206,16 +1206,106 @@
 tory %7B%0A%0A
+    private static final Log log = LogFactory.get(LeapTransactionProviderFactory.class);%0A%0A
     priv
@@ -1373,24 +1373,42 @@
 id init() %7B%0A
+        try %7B%0A    
         txm 
@@ -1475,104 +1475,424 @@
     
-%7D%0A%0A    @Override%0A    public TransactionProvider getTransactionProvider(DataSource dataSource) %7B%0A
+        log.info(%22Spring PlatformTransactionManager found, use it%22);%0A        %7Dcatch (NoSuchBeanDefinitionException e)%7B%0A            log.info(%22Spring PlatformTransactionManager not found, use local%22);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public TransactionProvider getTransactionProvider(DataSource dataSource) %7B%0A        if(null == txm) %7B%0A            return super.getTransactionProvider(dataSource);%0A        %7Delse %7B%0A    
     
@@ -1943,20 +1943,30 @@
 ataSource);%0A
+        %7D%0A
     %7D%0A%0A%7D

use local transaction if spring transaction not found