KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > revolt > definition > Table


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.revolt.definition;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 /**
31  * @author Felix Gnass [fgnass at neteye dot de]
32  *
33  */

34 public class Table extends Identifier {
35
36     private List JavaDoc columns = new ArrayList JavaDoc();
37
38     private List JavaDoc primaryKeys = new ArrayList JavaDoc();
39     
40     private List JavaDoc foreignKeys = new ArrayList JavaDoc();
41     
42     private List JavaDoc uniqueConstraints = new ArrayList JavaDoc();
43     
44     private List JavaDoc indices = new ArrayList JavaDoc();
45
46     public Table() {
47     }
48
49     public Table(String JavaDoc name) {
50         super(name);
51     }
52     
53     public Table(String JavaDoc name, List JavaDoc columns) {
54         super(name);
55         setColumns(columns);
56     }
57
58     public List JavaDoc getColumns() {
59         return this.columns;
60     }
61
62     public void setColumns(List JavaDoc columns) {
63         this.columns = new ArrayList JavaDoc(columns.size());
64         primaryKeys.clear();
65         if (columns != null) {
66             Iterator JavaDoc it = columns.iterator();
67             while (it.hasNext()) {
68                 Column column = (Column) it.next();
69                 Column copy = column.copy();
70                 this.columns.add(copy);
71                 if (column.isPrimaryKey()) {
72                     primaryKeys.add(copy);
73                 }
74             }
75         }
76     }
77
78     public void addColumn(Column column) {
79         columns.remove(column);
80         primaryKeys.remove(column);
81         Column copy = column.copy();
82         columns.add(copy);
83         if (column.isPrimaryKey()) {
84             primaryKeys.add(copy);
85         }
86     }
87
88     public void removeColumn(String JavaDoc name) {
89         columns.remove(new Identifier(name));
90     }
91     
92     public Column getColumn(String JavaDoc name) {
93         return (Column) columns.get(columns.indexOf(new Identifier(name)));
94     }
95     
96     public List JavaDoc getPrimaryKeys() {
97         return this.primaryKeys;
98     }
99     
100     public void addIndex(Index index) {
101         indices.remove(index);
102         indices.add(index);
103     }
104     
105     public void removeIndex(String JavaDoc name) {
106         indices.remove(new Index(name));
107     }
108     
109     public void addForeignKey(ForeignKey fk) {
110         foreignKeys.remove(fk);
111         foreignKeys.add(fk);
112     }
113     
114     public void removeForeignKey(String JavaDoc name) {
115         foreignKeys.remove(new ForeignKey(name));
116     }
117     
118     public void addUniqueConstraint(UniqueConstraint uc) {
119         uniqueConstraints.remove(uc);
120         uniqueConstraints.add(uc);
121     }
122     
123     public void removeUniqueConstraint(String JavaDoc uc) {
124         uniqueConstraints.remove(new UniqueConstraint(uc));
125     }
126
127     public List JavaDoc getForeignKeys() {
128         return this.foreignKeys;
129     }
130
131     public List JavaDoc getIndices() {
132         return this.indices;
133     }
134
135     public List JavaDoc getUniqueConstraints() {
136         return this.uniqueConstraints;
137     }
138     
139 }
140
Popular Tags