KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > sql > JoinFragment


1 //$Id: JoinFragment.java,v 1.4 2005/03/07 12:31:22 pgmjsd Exp $
2
package org.hibernate.sql;
3
4 import org.hibernate.util.StringHelper;
5
6 /**
7  * An abstract SQL join fragment renderer
8  *
9  * @author Gavin King
10  */

11 public abstract class JoinFragment {
12
13     public abstract void addJoin(String JavaDoc tableName, String JavaDoc alias, String JavaDoc[] fkColumns, String JavaDoc[] pkColumns, int joinType);
14
15     public abstract void addJoin(String JavaDoc tableName, String JavaDoc alias, String JavaDoc[] fkColumns, String JavaDoc[] pkColumns, int joinType, String JavaDoc on);
16
17     public abstract void addCrossJoin(String JavaDoc tableName, String JavaDoc alias);
18
19     public abstract void addJoins(String JavaDoc fromFragment, String JavaDoc whereFragment);
20
21     public abstract String JavaDoc toFromFragmentString();
22
23     public abstract String JavaDoc toWhereFragmentString();
24
25     // --Commented out by Inspection (12/4/04 9:10 AM): public abstract void addCondition(String alias, String[] columns, String condition);
26
public abstract void addCondition(String JavaDoc alias, String JavaDoc[] fkColumns, String JavaDoc[] pkColumns);
27
28     public abstract boolean addCondition(String JavaDoc condition);
29     // --Commented out by Inspection (12/4/04 9:10 AM): public abstract void addFromFragmentString(String fromFragmentString);
30

31     public abstract JoinFragment copy();
32
33     public static final int INNER_JOIN = 0;
34     public static final int FULL_JOIN = 4;
35     public static final int LEFT_OUTER_JOIN = 1;
36     public static final int RIGHT_OUTER_JOIN = 2;
37
38     private boolean hasFilterCondition = false;
39     private boolean hasThetaJoins = false;
40
41     public void addFragment(JoinFragment ojf) {
42         if ( ojf.hasThetaJoins() ) {
43             hasThetaJoins = true;
44         }
45         addJoins( ojf.toFromFragmentString(), ojf.toWhereFragmentString() );
46     }
47
48     /**
49      * Appends the 'on' condition to the buffer, returning true if the condition was added.
50      * Returns false if the 'on' condition was empty.
51      *
52      * @param buffer The buffer to append the 'on' condition to.
53      * @param on The 'on' condition.
54      * @return Returns true if the condition was added, false if the condition was already in 'on' string.
55      */

56     protected boolean addCondition(StringBuffer JavaDoc buffer, String JavaDoc on) {
57         if ( StringHelper.isNotEmpty( on ) ) {
58             if ( !on.startsWith( " and" ) ) buffer.append( " and " );
59             buffer.append( on );
60             return true;
61         }
62         else {
63             return false;
64         }
65     }
66
67     /**
68      * True if the where fragment is from a filter condition.
69      *
70      * @return True if the where fragment is from a filter condition.
71      */

72     public boolean hasFilterCondition() {
73         return hasFilterCondition;
74     }
75
76     public void setHasFilterCondition(boolean b) {
77         this.hasFilterCondition = b;
78     }
79
80     public boolean hasThetaJoins() {
81         return hasThetaJoins;
82     }
83
84     public void setHasThetaJoins(boolean hasThetaJoins) {
85         this.hasThetaJoins = hasThetaJoins;
86     }
87 }
88
Popular Tags