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