1 17 package org.apache.ws.jaxme.sqls.impl; 18 19 import org.apache.ws.jaxme.sqls.Column; 20 import org.apache.ws.jaxme.sqls.ColumnReference; 21 import org.apache.ws.jaxme.sqls.TableReference; 22 23 24 28 public class ColumnReferenceImpl implements ColumnReference { 29 private TableReference tableReference; 30 private Column column; 31 private Column.Name alias; 32 33 protected ColumnReferenceImpl(TableReference pTableReference, Column pColumn) { 34 if (pTableReference == null) { 35 throw new NullPointerException ("The referenced table must not be null."); 36 } 37 if (pColumn == null) { 38 throw new NullPointerException ("The referenced column must not be null."); 39 } 40 if (!pTableReference.getTable().equals(pColumn.getTable())) { 41 throw new IllegalStateException ("The columns table is not the referenced table."); 42 } 43 tableReference = pTableReference; 44 column = pColumn; 45 } 46 47 public TableReference getTableReference() { 48 return tableReference; 49 } 50 51 public Column getColumn() { 52 return column; 53 } 54 55 public void setAlias(String pName) { 56 setAlias(new ColumnImpl.NameImpl(pName)); 57 } 58 59 public void setAlias(Column.Name pName) { 60 alias = pName; 61 } 62 63 public Column.Name getAlias() { 64 return alias; 65 } 66 67 public boolean equals(Object o) { 68 if (o == null || !(o instanceof ColumnReference)) { 69 return false; 70 } 71 ColumnReference ref = (ColumnReference) o; 72 Column c1 = ref.getColumn(); 73 Column c2 = getColumn(); 74 if (c1 == null || c2 == null) { 75 return super.equals(o); 76 } 77 TableReference t1 = ref.getTableReference(); 78 TableReference t2 = ref.getTableReference(); 79 if (t1 == null || t2 == null) { 80 return super.equals(o); 81 } 82 return t1.equals(t2) && c1.equals(c2); 83 } 84 85 public int hashCode() { 86 return getTableReference().hashCode() + getColumn().hashCode(); 87 } 88 } 89 | Popular Tags |