1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.config.JdbcProjectConstants;
28 import org.kuali.common.jdbc.supplier.LocationSupplier;
29 import org.kuali.common.jdbc.supplier.LocationSupplierContext;
30 import org.kuali.common.jdbc.supplier.LocationSupplierSourceBean;
31 import org.kuali.common.jdbc.supplier.LocationSuppliersFactoryBean;
32 import org.kuali.common.jdbc.supplier.SqlLocationSupplier;
33 import org.kuali.common.jdbc.supplier.SqlSupplier;
34 import org.kuali.common.util.nullify.NullUtils;
35 import org.kuali.common.util.project.ProjectService;
36 import org.kuali.common.util.project.ProjectUtils;
37 import org.kuali.common.util.project.model.Project;
38 import org.kuali.common.util.project.spring.ProjectServiceConfig;
39 import org.kuali.common.util.spring.SpringUtils;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.context.annotation.Bean;
42 import org.springframework.context.annotation.Configuration;
43 import org.springframework.context.annotation.Import;
44 import org.springframework.core.env.ConfigurableEnvironment;
45
46
47
48
49 @Configuration
50 @Import({ ProjectServiceConfig.class })
51 @Deprecated
52 public class JdbcCommonConfig {
53
54 protected final static String CONTEXT_KEY_SUFFIX = ".context";
55
56 @Autowired
57 ConfigurableEnvironment env;
58
59 @Autowired
60 ProjectServiceConfig projectServiceConfig;
61
62 @Bean
63 public SqlReader jdbcSqlReader() {
64 return new DefaultSqlReader();
65 }
66
67 @Bean
68 public JdbcService jdbcService() {
69 return new DefaultJdbcService();
70 }
71
72 @Bean
73 public Map<String, LocationSupplierSourceBean> jdbcExtensionMappings() {
74
75 ProjectService service = projectServiceConfig.projectService();
76
77 Project project = service.getProject(JdbcProjectConstants.PROJECT_IDENTIFIER);
78
79 SqlLocationSupplier sls = new SqlLocationSupplier();
80 sls.setReader(jdbcSqlReader());
81 sls.setEncoding(ProjectUtils.getEncoding(project));
82
83 LocationSupplierSourceBean lssb = new LocationSupplierSourceBean();
84 lssb.setSupplierClass(SqlLocationSupplier.class);
85 lssb.setSupplierInstance(sls);
86
87 Map<String, LocationSupplierSourceBean> map = new HashMap<String, LocationSupplierSourceBean>();
88 map.put("sql", lssb);
89 return map;
90 }
91
92 public List<SqlSupplier> getSqlSuppliers(String propertyKey) {
93 String contextValue = SpringUtils.getProperty(env, propertyKey + CONTEXT_KEY_SUFFIX, NullUtils.NONE);
94 LocationSupplierContext context = new LocationSupplierContext();
95 context.setValue(contextValue);
96
97 LocationSuppliersFactoryBean factory = new LocationSuppliersFactoryBean();
98 factory.setPropertyKey(propertyKey);
99 factory.setEnv(env);
100 factory.setExtensionMappings(jdbcExtensionMappings());
101 factory.setContext(context);
102 List<LocationSupplier> list = factory.getObject();
103 return new ArrayList<SqlSupplier>(list);
104 }
105 }