01: //$Id: JoinFragment.java 6034 2005-03-07 12:31:37Z pgmjsd $
02: package org.hibernate.sql;
03:
04: import org.hibernate.util.StringHelper;
05:
06: /**
07: * An abstract SQL join fragment renderer
08: *
09: * @author Gavin King
10: */
11: public abstract class JoinFragment {
12:
13: public abstract void addJoin(String tableName, String alias,
14: String[] fkColumns, String[] pkColumns, int joinType);
15:
16: public abstract void addJoin(String tableName, String alias,
17: String[] fkColumns, String[] pkColumns, int joinType,
18: String on);
19:
20: public abstract void addCrossJoin(String tableName, String alias);
21:
22: public abstract void addJoins(String fromFragment,
23: String whereFragment);
24:
25: public abstract String toFromFragmentString();
26:
27: public abstract String toWhereFragmentString();
28:
29: // --Commented out by Inspection (12/4/04 9:10 AM): public abstract void addCondition(String alias, String[] columns, String condition);
30: public abstract void addCondition(String alias, String[] fkColumns,
31: String[] pkColumns);
32:
33: public abstract boolean addCondition(String condition);
34:
35: // --Commented out by Inspection (12/4/04 9:10 AM): public abstract void addFromFragmentString(String fromFragmentString);
36:
37: public abstract JoinFragment copy();
38:
39: public static final int INNER_JOIN = 0;
40: public static final int FULL_JOIN = 4;
41: public static final int LEFT_OUTER_JOIN = 1;
42: public static final int RIGHT_OUTER_JOIN = 2;
43:
44: private boolean hasFilterCondition = false;
45: private boolean hasThetaJoins = false;
46:
47: public void addFragment(JoinFragment ojf) {
48: if (ojf.hasThetaJoins()) {
49: hasThetaJoins = true;
50: }
51: addJoins(ojf.toFromFragmentString(), ojf
52: .toWhereFragmentString());
53: }
54:
55: /**
56: * Appends the 'on' condition to the buffer, returning true if the condition was added.
57: * Returns false if the 'on' condition was empty.
58: *
59: * @param buffer The buffer to append the 'on' condition to.
60: * @param on The 'on' condition.
61: * @return Returns true if the condition was added, false if the condition was already in 'on' string.
62: */
63: protected boolean addCondition(StringBuffer buffer, String on) {
64: if (StringHelper.isNotEmpty(on)) {
65: if (!on.startsWith(" and"))
66: buffer.append(" and ");
67: buffer.append(on);
68: return true;
69: } else {
70: return false;
71: }
72: }
73:
74: /**
75: * True if the where fragment is from a filter condition.
76: *
77: * @return True if the where fragment is from a filter condition.
78: */
79: public boolean hasFilterCondition() {
80: return hasFilterCondition;
81: }
82:
83: public void setHasFilterCondition(boolean b) {
84: this .hasFilterCondition = b;
85: }
86:
87: public boolean hasThetaJoins() {
88: return hasThetaJoins;
89: }
90:
91: public void setHasThetaJoins(boolean hasThetaJoins) {
92: this.hasThetaJoins = hasThetaJoins;
93: }
94: }
|