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.ArrayList;
19  import java.util.List;
20  import java.util.Properties;
21  
22  import org.kuali.common.impex.KualiImpexProducerConfig;
23  import org.kuali.common.impex.spring.MpxSupplierConfig;
24  import org.kuali.common.impex.spring.SchemaXmlSupplierConfig;
25  import org.kuali.common.jdbc.config.JdbcConfigConstants;
26  import org.kuali.common.jdbc.spring.SqlControllerExecutableConfig;
27  import org.kuali.common.util.CollectionUtils;
28  import org.kuali.common.util.PropertyUtils;
29  import org.kuali.common.util.config.service.DefaultConfigService;
30  import org.kuali.common.util.config.supplier.ConfigPropertiesSupplier;
31  import org.kuali.common.util.config.supplier.PropertiesSupplier;
32  import org.kuali.common.util.execute.SpringExecutable;
33  import org.kuali.common.util.spring.SpringUtils;
34  
35  public class BuildDatabaseUtility {
36  
37  	public static void main(String[] args) {
38  
39  		if (args.length < 1) {
40  			printHelpAndExit();
41  		}
42  
43  		String propertiesLocation = args[0];
44  		boolean includeMpxConfig = true;
45  		if (args.length >= 2) {
46  			includeMpxConfig = Boolean.parseBoolean(args[1]);
47  		}
48  
49  		try {
50  			List<Class<?>> configClasses = getAnnotatedClasses(includeMpxConfig);
51  			List<String> configIds = new ArrayList<String>(JdbcConfigConstants.DEFAULT_CONFIG_IDS);
52  			configIds.add(KualiImpexProducerConfig.SCHEMA_SQL.getConfigId());
53  			if (includeMpxConfig) {
54  				configIds.add(KualiImpexProducerConfig.MPX_SQL.getConfigId());
55  			}
56  
57  			Properties overrides = PropertyUtils.load(propertiesLocation);
58  			PropertiesSupplier supplier = new ConfigPropertiesSupplier(configIds, new DefaultConfigService(), overrides);
59  			SpringExecutable executable = SpringUtils.getSpringExecutable(supplier, configClasses);
60  			executable.execute();
61  		} catch (Exception e) {
62  			e.printStackTrace();
63  		}
64  
65  	}
66  
67  	protected static List<Class<?>> getAnnotatedClasses(boolean includeMpxConfig) {
68  		if (includeMpxConfig) {
69  			return CollectionUtils.asList(MpxSupplierConfig.class, SchemaXmlSupplierConfig.class, SqlControllerExecutableConfig.class);
70  		} else {
71  			return CollectionUtils.asList(SchemaXmlSupplierConfig.class, SqlControllerExecutableConfig.class);
72  		}
73  	}
74  
75  	protected static void printHelpAndExit() {
76  		System.out.println("Expects at least one argument, first a property file location.");
77  		System.out.println("Optionally, a second argument will be interpreted as whether or not to include configuration for Mpx files (default is true)");
78  		System.exit(1);
79  	}
80  
81  }