KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > jdbcimpl > KeyElementImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.dbschema.jdbcimpl;
21
22 import java.util.*;
23
24 import org.netbeans.modules.dbschema.*;
25
26 public abstract class KeyElementImpl extends DBMemberElementImpl implements KeyElement.Impl {
27     private DBElementsCollection columns;
28
29     /** Creates new KeyElementImpl */
30     public KeyElementImpl() {
31     }
32
33     /** Creates new KeyElementImpl with the specified name */
34     public KeyElementImpl (String JavaDoc name) {
35         super(name);
36         columns = initializeCollection();
37
38         //workaround for bug #4396371
39
//http://andorra.eng:8080/cgi-bin/ws.exe/bugtraq/bug.hts?where=bugid_value%3D4396371
40
Object JavaDoc hc = String.valueOf(columns.hashCode());
41         while (DBElementsCollection.instances.contains(hc)) {
42             columns = initializeCollection();
43             hc = String.valueOf(columns.hashCode());
44         }
45         DBElementsCollection.instances.add(hc);
46     }
47
48     protected DBElementsCollection initializeCollection() {
49         return new DBElementsCollection(this, new ColumnElement[0]);
50     }
51
52     /** Change the set of columns.
53      * @param elems the columns to change
54      * @param action one of {@link #ADD}, {@link #REMOVE}, or {@link #SET}
55      * @exception DBException if the action cannot be handled
56      */

57     public void changeColumns(ColumnElement[] elems,int action) throws DBException {
58         columns.changeElements(elems, action);
59     }
60
61     /** Get all columns.
62      * @return the columns
63      */

64     public ColumnElement[] getColumns() {
65         DBElement[] dbe = columns.getElements();
66         return (ColumnElement[]) Arrays.asList(dbe).toArray(new ColumnElement[dbe.length]);
67     }
68   
69     /** Find a column by name.
70      * @param name the name for which to look
71      * @return the column, or <code>null</code> if it does not exist
72      */

73     public ColumnElement getColumn(DBIdentifier name) {
74         return (ColumnElement) columns.find(name);
75     }
76
77     /** Returns the table collection of this schema element. This method
78      * should only be used internally and for cloning and archiving.
79      * @return the table collection of this schema element
80      */

81     public DBElementsCollection getColumnCollection () {
82         return columns;
83     }
84
85     /** Set the table collection of this claschemass element to the supplied
86      * collection. This method should only be used internally and for
87      * cloning and archiving.
88      * @param collection the table collection of this schema element
89      */

90     public void setColumnCollection (DBElementsCollection collection) {
91         columns = collection;
92     }
93 }
94
Popular Tags