1 package org.hibernate.sql; 3 4 import org.hibernate.util.ArrayHelper; 5 6 9 public class ConditionFragment { 10 private String tableAlias; 11 private String [] lhs; 12 private String [] rhs; 13 private String op = "="; 14 15 19 public ConditionFragment setOp(String op) { 20 this.op = op; 21 return this; 22 } 23 24 28 public ConditionFragment setTableAlias(String tableAlias) { 29 this.tableAlias = tableAlias; 30 return this; 31 } 32 33 public ConditionFragment setCondition(String [] lhs, String [] rhs) { 34 this.lhs = lhs; 35 this.rhs = rhs; 36 return this; 37 } 38 39 public ConditionFragment setCondition(String [] lhs, String rhs) { 40 this.lhs = lhs; 41 this.rhs = ArrayHelper.fillArray(rhs, lhs.length); 42 return this; 43 } 44 45 public String toFragmentString() { 46 StringBuffer buf = new StringBuffer ( 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 |