KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > sql > schema > AliasedDatabaseTable


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
6  * Contact: sequoia@continuent.org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * Initial developer(s): Emmanuel Cecchet.
21  * Contributor(s): ______________________________________.
22  */

23
24 package org.continuent.sequoia.controller.sql.schema;
25
26 import java.io.Serializable JavaDoc;
27
28 /**
29  * An <code>AliasedDatabaseTable</code> represents a database table with an
30  * alias name. Example:
31  *
32  * <pre>
33  * SELECT x.price FROM item x
34  * </pre>
35  *
36  * <p>
37  * In this case, the <code>item</code> table has an alias named <code>x</code>.
38  *
39  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet</a>
40  * @version 1.0
41  */

42 public class AliasedDatabaseTable implements Serializable JavaDoc
43 {
44   private static final long serialVersionUID = 7082201367853814224L;
45
46   /** Database table. */
47   private DatabaseTable table;
48
49   /** Alias name or <code>null</code> if no alias is defined. */
50   private String JavaDoc alias;
51
52   /**
53    * Creates a new <code>AliasedDatabaseTable</code> instance.
54    *
55    * @param table a <code>DatabaseTable</code> value
56    * @param alias the alias name, <code>null</code> if no alias is defined
57    */

58   public AliasedDatabaseTable(DatabaseTable table, String JavaDoc alias)
59   {
60     if (table == null)
61       throw new IllegalArgumentException JavaDoc(
62           "Illegal null database table in AliasedDatabaseTable constructor");
63
64     this.table = table;
65     this.alias = alias;
66   }
67
68   /**
69    * Returns the <code>DatabaseTable</code> object corresponding to this
70    * database.
71    *
72    * @return a <code>DatabaseTable</code> value
73    */

74   public DatabaseTable getTable()
75   {
76     return table;
77   }
78
79   /**
80    * Gets the alias name.
81    *
82    * @return the alias name. Returns <code>null</code> if no alias is set.
83    */

84   public String JavaDoc getAlias()
85   {
86     return alias;
87   }
88
89   /**
90    * Two <code>AliasedDatabaseTable</code> are considered equal if they
91    * represent the same table and have the same alias.
92    *
93    * @param other the object to compare with
94    * @return true if the 2 objects are the same
95    */

96   public boolean equals(Object JavaDoc other)
97   {
98     if ((other == null) || !(other instanceof AliasedDatabaseTable))
99       return false;
100
101     AliasedDatabaseTable ad = (AliasedDatabaseTable) other;
102     if (alias == null)
103       return (ad.getAlias() == null) && table.equals(ad.getTable());
104     else
105       return alias.equals(ad.getAlias()) && table.equals(ad.getTable());
106   }
107 }
108
Popular Tags