1 package org.hibernate.sql; 3 4 5 11 public class Sybase11JoinFragment extends JoinFragment { 12 13 private StringBuffer afterFrom = new StringBuffer (); 14 private StringBuffer afterWhere = new StringBuffer (); 15 16 public void addJoin(String tableName, String alias, String [] fkColumns, String [] pkColumns, int joinType) { 17 18 addCrossJoin(tableName, alias); 19 20 for ( int j=0; j<fkColumns.length; j++) { 21 if (joinType==JoinFragment.FULL_JOIN ) throw new UnsupportedOperationException (); 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 toFromFragmentString() { 41 return afterFrom.toString(); 42 } 43 44 public String toWhereFragmentString() { 45 return afterWhere.toString(); 46 } 47 48 public void addJoins(String fromFragment, String 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 ( afterFrom.toString() ); 56 copy.afterWhere = new StringBuffer ( afterWhere.toString() ); 57 return copy; 58 } 59 60 public void addCondition(String alias, String [] columns, String 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 tableName, String alias) { 71 afterFrom.append(", ") 72 .append(tableName) 73 .append(' ') 74 .append(alias); 75 } 76 77 public void addCondition(String alias, String [] fkColumns, String [] pkColumns) { 78 throw new UnsupportedOperationException (); 79 80 } 81 82 public boolean addCondition(String condition) { 83 return addCondition(afterWhere, condition); 84 } 85 86 87 public void addFromFragmentString(String fromFragmentString) { 88 afterFrom.append(fromFragmentString); 89 } 90 91 92 public void addJoin(String tableName, String alias, String [] fkColumns, String [] pkColumns, int joinType, String on) { 93 addJoin(tableName, alias, fkColumns, pkColumns, joinType); 94 addCondition(on); 95 } 96 } 97 98 99 | Popular Tags |