View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.jdbc.spring;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.kuali.common.jdbc.DefaultJdbcService;
24  import org.kuali.common.jdbc.DefaultSqlReader;
25  import org.kuali.common.jdbc.JdbcService;
26  import org.kuali.common.jdbc.SqlReader;
27  import org.kuali.common.jdbc.supplier.LocationSupplier;
28  import org.kuali.common.jdbc.supplier.LocationSupplierSourceBean;
29  import org.kuali.common.jdbc.supplier.LocationSuppliersFactoryBean;
30  import org.kuali.common.jdbc.supplier.SqlLocationSupplier;
31  import org.kuali.common.jdbc.supplier.SqlSupplier;
32  import org.kuali.common.util.Project;
33  import org.springframework.beans.factory.annotation.Autowired;
34  import org.springframework.context.annotation.Bean;
35  import org.springframework.context.annotation.Configuration;
36  import org.springframework.context.annotation.Import;
37  import org.springframework.core.env.ConfigurableEnvironment;
38  
39  @Configuration
40  @Import(JdbcProjectConfig.class)
41  public class JdbcCommonConfig {
42  
43  	@Autowired
44  	ConfigurableEnvironment env;
45  
46  	@Autowired
47  	JdbcProjectConfig projectConfig;
48  
49  	@Bean
50  	public SqlReader jdbcSqlReader() {
51  		return new DefaultSqlReader();
52  	}
53  
54  	@Bean
55  	public JdbcService jdbcService() {
56  		return new DefaultJdbcService();
57  	}
58  
59  	@Bean
60  	public Map<String, LocationSupplierSourceBean> jdbcExtensionMappings() {
61  		Project project = projectConfig.jdbcProject();
62  
63  		SqlLocationSupplier sls = new SqlLocationSupplier();
64  		sls.setReader(jdbcSqlReader());
65  		sls.setEncoding(project.getEncoding());
66  
67  		LocationSupplierSourceBean lssb = new LocationSupplierSourceBean();
68  		lssb.setSupplierClass(SqlLocationSupplier.class);
69  		lssb.setSupplierInstance(sls);
70  
71  		Map<String, LocationSupplierSourceBean> map = new HashMap<String, LocationSupplierSourceBean>();
72  		map.put("sql", lssb);
73  		return map;
74  	}
75  
76  	public List<SqlSupplier> getSqlSuppliers(String property) {
77  		LocationSuppliersFactoryBean factory = new LocationSuppliersFactoryBean();
78  		factory.setProperty(property);
79  		factory.setEnv(env);
80  		factory.setExtensionMappings(jdbcExtensionMappings());
81  		List<LocationSupplier> list = factory.getObject();
82  		return new ArrayList<SqlSupplier>(list);
83  	}
84  }