KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: Sybase11JoinFragment.java,v 1.3 2004/12/05 15:04:20 pgmjsd Exp $
2
package org.hibernate.sql;
3
4
5 /**
6  * An old Sybase-style join (before Sybase supported the ANSI style "inner join" etc syntax)
7  * This is needed for Sybase 11.9.2 and earlier, using the HQL 2.* syntax with Collections.
8  *
9  * @author Colm O' Flaherty
10  */

11 public class Sybase11JoinFragment extends JoinFragment {
12
13     private StringBuffer JavaDoc afterFrom = new StringBuffer JavaDoc();
14     private StringBuffer JavaDoc afterWhere = new StringBuffer JavaDoc();
15
16     public void addJoin(String JavaDoc tableName, String JavaDoc alias, String JavaDoc[] fkColumns, String JavaDoc[] pkColumns, int joinType) {
17
18         addCrossJoin(tableName, alias);
19
20         for ( int j=0; j<fkColumns.length; j++) {
21             //full joins are not supported.. yet!
22
if (joinType==JoinFragment.FULL_JOIN ) throw new UnsupportedOperationException JavaDoc();
23
24             afterWhere.append(" and ")
25                 .append( fkColumns[j] )
26                 .append( " " );
27
28             if (joinType==LEFT_OUTER_JOIN ) afterWhere.append("*");
29             afterWhere.append('=');
30             if (joinType==RIGHT_OUTER_JOIN ) afterWhere.append("*");
31
32             afterWhere.append (" ")
33                 .append(alias)
34                 .append('.')
35                 .append( pkColumns[j] );
36         }
37
38     }
39
40     public String JavaDoc toFromFragmentString() {
41         return afterFrom.toString();
42     }
43
44     public String JavaDoc toWhereFragmentString() {
45         return afterWhere.toString();
46     }
47
48     public void addJoins(String JavaDoc fromFragment, String JavaDoc whereFragment) {
49         afterFrom.append(fromFragment);
50         afterWhere.append(whereFragment);
51     }
52
53     public JoinFragment copy() {
54         Sybase11JoinFragment copy = new Sybase11JoinFragment();
55         copy.afterFrom = new StringBuffer JavaDoc( afterFrom.toString() );
56         copy.afterWhere = new StringBuffer JavaDoc( afterWhere.toString() );
57         return copy;
58     }
59
60     public void addCondition(String JavaDoc alias, String JavaDoc[] columns, String JavaDoc condition) {
61         for ( int i=0; i<columns.length; i++ ) {
62             afterWhere.append(" and ")
63                 .append(alias)
64                 .append('.')
65                 .append( columns[i] )
66                 .append(condition);
67         }
68     }
69
70     public void addCrossJoin(String JavaDoc tableName, String JavaDoc alias) {
71         afterFrom.append(", ")
72             .append(tableName)
73             .append(' ')
74             .append(alias);
75     }
76
77     public void addCondition(String JavaDoc alias, String JavaDoc[] fkColumns, String JavaDoc[] pkColumns) {
78         throw new UnsupportedOperationException JavaDoc();
79
80     }
81
82     public boolean addCondition(String JavaDoc condition) {
83         return addCondition(afterWhere, condition);
84     }
85
86
87     public void addFromFragmentString(String JavaDoc fromFragmentString) {
88         afterFrom.append(fromFragmentString);
89     }
90
91
92     public void addJoin(String JavaDoc tableName, String JavaDoc alias, String JavaDoc[] fkColumns, String JavaDoc[] pkColumns, int joinType, String JavaDoc on) {
93         addJoin(tableName, alias, fkColumns, pkColumns, joinType);
94         addCondition(on);
95     }
96 }
97
98
99
Popular Tags