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.spring;
17  
18  import java.io.IOException;
19  import java.util.HashMap;
20  import java.util.Map;
21  import javax.xml.bind.JAXBException;
22  
23  import org.kuali.common.impex.data.SqlProducer;
24  import org.kuali.common.impex.data.impl.MpxLocationSupplier;
25  import org.kuali.common.impex.data.impl.mysql.MySqlProducer;
26  import org.kuali.common.impex.data.impl.oracle.OracleProducer;
27  import org.kuali.common.jdbc.spring.JdbcCommonConfig;
28  import org.kuali.common.jdbc.spring.JdbcDataSourceConfig;
29  import org.kuali.common.jdbc.supplier.LocationSupplierSourceBean;
30  import org.kuali.common.util.spring.SpringUtils;
31  import org.springframework.beans.factory.annotation.Autowired;
32  import org.springframework.context.annotation.Bean;
33  import org.springframework.context.annotation.Configuration;
34  import org.springframework.context.annotation.Import;
35  import org.springframework.core.env.Environment;
36  
37  @Configuration
38  @Import({ JdbcCommonConfig.class, BatchConfig.class, JdbcDataSourceConfig.class, XmlSchemaConfig.class })
39  public class MpxSupplierConfig {
40  
41      @Autowired
42      Environment env;
43  
44      @Autowired
45      JdbcCommonConfig jdbcCommonConfig;
46  
47      @Autowired
48      JdbcDataSourceConfig dataSourceConfig;
49  
50      @Autowired
51      BatchConfig batchConfig;
52  
53      @Autowired
54      XmlSchemaConfig modelProviderConfig;
55  
56      private static final String DB_VENDOR_KEY = "db.vendor";
57  
58      @Bean
59      Map<String, SqlProducer> vendorProducerMap() {
60          Map<String, SqlProducer> results = new HashMap<String, SqlProducer>();
61  
62          results.put(OracleProducer.SUPPORTED_VENDOR, configureProducer(new OracleProducer()));
63          results.put(MySqlProducer.SUPPORTED_VENDOR, configureProducer(new MySqlProducer()));
64  
65          return results;
66      }
67  
68      private SqlProducer configureProducer(SqlProducer sqlProducer) {
69  
70          sqlProducer.setBatchDataSizeLimit(batchConfig.impexBatchSize());
71          sqlProducer.setBatchRowCountLimit(batchConfig.impexBatchRows());
72  
73          return sqlProducer;
74      }
75  
76      @Bean
77      public SqlProducer impexProducer() {
78          String vendor = SpringUtils.getProperty(env, DB_VENDOR_KEY);
79  
80          return vendorProducerMap().get(vendor);
81      }
82  
83      @Bean
84      public Map<String, LocationSupplierSourceBean> impexExtensionMappings() throws JAXBException, IOException {
85          // This gets cloned for each .mpx file
86          MpxLocationSupplier mls = new MpxLocationSupplier();
87          mls.setSchema(modelProviderConfig.schema());
88          mls.setProducer(impexProducer());
89  
90          // This hands out clones of MpxLocationSupplier, one for every .mpx file being parsed
91          LocationSupplierSourceBean lssb = new LocationSupplierSourceBean();
92          lssb.setSupplierClass(MpxLocationSupplier.class);
93          lssb.setSupplierInstance(mls);
94  
95          // Add mpx as an extension JDBC can handle
96          Map<String, LocationSupplierSourceBean> mappings = jdbcCommonConfig.jdbcExtensionMappings();
97          mappings.put("mpx", lssb);
98          return mappings;
99      }
100 
101 }