KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
27  * @author Felix Gnass [fgnass at neteye dot de]
28  *
29  */

30 public class Column extends Identifier implements Cloneable JavaDoc {
31
32     private String JavaDoc type;
33
34     private int length;
35
36     private boolean lengthSet;
37
38     private String JavaDoc defaultValue;
39     
40     private boolean defaultValueSet;
41
42     private boolean notNull;
43     
44     private boolean notNullSet;
45
46     private boolean primaryKey;
47     
48     private boolean primaryKeySet;
49
50     private boolean autoIncrement;
51     
52     private boolean autoIncrementSet;
53
54     public Column() {
55     }
56     
57     public Column(String JavaDoc name) {
58         super(name);
59     }
60
61     public Column(String JavaDoc name, String JavaDoc type) {
62         super(name);
63         this.type = type;
64     }
65
66     public Column(String JavaDoc name, String JavaDoc type, int length) {
67         this(name, type);
68         setLength(length);
69     }
70
71     public boolean isAutoIncrement() {
72         return autoIncrement;
73     }
74
75     public void setAutoIncrement(boolean autoIncrement) {
76         this.autoIncrement = autoIncrement;
77         autoIncrementSet = true;
78     }
79     
80     public boolean isAutoIncrementSet() {
81         return this.autoIncrementSet;
82     }
83
84     public String JavaDoc getDefaultValue() {
85         return this.defaultValue;
86     }
87
88     public void setDefaultValue(String JavaDoc defaultValue) {
89         this.defaultValue = defaultValue;
90         defaultValueSet = true;
91     }
92
93     public boolean isDefaultValueSet() {
94         return this.defaultValueSet;
95     }
96
97     public int getLength() {
98         return this.length;
99     }
100
101     public void setLength(int length) {
102         this.length = length;
103         lengthSet = true;
104     }
105
106     public boolean isLengthSet() {
107         return this.lengthSet;
108     }
109
110     public boolean isNotNullSet() {
111         return notNullSet;
112     }
113
114     public boolean isNotNull() {
115         return notNull;
116     }
117
118     public void setNotNull(boolean notNull) {
119         this.notNull = notNull;
120         notNullSet = true;
121     }
122
123     public boolean isPrimaryKeySet() {
124         return primaryKeySet;
125     }
126
127     public boolean isPrimaryKey() {
128         return primaryKey;
129     }
130
131     public void setPrimaryKey(boolean primaryKey) {
132         this.primaryKey = primaryKey;
133         primaryKeySet = true;
134     }
135
136     public String JavaDoc getType() {
137         return this.type;
138     }
139
140     public void setType(String JavaDoc type) {
141         this.type = type;
142     }
143     
144     public Column copy() {
145         try {
146             return (Column) clone();
147         }
148         catch (CloneNotSupportedException JavaDoc e) {
149             throw new RuntimeException JavaDoc(e);
150         }
151     }
152     
153     public void merge(Column column) {
154         if (column.isDefaultValueSet()) {
155             setDefaultValue(column.getDefaultValue());
156         }
157         if (column.isNotNullSet()) {
158             setNotNull(column.isNotNull());
159         }
160         if (column.getType() != null) {
161             setType(column.getType());
162         }
163         if (column.isLengthSet()) {
164             setLength(column.getLength());
165         }
166         if (column.isAutoIncrementSet()) {
167             setAutoIncrement(column.isAutoIncrement());
168         }
169     }
170 }
171
Popular Tags