1 package org.apache.torque.engine.database.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 473814 2006-11-11 22:30:30Z tv $
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 }