1 package org.apache.torque.engine.database.model;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. 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,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.List;
23
24 /**
25 * Information about unique columns of a table. This class assumes
26 * that in the underlying RDBMS, unique constraints and unique indices
27 * are roughly equivalent. For example, adding a unique constraint to
28 * a column also creates an index on that column (this is known to be
29 * true for MySQL and Oracle).
30 *
31 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
32 * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
33 * @version $Id: Unique.java,v 1.1 2007-10-21 07:57:27 abyrne Exp $
34 */
35 public class Unique extends Index
36 {
37 /**
38 * Returns <code>true</code>.
39 *
40 * @return true
41 */
42 public final boolean isUnique()
43 {
44 return true;
45 }
46
47 /**
48 * String representation of the index. This is an xml representation.
49 *
50 * @return string representation in xml
51 */
52 public String toString()
53 {
54 StringBuffer result = new StringBuffer();
55 result.append(" <unique name=\"")
56 .append(getName())
57 .append("\">\n");
58
59 List columns = getColumns();
60 for (int i = 0; i < columns.size(); i++)
61 {
62 result.append(" <unique-column name=\"")
63 .append(columns.get(i))
64 .append("\"/>\n");
65 }
66 result.append(" </unique>\n");
67 return result.toString();
68 }
69 }