KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > common > sql > schema > AliasedDatabaseTable


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): ______________________________________.
23  */

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

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

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

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

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

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