1 24 25 package com.mckoi.database; 26 27 import java.util.ArrayList ; 28 29 42 43 public final class JoiningSet implements java.io.Serializable , Cloneable { 44 45 static final long serialVersionUID = -380871062550922402L; 46 47 50 public final static int INNER_JOIN = 1; 52 public final static int LEFT_OUTER_JOIN = 2; 54 public final static int RIGHT_OUTER_JOIN = 3; 56 public final static int FULL_OUTER_JOIN = 4; 58 59 63 private ArrayList join_set; 64 65 68 public JoiningSet() { 69 join_set = new ArrayList (); 70 } 71 72 78 public void prepare(DatabaseConnection connection) { 79 } 80 81 85 public void addTable(TableName table_name) { 86 join_set.add(table_name); 87 } 88 89 93 public void addPreviousJoin(int type, Expression on_expression) { 94 join_set.add(join_set.size() - 1, new JoinPart(type, on_expression)); 95 } 96 97 100 public void addJoin(int type, Expression on_expression) { 101 join_set.add(new JoinPart(type, on_expression)); 102 } 103 104 107 public void addJoin(int type) { 108 join_set.add(new JoinPart(type)); 109 } 110 111 114 public int getTableCount() { 115 return (join_set.size() + 1) / 2; 116 } 117 118 121 public TableName getFirstTable() { 122 return getTable(0); 123 } 124 125 129 public TableName getTable(int n) { 130 return (TableName) join_set.get(n * 2); 131 } 132 133 136 private void setTable(int n, TableName table) { 137 join_set.set(n * 2, table); 138 } 139 140 154 public int getJoinType(int n) { 155 return ((JoinPart) join_set.get((n * 2) + 1)).type; 156 } 157 158 162 public Expression getOnExpression(int n) { 163 return ((JoinPart) join_set.get((n * 2) + 1)).on_expression; 164 } 165 166 169 public Object clone() throws CloneNotSupportedException { 170 JoiningSet v = (JoiningSet) super.clone(); 171 int size = join_set.size(); 172 ArrayList cloned_join_set = new ArrayList (size); 173 v.join_set = cloned_join_set; 174 175 for (int i = 0; i < size; ++i) { 176 Object element = join_set.get(i); 177 if (element instanceof TableName) { 178 } 180 else if (element instanceof JoinPart) { 181 element = ((JoinPart) element).clone(); 182 } 183 else { 184 throw new CloneNotSupportedException (element.getClass().toString()); 185 } 186 cloned_join_set.add(element); 187 } 188 189 return v; 190 } 191 192 193 194 196 public static class JoinPart implements java.io.Serializable , Cloneable { 197 198 static final long serialVersionUID = -1664565759669808084L; 199 200 204 int type; 205 206 211 Expression on_expression; 212 213 216 public JoinPart(int type, Expression on_expression) { 217 this.type = type; 218 this.on_expression = on_expression; 219 } 220 221 public JoinPart(int type) { 222 this(type, null); 223 } 224 225 public Object clone() throws CloneNotSupportedException { 226 JoinPart v = (JoinPart) super.clone(); 227 if (on_expression != null) { 228 v.on_expression = (Expression) on_expression.clone(); 229 } 230 return v; 231 } 232 233 } 234 235 } 236 | Popular Tags |