001 package org.apache.torque.engine.database.model;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. 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,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.util.List;
023
024 /**
025 * Information about unique columns of a table. This class assumes
026 * that in the underlying RDBMS, unique constraints and unique indices
027 * are roughly equivalent. For example, adding a unique constraint to
028 * a column also creates an index on that column (this is known to be
029 * true for MySQL and Oracle).
030 *
031 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
032 * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
033 * @version $Id: Unique.java,v 1.1 2007-10-21 07:57:27 abyrne Exp $
034 */
035 public class Unique extends Index
036 {
037 /**
038 * Returns <code>true</code>.
039 *
040 * @return true
041 */
042 public final boolean isUnique()
043 {
044 return true;
045 }
046
047 /**
048 * String representation of the index. This is an xml representation.
049 *
050 * @return string representation in xml
051 */
052 public String toString()
053 {
054 StringBuffer result = new StringBuffer();
055 result.append(" <unique name=\"")
056 .append(getName())
057 .append("\">\n");
058
059 List columns = getColumns();
060 for (int i = 0; i < columns.size(); i++)
061 {
062 result.append(" <unique-column name=\"")
063 .append(columns.get(i))
064 .append("\"/>\n");
065 }
066 result.append(" </unique>\n");
067 return result.toString();
068 }
069 }