1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.sql.spring;
17
18 import java.util.List;
19
20 import javax.sql.DataSource;
21
22 import org.kuali.common.jdbc.model.context.JdbcContext;
23 import org.kuali.common.jdbc.reset.DefaultJdbcResetConfig;
24 import org.kuali.common.jdbc.service.spring.DataSourceConfig;
25 import org.kuali.common.jdbc.sql.spring.DbaContextConfig;
26 import org.kuali.common.jdbc.sql.spring.JdbcContextsConfig;
27 import org.kuali.common.jdbc.suppliers.ResourcesSupplierFactory;
28 import org.kuali.common.jdbc.suppliers.SqlSupplier;
29 import org.kuali.common.jdbc.suppliers.spring.SuppliersFactoryConfig;
30 import org.kuali.common.jdbc.vendor.model.DatabaseVendor;
31 import org.kuali.common.util.metainf.service.MetaInfUtils;
32 import org.kuali.common.util.metainf.spring.MetaInfGroup;
33 import org.kuali.common.util.project.ProjectService;
34 import org.kuali.common.util.project.model.Project;
35 import org.kuali.common.util.project.spring.ProjectServiceConfig;
36 import org.kuali.rice.sql.project.SqlProjectConstants;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.context.annotation.Bean;
39 import org.springframework.context.annotation.Configuration;
40 import org.springframework.context.annotation.Import;
41
42 import com.google.common.collect.ImmutableList;
43
44
45
46
47
48
49
50 @Configuration
51 @Import({ DbaContextConfig.class, SuppliersFactoryConfig.class, ProjectServiceConfig.class, DefaultJdbcResetConfig.class })
52 public class SourceSqlConfig implements JdbcContextsConfig {
53
54 @Autowired
55 DbaContextConfig dba;
56
57 @Autowired
58 ResourcesSupplierFactory factory;
59
60 @Autowired
61 ProjectService projectService;
62
63 @Autowired
64 DatabaseVendor vendor;
65
66 @Autowired
67 DataSourceConfig dataSources;
68
69 @Bean
70 public Project riceSqlProject() {
71 return projectService.getProject(SqlProjectConstants.ID);
72 }
73
74 @Override
75 @Bean
76 public List<JdbcContext> jdbcContexts() {
77 JdbcContext before = dba.dbaBeforeContext();
78 JdbcContext schema = getJdbcContext(MetaInfGroup.SCHEMA, true);
79 JdbcContext data = getJdbcContext(MetaInfGroup.DATA, true);
80 JdbcContext constraints = getJdbcContext(MetaInfGroup.CONSTRAINTS, true);
81 JdbcContext other = getJdbcContext(MetaInfGroup.OTHER, false);
82 JdbcContext after = dba.dbaAfterContext();
83 return ImmutableList.of(before, schema, data, constraints, other, after);
84 }
85
86 protected JdbcContext getJdbcContext(MetaInfGroup group, boolean multithreaded) {
87 String resourcesLocation = MetaInfUtils.getClasspathResource(riceSqlProject(), vendor.getCode(), group);
88 List<SqlSupplier> suppliers = factory.getSuppliers(resourcesLocation);
89 DataSource dataSource = dataSources.dataSource();
90 String message = "[" + group.name().toLowerCase() + ":" + (multithreaded ? "concurrent" : "sequential") + "]";
91 return new JdbcContext.Builder(dataSource, suppliers).message(message).multithreaded(multithreaded).build();
92 }
93 }