Clover Coverage Report - JDBC Support Utilities 1.0.24-SNAPSHOT
Coverage timestamp: Tue Oct 4 2011 20:45:01 EDT
../../../img/srcFileCovDistChart0.png 8% of files have more coverage
46   148   25   1.92
2   115   0.54   24
24     1.04  
1    
 
  SQLGenerator       Line # 17 46 0% 25 72 0% 0.0
 
No Tests
 
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    */
 
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   
 
27  0 toggle public SQLGenerator() {
28  0 this(null, null, null);
29    }
30   
 
31  0 toggle 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   
 
38  0 toggle protected String getSQLLocation() {
39  0 return getLocation("/" + getPackageFriendlyName(command.toString()) + ".sql");
40    }
41   
 
42  0 toggle 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   
 
54  0 toggle protected String getPackageFriendlyName(String s) {
55  0 return s.toLowerCase().replace("_", "");
56    }
57   
 
58  0 toggle 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   
 
66  0 toggle protected String getCustomPropertiesLocation() {
67  0 return getLocation("/custom.properties");
68    }
69   
 
70  0 toggle 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   
 
84  0 toggle public String getEncoding() {
85  0 return encoding;
86    }
87   
 
88  0 toggle public void setEncoding(String encoding) {
89  0 this.encoding = encoding;
90    }
91   
 
92  0 toggle public Properties getProperties() {
93  0 return properties;
94    }
95   
 
96  0 toggle public void setProperties(Properties properties) {
97  0 this.properties = properties;
98    }
99   
 
100  0 toggle public String getUrl() {
101  0 return url;
102    }
103   
 
104  0 toggle public void setUrl(String url) {
105  0 this.url = url;
106    }
107   
 
108  0 toggle public DatabaseCommand getCommand() {
109  0 return command;
110    }
111   
 
112  0 toggle public void setCommand(DatabaseCommand command) {
113  0 this.command = command;
114    }
115   
 
116  0 toggle public PropertyPlaceholderHelper getHelper() {
117  0 return helper;
118    }
119   
 
120  0 toggle public void setHelper(PropertyPlaceholderHelper helper) {
121  0 this.helper = helper;
122    }
123   
 
124  0 toggle public JDBCUtils getJdbcUtils() {
125  0 return jdbcUtils;
126    }
127   
 
128  0 toggle public void setJdbcUtils(JDBCUtils jdbcUtils) {
129  0 this.jdbcUtils = jdbcUtils;
130    }
131   
 
132  0 toggle public DefaultResourceLoader getLoader() {
133  0 return loader;
134    }
135   
 
136  0 toggle public void setLoader(DefaultResourceLoader loader) {
137  0 this.loader = loader;
138    }
139   
 
140  0 toggle public String getPrefix() {
141  0 return prefix;
142    }
143   
 
144  0 toggle public void setPrefix(String prefix) {
145  0 this.prefix = prefix;
146    }
147   
148    }