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.util.execute.Executable;
22  import org.kuali.common.util.execute.ExecutablesExecutable;
23  import org.kuali.common.util.spring.SpringUtils;
24  import org.springframework.beans.factory.annotation.Autowired;
25  import org.springframework.context.annotation.Configuration;
26  import org.springframework.context.annotation.Import;
27  import org.springframework.core.env.Environment;
28  
29  /**
30   * Default database reset controller class. It displays the JDBC configuration, then executes a series of SQL statements in order [dba->schema->data->constraints->other].
31   */
32  @Configuration
33  @Import({ JdbcCommonConfig.class, JdbcDataSourceConfig.class, ResetDbaConfig.class, ResetSchemaConfig.class, ResetConstraintsConfig.class, ResetOtherConfig.class,
34  		DbaCleanupConfig.class })
35  public abstract class AbstractResetController {
36  
37  	@Autowired
38  	Environment env;
39  
40  	@Autowired
41  	JdbcDataSourceConfig dataSourceConfig;
42  
43  	@Autowired
44  	ResetDbaConfig dbaConfig;
45  
46  	@Autowired
47  	ResetSchemaConfig schemaConfig;
48  
49  	@Autowired
50  	ResetDataConfig dataConfig;
51  
52  	@Autowired
53  	ResetConstraintsConfig constraintsConfig;
54  
55  	@Autowired
56  	ResetOtherConfig otherConfig;
57  
58  	@Autowired
59  	DbaCleanupConfig dbaCleanupConfig;
60  
61  	protected Executable getResetExecutable() {
62  		List<Executable> executables = new ArrayList<Executable>();
63  		executables.add(dataSourceConfig.jdbcShowConfigExecutable());
64  		executables.add(dbaConfig.jdbcDbaExecutable());
65  		executables.add(schemaConfig.jdbcSchemaExecutable());
66  		executables.add(dataConfig.jdbcDataConcurrentExecutable());
67  		executables.add(dataConfig.jdbcDataSequentialExecutable());
68  		executables.add(constraintsConfig.jdbcConstraintsConcurrentExecutable());
69  		executables.add(constraintsConfig.jdbcConstraintsSequentialExecutable());
70  		executables.add(otherConfig.jdbcOtherConcurrentExecutable());
71  		executables.add(otherConfig.jdbcOtherSequentialExecutable());
72  		executables.add(dbaCleanupConfig.jdbcDbaCleanupExecutable());
73  
74  		ExecutablesExecutable exec = new ExecutablesExecutable();
75  		exec.setSkip(SpringUtils.getBoolean(env, "jdbc.reset.skip", false));
76  		exec.setTimed(SpringUtils.getBoolean(env, "jdbc.reset.timed", true));
77  		exec.setExecutables(executables);
78  		return exec;
79  	}
80  
81  }