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.util;
17  
18  import java.util.List;
19  
20  import org.kuali.common.impex.spring.MpxSupplierConfig;
21  import org.kuali.common.impex.spring.SchemaXmlSupplierConfig;
22  import org.kuali.common.jdbc.JdbcProjectContext;
23  import org.kuali.common.jdbc.spring.SqlControllerConfig;
24  import org.kuali.common.util.CollectionUtils;
25  import org.kuali.common.util.ProjectContext;
26  import org.kuali.common.util.execute.SpringExecutable;
27  import org.kuali.common.util.spring.SpringUtils;
28  
29  public class BuildDatabaseUtility {
30  
31  	public static void main(String[] args) {
32  
33  		if (args.length < 1) {
34  			printHelpAndExit();
35  		}
36  
37  		String propertiesLocation = args[0];
38  		boolean includeMpxConfig = true;
39  		if (args.length >= 2) {
40  			includeMpxConfig = Boolean.parseBoolean(args[1]);
41  		}
42  
43  		try {
44  			List<Class<?>> configClasses = getAnnotatedClasses(includeMpxConfig);
45  			ProjectContext project = new JdbcProjectContext();
46  			SpringExecutable executable = SpringUtils.getSpringExecutable(project, propertiesLocation, configClasses);
47  			executable.execute();
48  		} catch (Exception e) {
49  			e.printStackTrace();
50  		}
51  
52  	}
53  
54  	protected static List<Class<?>> getAnnotatedClasses(boolean includeMpxConfig) {
55  		if (includeMpxConfig) {
56  			return CollectionUtils.asList(MpxSupplierConfig.class, SchemaXmlSupplierConfig.class, SqlControllerConfig.class);
57  		} else {
58  			return CollectionUtils.asList(SchemaXmlSupplierConfig.class, SqlControllerConfig.class);
59  		}
60  	}
61  
62  	protected static void printHelpAndExit() {
63  		System.out.println("Expects at least one argument, first a property file location.");
64  		System.out.println("Optionally, a second argument will be interpreted as whether or not to include configuration for Mpx files (default is true)");
65  		System.exit(1);
66  	}
67  
68  }