01: package jimm.datavision.source.ncsql;
02:
03: import jimm.datavision.Report;
04: import jimm.datavision.source.sql.SQLQuery;
05: import jimm.util.StringUtils;
06: import java.util.List;
07:
08: /**
09: * Queries build NC query strings. They contain tables, joins, and
10: * where clauses.
11: *
12: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
13: */
14: public class NCQuery extends SQLQuery {
15:
16: /**
17: * Constructor.
18: *
19: * @param report the report for which this query will generate NC
20: */
21: public NCQuery(Report report) {
22: super (report);
23: }
24:
25: /**
26: * Quotes those parts of a table or column name that need to be quoted.
27: * <p>
28: * Different databases and JDBC drivers treat case sensitively differently.
29: * We assume the database is case-sensitive.
30: *
31: * @param name a table or column name
32: * @return a quoted version of the name
33: */
34: public String quoted(String name) {
35: List components = StringUtils.split(name, ".");
36: int len = components.size();
37: for (int i = 0; i < len; ++i) {
38: String component = (String) components.get(i);
39: // Put quotes around the component if there is a space in the
40: // component or we have non-lower-case letters.
41: if (component.indexOf(" ") >= 0
42: || !component.equals(component.toLowerCase()))
43: components.set(i, "\"" + component + "\"");
44: }
45: return StringUtils.join(components, ".");
46: }
47:
48: }
|