View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.jdbc.spring;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.common.jdbc.context.SqlExecutionContext;
22  import org.kuali.common.util.execute.Executable;
23  import org.kuali.common.util.execute.ExecutablesExecutable;
24  import org.kuali.common.util.spring.SpringUtils;
25  import org.springframework.beans.factory.annotation.Autowired;
26  import org.springframework.context.annotation.Configuration;
27  import org.springframework.context.annotation.Import;
28  import org.springframework.core.env.Environment;
29  
30  /**
31   *
32   */
33  @Configuration
34  @Import({ JdbcCommonConfig.class, JdbcDataSourceConfig.class, SqlDbaBeforeConfig.class, SqlDbaAfterConfig.class })
35  public abstract class AbstractSqlController {
36  
37  	@Autowired
38  	Environment env;
39  
40  	@Autowired
41  	JdbcDataSourceConfig dataSourceConfig;
42  
43  	@Autowired
44  	SqlDbaBeforeConfig dbaBeforeConfig;
45  
46  	@Autowired
47  	SqlDbaAfterConfig dbaAfterConfig;
48  
49  	@Autowired
50  	JdbcCommonConfig commonConfig;
51  
52  	protected Executable getSqlExecutable() {
53  		List<Executable> executables = new ArrayList<Executable>();
54  		executables.add(dataSourceConfig.jdbcShowConfigExecutable());
55  		executables.add(dbaBeforeConfig.getDbaPhaseExecutable());
56  		List<SqlExecutionContext> contexts = SqlConfigUtils.getSqlExecutionContexts(env);
57  
58  		for (SqlExecutionContext context : contexts) {
59  			SqlConfigContext scc = new SqlConfigContext(env, context, commonConfig, dataSourceConfig);
60  			Executable executable = SqlConfigUtils.getJdbcExecutable(scc);
61  			executables.add(executable);
62  		}
63  		executables.add(dbaAfterConfig.getDbaPhaseExecutable());
64  
65  		ExecutablesExecutable exec = new ExecutablesExecutable();
66  		exec.setSkip(SpringUtils.getBoolean(env, "jdbc.reset.skip", false));
67  		exec.setTimed(SpringUtils.getBoolean(env, "jdbc.reset.timed", true));
68  		exec.setExecutables(executables);
69  		return exec;
70  	}
71  
72  }