KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > source > ncsql > NCQuery


1 package jimm.datavision.source.ncsql;
2 import jimm.datavision.Report;
3 import jimm.datavision.source.sql.SQLQuery;
4 import jimm.util.StringUtils;
5 import java.util.List JavaDoc;
6
7 /**
8  * Queries build NC query strings. They contain tables, joins, and
9  * where clauses.
10  *
11  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
12  */

13 public class NCQuery extends SQLQuery {
14
15 /**
16  * Constructor.
17  *
18  * @param report the report for which this query will generate NC
19  */

20 public NCQuery(Report report) {
21     super(report);
22 }
23
24 /**
25  * Quotes those parts of a table or column name that need to be quoted.
26  * <p>
27  * Different databases and JDBC drivers treat case sensitively differently.
28  * We assume the database is case-sensitive.
29  *
30  * @param name a table or column name
31  * @return a quoted version of the name
32  */

33 public String JavaDoc quoted(String JavaDoc name) {
34     List JavaDoc components = StringUtils.split(name, ".");
35     int len = components.size();
36     for (int i = 0; i < len; ++i) {
37     String JavaDoc component = (String JavaDoc)components.get(i);
38     // Put quotes around the component if there is a space in the
39
// component or we have non-lower-case letters.
40
if (component.indexOf(" ") >= 0
41         || !component.equals(component.toLowerCase()))
42         components.set(i, "\"" + component + "\"");
43     }
44     return StringUtils.join(components, ".");
45 }
46
47 }
48
Popular Tags