00001 /** 00002 * C-JDBC: Clustered JDBC. 00003 * Copyright (C) 2002-2004 French National Institute For Research In Computer 00004 * Science And Control (INRIA). 00005 * Contact: c-jdbc@objectweb.org 00006 * 00007 * This library is free software; you can redistribute it and/or modify it 00008 * under the terms of the GNU Lesser General Public License as published by the 00009 * Free Software Foundation; either version 2.1 of the License, or any later 00010 * version. 00011 * 00012 * This library is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 00015 * for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with this library; if not, write to the Free Software Foundation, 00019 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00020 * 00021 * Initial developer(s): Emmanuel Cecchet. 00022 * Contributor(s): ______________________________________. 00023 */ 00024 00025 package org.objectweb.cjdbc.common.sql.schema; 00026 00027 import java.io.Serializable; 00028 00029 /** 00030 * An <code>AliasedDatabaseTable</code> represents a database table with an 00031 * alias name. Example: 00032 * 00033 * <pre> 00034 * SELECT x.price FROM item x 00035 * </pre> 00036 * 00037 * 00038 * <p> 00039 * In this case, the <code>item</code> table has an alias named <code>x</code>. 00040 * 00041 * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet</a> 00042 * @version 1.0 00043 */ 00044 public class AliasedDatabaseTable implements Serializable 00045 { 00046 /** Database table. */ 00047 private DatabaseTable table; 00048 00049 /** Alias name or <code>null</code> if no alias is defined. */ 00050 private String alias; 00051 00052 /** 00053 * Creates a new <code>AliasedDatabaseTable</code> instance. 00054 * 00055 * @param table a <code>DatabaseTable</code> value 00056 * @param alias the alias name, <code>null</code> if no alias is defined 00057 */ 00058 public AliasedDatabaseTable(DatabaseTable table, String alias) 00059 { 00060 if (table == null) 00061 throw new IllegalArgumentException("Illegal null database table in AliasedDatabaseTable constructor"); 00062 00063 this.table = table; 00064 this.alias = alias; 00065 } 00066 00067 /** 00068 * Returns the <code>DatabaseTable</code> object corresponding to this 00069 * database. 00070 * 00071 * @return a <code>DatabaseTable</code> value 00072 */ 00073 public DatabaseTable getTable() 00074 { 00075 return table; 00076 } 00077 00078 /** 00079 * Gets the alias name. 00080 * 00081 * @return the alias name. Returns <code>null</code> if no alias is set. 00082 */ 00083 public String getAlias() 00084 { 00085 return alias; 00086 } 00087 00088 /** 00089 * Two <code>AliasedDatabaseTable</code> are considered equal if they 00090 * represent the same table and have the same alias. 00091 * 00092 * @param other the object to compare with 00093 * @return true if the 2 objects are the same 00094 */ 00095 public boolean equals(Object other) 00096 { 00097 if ((other == null) || !(other instanceof AliasedDatabaseTable)) 00098 return false; 00099 00100 AliasedDatabaseTable ad = (AliasedDatabaseTable) other; 00101 if (alias == null) 00102 return (ad.getAlias() == null) && table.equals(ad.getTable()); 00103 else 00104 return alias.equals(ad.getAlias()) && table.equals(ad.getTable()); 00105 } 00106 }