001    /**
002     * Copyright 2011 The Kuali Foundation Licensed under the
003     * Educational Community License, Version 2.0 (the "License"); you may
004     * not use this file except in compliance with the License. You may
005     * obtain a copy of the License at
006     *
007     * http://www.osedu.org/licenses/ECL-2.0
008     *
009     * Unless required by applicable law or agreed to in writing,
010     * software distributed under the License is distributed on an "AS IS"
011     * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012     * or implied. See the License for the specific language governing
013     * permissions and limitations under the License.
014     */
015    
016    package org.kuali.common.impex.database;
017    
018    import org.kuali.common.impex.data.DumpDataExecutable;
019    import org.kuali.common.impex.model.Schema;
020    import org.kuali.common.impex.schema.execute.DumpSchemaExecutable;
021    import org.kuali.common.impex.schema.service.ExtractSchemaExecutable;
022    import org.kuali.common.util.Assert;
023    import org.kuali.common.util.execute.Executable;
024    
025    /**
026     * Connect to a database using JDBC, extract schema information needed for Kuali applications, and dump it to disk as XML
027     */
028    public class DumpDatabaseExecutable implements Executable {
029    
030            boolean skip;
031            Executable showConfigExecutable;
032            ExtractSchemaExecutable extractSchemaExecutable;
033            DumpSchemaExecutable dumpSchemaExecutable;
034            DumpDataExecutable dumpDataExecutable;
035    
036            @Override
037            public void execute() {
038    
039                    // May have nothing to do
040                    if (skip) {
041                            return;
042                    }
043    
044                    // Make sure we are configured correctly
045                    Assert.notNull(showConfigExecutable, "showConfigExecutable is null");
046                    Assert.notNull(extractSchemaExecutable, "extractSchemaExecutable is null");
047                    Assert.notNull(dumpSchemaExecutable, "dumpSchemaExecutable is null");
048                    Assert.notNull(dumpDataExecutable, "dumpDataExecutable is null");
049    
050                    // Show the JDBC configuration we are using
051                    showConfigExecutable.execute();
052    
053                    // Connect to the database and extract the schema info
054                    extractSchemaExecutable.execute();
055    
056                    // Get the schema object generated during the extract
057                    Schema schema = extractSchemaExecutable.getResult().getSchema();
058    
059                    // Schema can't be null here
060                    Assert.notNull(schema, "schema is null");
061    
062                    // Dump the schema to disk as XML
063                    dumpSchemaExecutable.getRequest().setSchema(schema);
064                    dumpSchemaExecutable.execute();
065    
066                    // Connect to the database, extract the data, and dump it to disk
067                    dumpDataExecutable.setSchema(schema);
068                    dumpDataExecutable.execute();
069            }
070    
071            public boolean isSkip() {
072                    return skip;
073            }
074    
075            public void setSkip(boolean skip) {
076                    this.skip = skip;
077            }
078    
079            public Executable getShowConfigExecutable() {
080                    return showConfigExecutable;
081            }
082    
083            public void setShowConfigExecutable(Executable showConfigExecutable) {
084                    this.showConfigExecutable = showConfigExecutable;
085            }
086    
087            public ExtractSchemaExecutable getExtractSchemaExecutable() {
088                    return extractSchemaExecutable;
089            }
090    
091            public void setExtractSchemaExecutable(ExtractSchemaExecutable extractSchemaExecutable) {
092                    this.extractSchemaExecutable = extractSchemaExecutable;
093            }
094    
095            public DumpSchemaExecutable getDumpSchemaExecutable() {
096                    return dumpSchemaExecutable;
097            }
098    
099            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    }