1 |
|
package org.kuali.db; |
2 |
|
|
3 |
|
import java.io.IOException; |
4 |
|
import java.io.InputStreamReader; |
5 |
|
import java.io.Reader; |
6 |
|
import java.util.Properties; |
7 |
|
|
8 |
|
import org.apache.commons.io.IOUtils; |
9 |
|
import org.springframework.core.io.DefaultResourceLoader; |
10 |
|
import org.springframework.core.io.Resource; |
11 |
|
import org.springframework.util.PropertyPlaceholderHelper; |
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
|
|
| 0% |
Uncovered Elements: 72 (72) |
Complexity: 25 |
Complexity Density: 0.54 |
|
17 |
|
public class SQLGenerator { |
18 |
|
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}"); |
19 |
|
JDBCUtils jdbcUtils = new JDBCUtils(); |
20 |
|
DefaultResourceLoader loader = new DefaultResourceLoader(); |
21 |
|
String encoding; |
22 |
|
Properties properties; |
23 |
|
String url; |
24 |
|
DatabaseCommand command; |
25 |
|
String prefix = "classpath:org/kuali/db/"; |
26 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
27 |
0
|
public SQLGenerator() {... |
28 |
0
|
this(null, null, null); |
29 |
|
} |
30 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
31 |
0
|
public SQLGenerator(Properties properties, String url, DatabaseCommand command) {... |
32 |
0
|
super(); |
33 |
0
|
this.properties = properties; |
34 |
0
|
this.url = url; |
35 |
0
|
this.command = command; |
36 |
|
} |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
0
|
protected String getSQLLocation() {... |
39 |
0
|
return getLocation("/" + getPackageFriendlyName(command.toString()) + ".sql"); |
40 |
|
} |
41 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
42 |
0
|
public String getSQL() throws IOException {... |
43 |
0
|
String location = getSQLLocation(); |
44 |
0
|
Resource resource = loader.getResource(location); |
45 |
0
|
String sql = IOUtils.toString(resource.getInputStream(), getEncoding()); |
46 |
0
|
Properties customProperties = getCustomProperties(); |
47 |
0
|
if (properties != null) { |
48 |
0
|
customProperties.putAll(properties); |
49 |
|
} |
50 |
0
|
sql = helper.replacePlaceholders(sql, customProperties); |
51 |
0
|
return sql; |
52 |
|
} |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
0
|
protected String getPackageFriendlyName(String s) {... |
55 |
0
|
return s.toLowerCase().replace("_", ""); |
56 |
|
} |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
58 |
0
|
protected String getLocation(String suffix) {... |
59 |
0
|
JDBCConfiguration jdbcConfiguration = jdbcUtils.getDatabaseConfiguration(url); |
60 |
0
|
DatabaseType type = jdbcConfiguration.getType(); |
61 |
0
|
String packageFriendlyName = getPackageFriendlyName(type.toString()); |
62 |
0
|
String location = prefix + packageFriendlyName + suffix; |
63 |
0
|
return location; |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0
|
protected String getCustomPropertiesLocation() {... |
67 |
0
|
return getLocation("/custom.properties"); |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
70 |
0
|
protected Properties getCustomProperties() throws IOException {... |
71 |
0
|
String location = getCustomPropertiesLocation(); |
72 |
0
|
Reader input = null; |
73 |
0
|
try { |
74 |
0
|
Resource resource = loader.getResource(location); |
75 |
0
|
input = new InputStreamReader(resource.getInputStream(), getEncoding()); |
76 |
0
|
Properties p = new Properties(); |
77 |
0
|
p.load(input); |
78 |
0
|
return p; |
79 |
|
} finally { |
80 |
0
|
IOUtils.closeQuietly(input); |
81 |
|
} |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
0
|
public String getEncoding() {... |
85 |
0
|
return encoding; |
86 |
|
} |
87 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
0
|
public void setEncoding(String encoding) {... |
89 |
0
|
this.encoding = encoding; |
90 |
|
} |
91 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
0
|
public Properties getProperties() {... |
93 |
0
|
return properties; |
94 |
|
} |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
0
|
public void setProperties(Properties properties) {... |
97 |
0
|
this.properties = properties; |
98 |
|
} |
99 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
0
|
public String getUrl() {... |
101 |
0
|
return url; |
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
0
|
public void setUrl(String url) {... |
105 |
0
|
this.url = url; |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
0
|
public DatabaseCommand getCommand() {... |
109 |
0
|
return command; |
110 |
|
} |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
0
|
public void setCommand(DatabaseCommand command) {... |
113 |
0
|
this.command = command; |
114 |
|
} |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
0
|
public PropertyPlaceholderHelper getHelper() {... |
117 |
0
|
return helper; |
118 |
|
} |
119 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
120 |
0
|
public void setHelper(PropertyPlaceholderHelper helper) {... |
121 |
0
|
this.helper = helper; |
122 |
|
} |
123 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
0
|
public JDBCUtils getJdbcUtils() {... |
125 |
0
|
return jdbcUtils; |
126 |
|
} |
127 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
0
|
public void setJdbcUtils(JDBCUtils jdbcUtils) {... |
129 |
0
|
this.jdbcUtils = jdbcUtils; |
130 |
|
} |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
0
|
public DefaultResourceLoader getLoader() {... |
133 |
0
|
return loader; |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0
|
public void setLoader(DefaultResourceLoader loader) {... |
137 |
0
|
this.loader = loader; |
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
0
|
public String getPrefix() {... |
141 |
0
|
return prefix; |
142 |
|
} |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
144 |
0
|
public void setPrefix(String prefix) {... |
145 |
0
|
this.prefix = prefix; |
146 |
|
} |
147 |
|
|
148 |
|
} |