View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.common.impex.spring;
17  
18  import org.kuali.common.impex.database.DumpDatabaseExecutable;
19  import org.kuali.common.jdbc.spring.JdbcDataSourceConfig;
20  import org.kuali.common.util.execute.Executable;
21  import org.kuali.common.util.spring.SpringUtils;
22  import org.springframework.beans.factory.annotation.Autowired;
23  import org.springframework.context.annotation.Bean;
24  import org.springframework.context.annotation.Configuration;
25  import org.springframework.context.annotation.Import;
26  import org.springframework.core.env.Environment;
27  
28  /**
29   * Configures tasks related to dumping a database to disk
30   */
31  @Configuration
32  @Import({ JdbcDataSourceConfig.class, ExtractSchemaConfig.class, DumpSchemaConfig.class, DumpDataConfig.class })
33  public class DumpDatabaseConfig {
34  
35  	private static final String SKIP_KEY = "impex.dump.skip";
36  	private static final boolean DEFAULT_SKIP_VALUE = false;
37  
38  	@Autowired
39  	Environment env;
40  
41  	@Autowired
42  	JdbcDataSourceConfig dataSourceConfig;
43  
44  	@Autowired
45  	ExtractSchemaConfig extractSchemaConfig;
46  
47  	@Autowired
48  	DumpSchemaConfig dumpSchemaConfig;
49  
50  	@Autowired
51  	DumpDataConfig dumpDataConfig;
52  
53  	@Bean
54  	public Executable dumpDatabaseExecutable() {
55  
56  		// Setup a new executable
57  		DumpDatabaseExecutable exec = new DumpDatabaseExecutable();
58  
59  		// Figure out if we are skipping execution all together
60  		exec.setSkip(SpringUtils.getBoolean(env, SKIP_KEY, DEFAULT_SKIP_VALUE));
61  
62  		// Show the JDBC configuration
63  		exec.setShowConfigExecutable(dataSourceConfig.jdbcShowConfigExecutable());
64  
65  		// Connect to the db using JDBC and extract the information needed to create model objects representing the schema
66  		exec.setExtractSchemaExecutable(extractSchemaConfig.extractSchemaExecutable());
67  
68  		// Dump the schema model objects from memory to disk as XML
69  		exec.setDumpSchemaExecutable(dumpSchemaConfig.dumpSchemaExecutable());
70  
71  		// Connect to the db, extract data from the tables, and dump it to disk as MPX files
72  		exec.setDumpDataExecutable(dumpDataConfig.dumpDataExecutable());
73  
74  		// Return the configured executable
75  		return exec;
76  	}
77  
78  }