KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.*;
23 import java.util.Arrays JavaDoc;
24
25 import org.netbeans.modules.dbschema.*;
26
27 public class ForeignKeyElementImpl extends KeyElementImpl implements ForeignKeyElement.Impl {
28
29     private TableElementImpl tei;
30
31     public ForeignKeyElementImpl() {
32         this(null, null);
33     }
34
35     public ForeignKeyElementImpl(TableElementImpl tei, String JavaDoc name) {
36         super(name);
37
38         this.tei = tei;
39     }
40
41     protected DBElementsCollection initializeCollection() {
42         return new DBElementsCollection(this, new ColumnPairElement[0]);
43     }
44   
45     public ColumnPairElement[] getColumnPairs() {
46         DBElement[] dbe = getColumnCollection().getElements();
47         return (ColumnPairElement[]) Arrays.asList(dbe).toArray(new ColumnPairElement[dbe.length]);
48     }
49     
50     public ColumnPairElement getColumnPair(DBIdentifier name) {
51         return (ColumnPairElement) getColumnCollection().find(name);
52     }
53     
54     public void changeColumnPairs(ColumnPairElement[] pairs,int action) throws DBException {
55         getColumnCollection().changeElements(pairs, action);
56     }
57     
58     public ColumnElement[] getColumns() {
59         ColumnPairElement[] cpe = getColumnPairs();
60         
61         if (cpe == null || cpe.length == 0)
62             return null;
63         
64         ColumnElement[] ce = new ColumnElement[cpe.length];
65         
66         for (int i = 0; i < cpe.length; i++) {
67             String JavaDoc localColumn = cpe[i].getName().getFullName();
68             int pos = localColumn.indexOf(";");
69             localColumn = localColumn.substring(0, pos);
70
71             ce[i] = ((ForeignKeyElement) element).getDeclaringTable().getColumn(DBIdentifier.create(localColumn));
72         }
73         
74         return ce;
75     }
76     
77     public ColumnElement getColumn(DBIdentifier name) {
78         ColumnPairElement[] cpe = getColumnPairs();
79         
80         if (cpe == null || cpe.length == 0)
81             return null;
82         
83         for (int i = 0; i < cpe.length; i++) {
84             String JavaDoc localColumn = cpe[i].getName().getFullName();
85             int pos = localColumn.indexOf(";");
86             localColumn = localColumn.substring(0, pos);
87
88             if (name.getName().equals(DBIdentifier.create(localColumn).getName())) //need to check
89
return ((ForeignKeyElement) element).getDeclaringTable().getColumn(name);
90         }
91         
92         return null;
93     }
94     
95 }
96
Popular Tags