KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > source > Join


1 package jimm.datavision.source;
2 import jimm.datavision.Writeable;
3 import jimm.util.XMLWriter;
4
5 /**
6  * A join represents the relationship between two columns in the database.
7  * It is used by a query to build the SQL string necessary to retrieve data.
8  *
9  * @see jimm.datavision.source.Query
10  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
11  */

12 public class Join implements Writeable, Cloneable JavaDoc {
13
14 public static final String JavaDoc[] RELATIONS = {
15     "=", "!=", "<", "<=", ">", ">=", "like", "not like", // "null", "not null",
16
"in", "not in"
17 };
18
19 protected Column from;
20 protected String JavaDoc relation;
21 protected Column to;
22
23 /**
24  * Constructor.
25  *
26  * @param fromCol a database column
27  * @param relation a string like "=" or "&lt;" used to join the two database
28  * columns
29  * @param toCol another database column
30  * @see Column
31  */

32 public Join(Column fromCol, String JavaDoc relation, Column toCol) {
33     from = fromCol;
34     this.relation = relation;
35     to = toCol;
36 }
37
38 public Object JavaDoc clone() {
39     return new Join(from, relation, to);
40 }
41
42 /**
43  * Returns the "from" column.
44  *
45  * @return a column
46  */

47 public Column getFrom() { return from; }
48
49 /**
50  * Sets the "from" column.
51  *
52  * @param newFrom the new column
53  */

54 public void setFrom(Column newFrom) { from = newFrom; }
55
56 /**
57  * Returns the relation string (for example, "=" or "&lt;").
58  *
59  * @return a string used to define the relationship between the two
60  * database columns
61  */

62 public String JavaDoc getRelation() { return relation; }
63
64 /**
65  * Sets the relation string (for example, "=" or "&lt;").
66  *
67  * @param newRelation the new string
68  */

69 public void setRelation(String JavaDoc newRelation) { relation = newRelation; }
70
71 /**
72  * Returns the "to" column.
73  *
74  * @return a column
75  */

76 public Column getTo() { return to; }
77
78 /**
79  * Sets the "to" column.
80  *
81  * @param newTo the new column
82  */

83 public void setTo(Column newTo) { to = newTo; }
84
85 /**
86  * Returns a string representation of this join, usable as a where
87  * clause in a SQL query.
88  */

89 public String JavaDoc toString() {
90     return from.fullName() + " " + relation + " " + to.fullName();
91 }
92
93 /**
94  * Writes this join as an XML tag.
95  *
96  * @param out a writer that knows how to write XML
97  */

98 public void writeXML(XMLWriter out) {
99     out.startElement("join");
100     out.attr("from", from.fullName());
101     out.attr("relation", relation);
102     out.attr("to", to.fullName());
103     out.endElement();
104 }
105
106 }
107
Popular Tags