KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > sql > SqlBinOpOuterJoin


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.extractor.sql;
24
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 public class SqlBinOpOuterJoin extends SqlBinaryOperator
29 {
30
31     private static final String JavaDoc RCSRevision = "$Revision: 1.5 $";
32     private static final String JavaDoc RCSName = "$Name: $";
33
34
35
36     public static final int LEFT_OUTER_jOIN = 0;
37     public static final int RIGHT_OUTER_jOIN = 0;
38
39     protected int _outerJoinType ;
40     protected List JavaDoc _predicateList;
41
42     /**
43     @roseuid 3BD17C0503E3
44      */

45     public SqlBinOpOuterJoin() {
46     }
47
48
49     public SqlBinOpOuterJoin(SqlExpression leftOperand, SqlExpression rightOperand, int outerJoinType, List JavaDoc predicateList)
50     {
51         super (leftOperand, rightOperand);
52         setOuterJoinType(outerJoinType);
53         setPredicateList(predicateList);
54     }
55
56     public int getOuterJoinType() {
57         return _outerJoinType;
58     }
59
60     public void setOuterJoinType(int outerJoinType) {
61         _outerJoinType = outerJoinType;
62     }
63
64     public List JavaDoc getPredicateList()
65     {
66         return _predicateList;
67     }
68
69
70     public void setPredicateList(List JavaDoc predicateList)
71     {
72         _predicateList = predicateList;
73     }
74
75     public String JavaDoc toSql (Context context)
76     {
77         //Trace.enter(this,"toSql(Context context)");
78

79         StringBuffer JavaDoc retVal = new StringBuffer JavaDoc();
80
81         retVal.append(getLeftOperand().toSql(context));
82
83         if ( getOuterJoinType() == Constants.LEFT_OUTER_JOIN ) {
84             retVal.append(" LEFT OUTER JOIN ");
85         }
86         else {
87             retVal.append(" RIGHT OUTER JOIN ");
88         }
89
90         retVal.append(getRightOperand().toSql(context));
91
92         retVal.append(" ON ");
93
94         predicteListToSql(retVal, context);
95
96         //Trace.exit(this,"toSql(Context context)");
97
return retVal.toString();
98     }
99
100     protected StringBuffer JavaDoc predicteListToSql(StringBuffer JavaDoc statementBuffer, Context context) {
101         //Trace.enter(this, "predicteListToSql(StringBuffer statementBuffer, Context context)");
102

103         Iterator JavaDoc tmpItr = null;
104         if ( null != _predicateList)
105         {
106             tmpItr = _predicateList.iterator();
107             while (tmpItr.hasNext()) {
108                 statementBuffer.append('(');
109                 statementBuffer.append(((SqlExpression)tmpItr.next()).toSql(context));
110                 statementBuffer.append(") AND ");
111             }
112             statementBuffer.setLength(statementBuffer.length() - 5);
113         }
114
115         //Trace.exit(this, "predicteListToSql(StringBuffer statementBuffer, Context context)");
116
return statementBuffer;
117     }
118 }
119
Popular Tags