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.data;
17  
18  import java.util.List;
19  
20  import org.kuali.common.impex.data.service.DumpDataContext;
21  import org.kuali.common.impex.data.service.DumpDataService;
22  import org.kuali.common.impex.data.service.impl.DefaultDumpDataService;
23  import org.kuali.common.impex.data.service.impl.DumpTableResult;
24  import org.kuali.common.impex.model.Schema;
25  import org.kuali.common.impex.util.DumpUtils;
26  import org.kuali.common.util.Assert;
27  import org.kuali.common.util.execute.Executable;
28  
29  public class DumpDataExecutable implements Executable {
30  
31  	public static final boolean DEFAULT_SKIP_EXECUTION = false;
32  	public static final DumpDataService DEFAULT_SERVICE = new DefaultDumpDataService();
33  
34  	boolean skip = DEFAULT_SKIP_EXECUTION;
35  	DumpDataService service = DEFAULT_SERVICE;
36  	DumpDataContext context;
37  	Schema schema;
38  
39  	@Override
40  	public void execute() {
41  
42  		// May have nothing to do
43  		if (skip) {
44  			return;
45  		}
46  
47  		// Make sure we are configured correctly
48  		Assert.notNull(schema, "schema is null");
49  		Assert.notNull(context, "context is null");
50  		Assert.notNull(service, "service is null");
51  
52  		// Connect to the database, extract data from each table and create a .mpx file for each table that has data
53  		List<DumpTableResult> results = service.dumpTables(context, schema);
54  
55  		// After exporting tables, store the table statistics
56  		DumpUtils.storeTableStatistics(results, context.getTableStatisticsLocation());
57  	}
58  
59  	public DumpDataContext getContext() {
60  		return context;
61  	}
62  
63  	public void setContext(DumpDataContext context) {
64  		this.context = context;
65  	}
66  
67  	public DumpDataService getService() {
68  		return service;
69  	}
70  
71  	public void setService(DumpDataService service) {
72  		this.service = service;
73  	}
74  
75  	public Schema getSchema() {
76  		return schema;
77  	}
78  
79  	public void setSchema(Schema schema) {
80  		this.schema = schema;
81  	}
82  
83  	public boolean getSkip() {
84  		return skip;
85  	}
86  
87  	public void setSkip(boolean skip) {
88  		this.skip = skip;
89  	}
90  }