/**
 * Copyright © 2018 Mercateo AG (http://www.mercateo.com)
 *
 * 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 org.factcast.store.pgsql.rds;

import javax.annotation.Resource;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.cloud.aws.jdbc.datasource.TomcatJdbcDataSourceFactory;
import org.springframework.cloud.aws.jdbc.rds.AmazonRdsDataSourceFactoryBean;
import org.springframework.core.env.Environment;

/**
 * exchange the given TomcatJdbcDataSourceFactory with a customized factory so
 * we can configure the datasource connection pool
 * 
 *
 */

public class RdsDataSourceFactorBeanPostProcessor implements BeanPostProcessor {

    @Resource
    private Environment env;

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName)
            throws BeansException {

        if (bean instanceof AmazonRdsDataSourceFactoryBean) {
            ((AmazonRdsDataSourceFactoryBean) bean).setDataSourceFactory(
                    tomcatJdbcDataSourceFactory());
        }

        return bean;
    }

    TomcatJdbcDataSourceFactory tomcatJdbcDataSourceFactory() {

        TomcatJdbcDataSourceFactory fac = new TomcatJdbcDataSourceFactory();

        fac.setTestOnBorrow(env.getProperty("tomcat.testOnBorrow", Boolean.class));
        fac.setConnectionProperties(env.getProperty("tomcat.connectionProperties", String.class));
        return fac;

    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName)
            throws BeansException {
        return bean;
    }
}

@@ -1643,24 +1643,132 @@
 ean;%0A    %7D%0A%0A
+    // TODO this was reset to 0.0.6 state. Will be discussed with the original%0A    // author of that change%0A
     TomcatJd
@@ -1917,176 +1917,72 @@
 .set
-TestOnBorrow(env.getProperty(%22tomcat.testOnBorrow%22, Boolean.class));%0A        fac.setConnectionProperties(env.getProperty(%22tomcat.connectionProperties%22, String.class)
+RemoveAbandonedTimeout(360000);%0A        fac.setMaxWait(20000
 );%0A
+%0A
     

reset RDS autoconfig to 0.0.6 (#136)