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.database;
17  
18  import org.kuali.common.impex.data.DumpDataExecutable;
19  import org.kuali.common.impex.model.Schema;
20  import org.kuali.common.impex.schema.execute.DumpSchemaExecutable;
21  import org.kuali.common.impex.schema.service.ExtractSchemaExecutable;
22  import org.kuali.common.util.Assert;
23  import org.kuali.common.util.execute.Executable;
24  
25  /**
26   * Connect to a database using JDBC, extract schema information needed for Kuali applications, and dump it to disk as XML
27   */
28  public class DumpDatabaseExecutable implements Executable {
29  
30  	boolean skip;
31  	Executable showConfigExecutable;
32  	ExtractSchemaExecutable extractSchemaExecutable;
33  	DumpSchemaExecutable dumpSchemaExecutable;
34  	DumpDataExecutable dumpDataExecutable;
35  
36  	@Override
37  	public void execute() {
38  
39  		// May have nothing to do
40  		if (skip) {
41  			return;
42  		}
43  
44  		// Make sure we are configured correctly
45  		Assert.notNull(showConfigExecutable, "showConfigExecutable is null");
46  		Assert.notNull(extractSchemaExecutable, "extractSchemaExecutable is null");
47  		Assert.notNull(dumpSchemaExecutable, "dumpSchemaExecutable is null");
48  		Assert.notNull(dumpDataExecutable, "dumpDataExecutable is null");
49  
50  		// Show the JDBC configuration we are using
51  		showConfigExecutable.execute();
52  
53  		// Connect to the database and extract the schema info
54  		extractSchemaExecutable.execute();
55  
56  		// Get the schema object generated during the extract
57  		Schema schema = extractSchemaExecutable.getResult().getSchema();
58  
59  		// Schema can't be null here
60  		Assert.notNull(schema, "schema is null");
61  
62  		// Dump the schema to disk as XML
63  		dumpSchemaExecutable.getRequest().setSchema(schema);
64  		dumpSchemaExecutable.execute();
65  
66  		// Connect to the database, extract the data, and dump it to disk
67  		dumpDataExecutable.setSchema(schema);
68  		dumpDataExecutable.execute();
69  	}
70  
71  	public boolean isSkip() {
72  		return skip;
73  	}
74  
75  	public void setSkip(boolean skip) {
76  		this.skip = skip;
77  	}
78  
79  	public Executable getShowConfigExecutable() {
80  		return showConfigExecutable;
81  	}
82  
83  	public void setShowConfigExecutable(Executable showConfigExecutable) {
84  		this.showConfigExecutable = showConfigExecutable;
85  	}
86  
87  	public ExtractSchemaExecutable getExtractSchemaExecutable() {
88  		return extractSchemaExecutable;
89  	}
90  
91  	public void setExtractSchemaExecutable(ExtractSchemaExecutable extractSchemaExecutable) {
92  		this.extractSchemaExecutable = extractSchemaExecutable;
93  	}
94  
95  	public DumpSchemaExecutable getDumpSchemaExecutable() {
96  		return dumpSchemaExecutable;
97  	}
98  
99  	public void setDumpSchemaExecutable(DumpSchemaExecutable dumpSchemaExecutable) {
100 		this.dumpSchemaExecutable = dumpSchemaExecutable;
101 	}
102 
103 	public DumpDataExecutable getDumpDataExecutable() {
104 		return dumpDataExecutable;
105 	}
106 
107 	public void setDumpDataExecutable(DumpDataExecutable dumpDataExecutable) {
108 		this.dumpDataExecutable = dumpDataExecutable;
109 	}
110 
111 }