Revision 6458 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/FieldDescription.java

View differences:

FieldDescription.java
43 43
 */
44 44
package com.iver.cit.gvsig.fmap.drivers;
45 45

  
46
import java.sql.Types;
47

  
46 48
import com.hardcode.gdbms.engine.values.NullValue;
47 49
import com.hardcode.gdbms.engine.values.Value;
48 50

  
49 51
public class FieldDescription {
50
    /**
51
     * Internal field name.
52
     */
53
    private String fieldName;
54
    private String fieldAlias;
55
    private int fieldType;
56
    private Value defaultValue = new NullValue();
57
    /**
58
     * En campos num?ricos, numero de d?gitos a la izquierda del punto
59
     * En campos de texto, numero de caracteres.
60
     */
61
    private int fieldLength; 
62
    
63
    /**
64
     * En campos num?ricos, numero de d?gitos a la derecha del punto.
65
     */
66
    private int fieldDecimalCount;
67 52

  
68
    /**
69
     * @return Returns the fieldDecimalCount.
70
     */
71
    public int getFieldDecimalCount() {
72
        return fieldDecimalCount;
73
    }
53
	public static int stringToType(String strType) {
54
		int type = -1;
55
		if (strType.equals("String"))
56
			type = Types.VARCHAR;
57
		if (strType.equals("Double"))
58
			type = Types.DOUBLE;
59
		if (strType.equals("Integer"))
60
			type = Types.INTEGER;
61
		if (strType.equals("Boolean"))
62
			type = Types.BOOLEAN;
63
		if (strType.equals("Date"))
64
			type = Types.DATE;
74 65

  
75
    /**
76
     * @param fieldDecimalCount The fieldDecimalCount to set.
77
     */
78
    public void setFieldDecimalCount(int fieldDecimalCount) {
79
        this.fieldDecimalCount = fieldDecimalCount;
80
    }
66
		if (type == -1) {
67
			throw new RuntimeException("Type not recognized: " + strType);
68
		}
69
		return type;
81 70

  
82
    /**
83
     * @return Returns the fieldLength.
84
     */
85
    public int getFieldLength() {
86
        return fieldLength;
87
    }
71
	}
88 72

  
89
    /**
90
     * @param fieldLength The fieldLength to set.
91
     */
92
    public void setFieldLength(int fieldLength) {
93
        this.fieldLength = fieldLength;
94
    }
73
	public static String typeToString(int sqlType) {
74
		switch (sqlType) {
75
		case Types.NUMERIC:
76
		case Types.BIGINT:
77
			return "Integer";
95 78

  
96
    /**
97
     * @return Returns the fieldName.
98
     */
99
    public String getFieldName() {
100
        return fieldName;
101
    }
79
		case Types.BIT:
80
			return "Boolean";
102 81

  
103
    /**
104
     * @param fieldName The fieldName to set.
105
     */
106
    public void setFieldName(String fieldName) {
107
        this.fieldName = fieldName;
108
        this.fieldAlias = fieldName;
109
    }
82
		case Types.SMALLINT:
83
			return "Integer";
110 84

  
111
    /**
112
     * @return Returns the fieldType.
113
     */
114
    public int getFieldType() {
115
        return fieldType;
116
    }
85
		case Types.TINYINT:
86
			return "Integer";
117 87

  
118
    /**
119
     * @param fieldType The fieldType to set.
120
     */
121
    public void setFieldType(int fieldType) {
122
        this.fieldType = fieldType;
123
    }
88
		case Types.CHAR:
89
		case Types.VARCHAR:
90
		case Types.LONGVARCHAR:
91
			return "String";
124 92

  
93
		case Types.DATE:
94
			return "Date";
95

  
96
		case Types.FLOAT:
97
		case Types.DOUBLE:
98
		case Types.DECIMAL:
99
			return "Double";
100

  
101
		case Types.INTEGER:
102
			return "Integer";
103

  
104
		case Types.REAL:
105
			return "Double";
106

  
107
		case Types.BINARY:
108
		case Types.VARBINARY:
109
		case Types.LONGVARBINARY:
110
			return "Binary";
111

  
112
		case Types.TIMESTAMP:
113
			return "Timestamp";
114

  
115
		case Types.TIME:
116
			return "Time";
117

  
118
		case Types.OTHER:
119
		default:
120
			throw new RuntimeException("Type not recognized: " + sqlType);
121
		}		
122

  
123
	}
124

  
125
	/**
126
	 * Internal field name.
127
	 */
128
	private String fieldName;
129

  
130
	private String fieldAlias;
131

  
132
	private int fieldType;
133

  
134
	private Value defaultValue = new NullValue();
135

  
136
	/**
137
	 * En campos num?ricos, numero de d?gitos a la izquierda del punto En campos
138
	 * de texto, numero de caracteres.
139
	 */
140
	private int fieldLength;
141

  
142
	/**
143
	 * En campos num?ricos, numero de d?gitos a la derecha del punto.
144
	 */
145
	private int fieldDecimalCount;
146

  
147
	/**
148
	 * @return Returns the fieldDecimalCount.
149
	 */
150
	public int getFieldDecimalCount() {
151
		return fieldDecimalCount;
152
	}
153

  
154
	/**
155
	 * @param fieldDecimalCount
156
	 *            The fieldDecimalCount to set.
157
	 */
158
	public void setFieldDecimalCount(int fieldDecimalCount) {
159
		this.fieldDecimalCount = fieldDecimalCount;
160
	}
161

  
162
	/**
163
	 * @return Returns the fieldLength.
164
	 */
165
	public int getFieldLength() {
166
		return fieldLength;
167
	}
168

  
169
	/**
170
	 * @param fieldLength
171
	 *            The fieldLength to set.
172
	 */
173
	public void setFieldLength(int fieldLength) {
174
		this.fieldLength = fieldLength;
175
	}
176

  
177
	/**
178
	 * @return Returns the fieldName.
179
	 */
180
	public String getFieldName() {
181
		return fieldName;
182
	}
183

  
184
	/**
185
	 * @param fieldName
186
	 *            The fieldName to set.
187
	 */
188
	public void setFieldName(String fieldName) {
189
		this.fieldName = fieldName;
190
		this.fieldAlias = fieldName;
191
	}
192

  
193
	/**
194
	 * @return Returns the fieldType.
195
	 */
196
	public int getFieldType() {
197
		return fieldType;
198
	}
199

  
200
	/**
201
	 * @param fieldType
202
	 *            The fieldType to set.
203
	 */
204
	public void setFieldType(int fieldType) {
205
		this.fieldType = fieldType;
206
	}
207

  
125 208
	public String getFieldAlias() {
126 209
		return fieldAlias;
127 210
	}
......
129 212
	public void setFieldAlias(String fieldAlias) {
130 213
		this.fieldAlias = fieldAlias;
131 214
	}
132
	
215

  
133 216
	public FieldDescription cloneField() {
134 217
		FieldDescription resul = new FieldDescription();
135 218
		resul.fieldAlias = fieldAlias;

Also available in: Unified diff