KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: ConditionFragment.java,v 1.2 2004/08/10 05:06:13 oneovthafew Exp $
2
package org.hibernate.sql;
3
4 import org.hibernate.util.ArrayHelper;
5
6 /**
7  * @author Gavin King
8  */

9 public class ConditionFragment {
10     private String JavaDoc tableAlias;
11     private String JavaDoc[] lhs;
12     private String JavaDoc[] rhs;
13     private String JavaDoc op = "=";
14
15     /**
16      * Sets the op.
17      * @param op The op to set
18      */

19     public ConditionFragment setOp(String JavaDoc op) {
20         this.op = op;
21         return this;
22     }
23
24     /**
25      * Sets the tableAlias.
26      * @param tableAlias The tableAlias to set
27      */

28     public ConditionFragment setTableAlias(String JavaDoc tableAlias) {
29         this.tableAlias = tableAlias;
30         return this;
31     }
32
33     public ConditionFragment setCondition(String JavaDoc[] lhs, String JavaDoc[] rhs) {
34         this.lhs = lhs;
35         this.rhs = rhs;
36         return this;
37     }
38
39     public ConditionFragment setCondition(String JavaDoc[] lhs, String JavaDoc rhs) {
40         this.lhs = lhs;
41         this.rhs = ArrayHelper.fillArray(rhs, lhs.length);
42         return this;
43     }
44
45     public String JavaDoc toFragmentString() {
46         StringBuffer JavaDoc buf = new StringBuffer JavaDoc( lhs.length * 10 );
47         for ( int i=0; i<lhs.length; i++ ) {
48             buf.append(tableAlias)
49                 .append('.')
50                 .append( lhs[i] )
51                 .append(op)
52                 .append( rhs[i] );
53             if (i<lhs.length-1) buf.append(" and ");
54         }
55         return buf.toString();
56     }
57
58 }
59
Popular Tags