001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
006: * Contact: sequoia@continuent.org
007: *
008: * Licensed under the Apache License, Version 2.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: * Initial developer(s): Emmanuel Cecchet.
021: * Contributor(s): ______________________________________.
022: */package org.continuent.sequoia.common.sql.schema;
023:
024: import java.io.Serializable;
025:
026: /**
027: * An <code>AliasedDatabaseTable</code> represents a database table with an
028: * alias name. Example:
029: *
030: * <pre>
031: * SELECT x.price FROM item x
032: * </pre>
033: *
034: * <p>
035: * In this case, the <code>item</code> table has an alias named <code>x</code>.
036: *
037: * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet</a>
038: * @version 1.0
039: */
040: public class AliasedDatabaseTable implements Serializable {
041: private static final long serialVersionUID = 7082201367853814224L;
042:
043: /** Database table. */
044: private DatabaseTable table;
045:
046: /** Alias name or <code>null</code> if no alias is defined. */
047: private String alias;
048:
049: /**
050: * Creates a new <code>AliasedDatabaseTable</code> instance.
051: *
052: * @param table a <code>DatabaseTable</code> value
053: * @param alias the alias name, <code>null</code> if no alias is defined
054: */
055: public AliasedDatabaseTable(DatabaseTable table, String alias) {
056: if (table == null)
057: throw new IllegalArgumentException(
058: "Illegal null database table in AliasedDatabaseTable constructor");
059:
060: this .table = table;
061: this .alias = alias;
062: }
063:
064: /**
065: * Returns the <code>DatabaseTable</code> object corresponding to this
066: * database.
067: *
068: * @return a <code>DatabaseTable</code> value
069: */
070: public DatabaseTable getTable() {
071: return table;
072: }
073:
074: /**
075: * Gets the alias name.
076: *
077: * @return the alias name. Returns <code>null</code> if no alias is set.
078: */
079: public String getAlias() {
080: return alias;
081: }
082:
083: /**
084: * Two <code>AliasedDatabaseTable</code> are considered equal if they
085: * represent the same table and have the same alias.
086: *
087: * @param other the object to compare with
088: * @return true if the 2 objects are the same
089: */
090: public boolean equals(Object other) {
091: if ((other == null) || !(other instanceof AliasedDatabaseTable))
092: return false;
093:
094: AliasedDatabaseTable ad = (AliasedDatabaseTable) other;
095: if (alias == null)
096: return (ad.getAlias() == null)
097: && table.equals(ad.getTable());
098: else
099: return alias.equals(ad.getAlias())
100: && table.equals(ad.getTable());
101: }
102: }
|