KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > engine > database > model > Unique


1 package org.apache.torque.engine.database.model;
2
3 /*
4  * Copyright 2001,2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.util.List JavaDoc;
20
21 /**
22  * Information about unique columns of a table. This class assumes
23  * that in the underlying RDBMS, unique constraints and unique indices
24  * are roughly equivalent. For example, adding a unique constraint to
25  * a column also creates an index on that column (this is known to be
26  * true for MySQL and Oracle).
27  *
28  * @author <a HREF="mailto:jvanzyl@apache.org">Jason van Zyl</a>
29  * @author <a HREF="mailto:dlr@collab.net">Daniel Rall</a>
30  * @version $Id: Unique.java,v 1.2 2004/02/22 06:27:19 jmcnally Exp $
31  */

32 public class Unique extends Index
33 {
34     /**
35      * Returns <code>true</code>.
36      *
37      * @return true
38      */

39     public final boolean isUnique()
40     {
41         return true;
42     }
43
44     /**
45      * String representation of the index. This is an xml representation.
46      *
47      * @return string representation in xml
48      */

49     public String JavaDoc toString()
50     {
51         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
52         result.append(" <unique name=\"")
53             .append(getName())
54             .append("\">\n");
55
56         List JavaDoc columns = getColumns();
57         for (int i = 0; i < columns.size(); i++)
58         {
59             result.append(" <unique-column name=\"")
60                 .append(columns.get(i))
61                 .append("\"/>\n");
62         }
63         result.append(" </unique>\n");
64         return result.toString();
65     }
66 }
67
Popular Tags