KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > sqls > impl > AbstractColumn


1 /*
2  * Copyright 2003, 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.sqls.impl;
18
19 import org.apache.ws.jaxme.sqls.BinaryColumn;
20 import org.apache.ws.jaxme.sqls.Column;
21 import org.apache.ws.jaxme.sqls.StringColumn;
22 import org.apache.ws.jaxme.sqls.Table;
23
24 /**
25  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
26  */

27 public abstract class AbstractColumn implements Column, StringColumn, BinaryColumn {
28   private final Column.Name name;
29   private final Column.Type type;
30   private boolean nullable;
31   private Long JavaDoc length;
32   private Object JavaDoc customData;
33
34   protected AbstractColumn(Column.Name pName, Column.Type pType) {
35     if (pName == null) {
36       throw new NullPointerException JavaDoc("The column name must not be null.");
37     }
38     if (pType == null) {
39       throw new NullPointerException JavaDoc("The column type must not be null.");
40     }
41     name = pName;
42     type = pType;
43   }
44
45   public Column.Name getName() { return name; }
46   public Column.Type getType() { return type; }
47   public boolean isNullable() { return nullable; }
48   public void setNullable(boolean pNullable) { nullable = pNullable; }
49
50
51   public boolean equals(Object JavaDoc o) {
52     if (o == null || !(o instanceof Column)) {
53       return false;
54     }
55     Column other = (Column) o;
56     Table table = getTable();
57     if (table == null) {
58       if (other.getTable() != null) {
59         return false;
60       }
61     } else {
62       if (!table.equals(other.getTable())) {
63         return false;
64       }
65     }
66     return getName().equals(other.getName());
67   }
68
69   public int hashCode() {
70     return getTable().hashCode() + getName().hashCode();
71   }
72
73   public boolean hasFixedLength() {
74     Column.Type myType = getType();
75     if (Column.Type.CHAR.equals(myType) ||
76         Column.Type.BINARY.equals(myType)) {
77       return true;
78     } else if (Column.Type.VARCHAR.equals(myType)
79                || Column.Type.VARBINARY.equals(myType)
80                || Column.Type.BLOB.equals(myType)
81                || Column.Type.OTHER.equals(myType)
82                || Column.Type.CLOB.equals(myType)) {
83       return false;
84     } else {
85       throw new IllegalStateException JavaDoc("Invalid data type for fixed length.");
86     }
87   }
88
89   public boolean isStringColumn() {
90     Column.Type myType = getType();
91     return Column.Type.CHAR.equals(myType) || Column.Type.VARCHAR.equals(myType) ||
92             Column.Type.CLOB.equals(myType);
93   }
94
95   public boolean isBinaryColumn() {
96     Column.Type myType = getType();
97     return Column.Type.BINARY.equals(myType) || Column.Type.VARBINARY.equals(myType) ||
98             Column.Type.BLOB.equals(myType) || Column.Type.OTHER.equals(myType);
99   }
100
101   public void setLength(Long JavaDoc pLength) {
102     length = pLength;
103   }
104
105   public void setLength(long pLength) {
106     setLength(new Long JavaDoc(pLength));
107   }
108
109   public Long JavaDoc getLength() {
110     return length;
111   }
112
113   public Object JavaDoc getCustomData() {
114     return customData;
115   }
116
117   public void setCustomData(Object JavaDoc pCustomData) {
118     customData = pCustomData;
119   }
120 }
121
Popular Tags