001    /**
002     * Copyright 2010-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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    package org.kuali.common.jdbc.spring;
017    
018    import java.util.ArrayList;
019    import java.util.List;
020    
021    import org.kuali.common.jdbc.context.SqlExecutionContext;
022    import org.kuali.common.util.execute.Executable;
023    import org.kuali.common.util.execute.ExecutablesExecutable;
024    import org.kuali.common.util.spring.SpringUtils;
025    import org.springframework.beans.factory.annotation.Autowired;
026    import org.springframework.context.annotation.Bean;
027    import org.springframework.context.annotation.Configuration;
028    import org.springframework.context.annotation.Import;
029    import org.springframework.core.env.Environment;
030    
031    /**
032     * @deprecated
033     */
034    @Configuration
035    @Import({ JdbcCommonConfig.class, JdbcDataSourceConfig.class, SqlDbaBeforeConfig.class, SqlDbaAfterConfig.class })
036    @Deprecated
037    public abstract class AbstractSqlController {
038    
039            @Autowired
040            Environment env;
041    
042            @Autowired
043            JdbcDataSourceConfig dataSourceConfig;
044    
045            @Autowired
046            SqlDbaBeforeConfig dbaBeforeConfig;
047    
048            @Autowired
049            SqlDbaAfterConfig dbaAfterConfig;
050    
051            @Autowired
052            JdbcCommonConfig commonConfig;
053    
054            @Bean
055            public Executable sqlExecutable() {
056                    return getSqlExecutable();
057            }
058    
059            protected Executable getSqlExecutable() {
060                    List<Executable> executables = new ArrayList<Executable>();
061                    executables.add(dataSourceConfig.jdbcShowDbaConfigExecutable());
062                    executables.add(dbaBeforeConfig.getDbaPhaseExecutable());
063                    List<SqlExecutionContext> contexts = SqlConfigUtils.getSqlExecutionContexts(env);
064    
065                    for (SqlExecutionContext context : contexts) {
066                            SqlConfigContext scc = new SqlConfigContext(env, context, commonConfig, dataSourceConfig);
067                            Executable executable = SqlConfigUtils.getJdbcExecutable(scc);
068                            executables.add(executable);
069                    }
070                    executables.add(dbaAfterConfig.getDbaPhaseExecutable());
071    
072                    ExecutablesExecutable exec = new ExecutablesExecutable();
073                    exec.setSkip(SpringUtils.getBoolean(env, "jdbc.reset.skip", false));
074                    exec.setTimed(SpringUtils.getBoolean(env, "jdbc.reset.timed", true));
075                    exec.setExecutables(executables);
076                    return exec;
077            }
078    
079    }