KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > tools > schemaframework > UniqueKeyConstraint


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.tools.schemaframework;
23
24 import java.io.*;
25 import java.util.*;
26 import oracle.toplink.essentials.exceptions.*;
27 import oracle.toplink.essentials.internal.sessions.AbstractSession;
28
29 /**
30  * <p>
31  * <b>Purpose</b>: Define a unique key constraint for a table.
32  */

33 public class UniqueKeyConstraint implements Serializable {
34     protected String JavaDoc name;
35     protected Vector sourceFields;
36
37     public UniqueKeyConstraint() {
38         this.name = "";
39         this.sourceFields = new Vector();
40     }
41
42     public UniqueKeyConstraint(String JavaDoc name, String JavaDoc sourceField) {
43         this();
44         this.name = name;
45         sourceFields.addElement(sourceField);
46     }
47
48     public void addSourceField(String JavaDoc sourceField) {
49         getSourceFields().addElement(sourceField);
50     }
51
52     /**
53      * INTERNAL:
54      * Append the database field definition string to the table creation statement.
55      */

56     public void appendDBString(Writer writer, AbstractSession session) {
57         try {
58             writer.write("UNIQUE (");
59             for (Enumeration sourceEnum = getSourceFields().elements();
60                      sourceEnum.hasMoreElements();) {
61                 writer.write((String JavaDoc)sourceEnum.nextElement());
62                 if (sourceEnum.hasMoreElements()) {
63                     writer.write(", ");
64                 }
65             }
66             writer.write(")");
67         } catch (IOException ioException) {
68             throw ValidationException.fileError(ioException);
69         }
70     }
71
72     public String JavaDoc getName() {
73         return name;
74     }
75
76     public Vector getSourceFields() {
77         return sourceFields;
78     }
79
80     public void setName(String JavaDoc name) {
81         this.name = name;
82     }
83
84     /**
85      * PUBLIC:
86      * Enables delete cascading on the database.
87      * This must be used carefully, i.e. only private relationships.
88      */

89     public void setSourceFields(Vector sourceFields) {
90         this.sourceFields = sourceFields;
91     }
92 }
93
94
Popular Tags