KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > sqls > impl > TableReferenceImpl


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.sqls.impl;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.apache.ws.jaxme.sqls.Column;
23 import org.apache.ws.jaxme.sqls.ColumnReference;
24 import org.apache.ws.jaxme.sqls.Statement;
25 import org.apache.ws.jaxme.sqls.Table;
26 import org.apache.ws.jaxme.sqls.TableReference;
27
28
29 /** <p>Implementation of a {@link org.apache.ws.jaxme.sqls.TableReference}.</p>
30  *
31  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
32  */

33 public class TableReferenceImpl implements TableReference {
34    private Statement statement;
35    private Table table;
36    private Table.Name alias;
37    private List JavaDoc columnReferences = new ArrayList JavaDoc();
38
39     /** <p>Creates a new instance of TableReference.</p>
40      */

41     TableReferenceImpl(Statement pStatement, Table pTable) {
42       statement = pStatement;
43       table = pTable;
44     }
45
46     public Statement getStatement() {
47       return statement;
48     }
49
50     public Table getTable() {
51       return table;
52     }
53
54     public Table.Name getAlias() {
55       return alias;
56     }
57
58     public void setAlias(Table.Name pName) {
59       alias = pName;
60     }
61
62     public void setAlias(String JavaDoc pName) {
63       setAlias(new TableImpl.NameImpl(pName));
64     }
65
66     public ColumnReference newColumnReference(String JavaDoc pName) {
67       return newColumnReference(new ColumnImpl.NameImpl(pName));
68     }
69
70     public ColumnReference newColumnReference(Column.Name pName) {
71       Column column = getTable().getColumn(pName);
72       if (column == null) {
73          throw new NullPointerException JavaDoc("Unknown column name in table " + getTable().getName() +
74                                          ": " + pName);
75       }
76       return newColumnReference(column);
77     }
78
79     public ColumnReference newColumnReference(Column pColumn) {
80       ColumnReference columnReference = getStatement().getSQLFactory().getObjectFactory().newColumnReference(this, pColumn);
81       columnReferences.add(columnReference);
82       return columnReference;
83     }
84
85    public boolean equals(Object JavaDoc o) {
86       if (o == null || !(o instanceof TableReference)) {
87          return false;
88       }
89       TableReference ref = (TableReference) o;
90       return ref.getStatement().equals(getStatement()) &&
91              ref.getTable().equals(getTable());
92    }
93
94    public int hashCode() {
95       return getStatement().hashCode() + getTable().hashCode();
96    }
97 }
98
Popular Tags