01: package org.apache.torque.engine.database.model;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 473814 2006-11-11 22:30:30Z tv $
34: */
35: public class Unique extends Index {
36: /**
37: * Returns <code>true</code>.
38: *
39: * @return true
40: */
41: public final boolean isUnique() {
42: return true;
43: }
44:
45: /**
46: * String representation of the index. This is an xml representation.
47: *
48: * @return string representation in xml
49: */
50: public String toString() {
51: StringBuffer result = new StringBuffer();
52: result.append(" <unique name=\"").append(getName()).append(
53: "\">\n");
54:
55: List columns = getColumns();
56: for (int i = 0; i < columns.size(); i++) {
57: result.append(" <unique-column name=\"").append(
58: columns.get(i)).append("\"/>\n");
59: }
60: result.append(" </unique>\n");
61: return result.toString();
62: }
63: }
|