My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright 2011 stanislawbartkowski@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.ibm.sampledb.shared;

import java.math.BigDecimal;
import java.sql.Timestamp;

public class GetField {

public enum FieldType {
INTEGER, DATE, STRING, NUMBER
}

/**
* Field, column value (C union structure would be the best) Only one
* attribute should be set
*
* @author sbartkowski
*
*/
public static class FieldValue {
/** Timestamp. date column. */
private final Timestamp dField;
/** char, carchar2 column. */
private final String sField;
/** integer column. */
private final Integer iField;
/** decimal column. */
private final BigDecimal nField;

public FieldValue(Timestamp dField, String sField, Integer iField,
BigDecimal nField) {
super();
this.dField = dField;
this.sField = sField;
this.iField = iField;
this.nField = nField;
}

public Timestamp getdField() {
return dField;
}

public String getsField() {
return sField;
}

public int getiField() {
return iField;
}

public BigDecimal getnField() {
return nField;
}

public String getString(RowFieldInfo f) {
String val = null;
switch (f.getfType()) {
case STRING:
val = sField;
break;
case DATE:
if (dField != null) {
val = dField.toString();
}
break;
case INTEGER:
val = new Integer(iField).toString();
break;
case NUMBER:
if (nField != null) {
val = nField.toPlainString();
}
break;
}
return val;
}
}


public static FieldValue getValue(RowFieldInfo f, OneRecord i) {
Object o = i.getField(f.getfId());
String val = null;
Integer iVal = null;
Timestamp dVal = null;
BigDecimal bVal = null;
switch (f.getfType()) {
case INTEGER:
iVal = (Integer) o;
break;
case DATE:
dVal = (Timestamp) o;
break;
case STRING:
val = (String) o;
break;
case NUMBER:
bVal = (BigDecimal) o;
break;
}
return new FieldValue(dVal, val, iVal, bVal);
}

public static FieldValue getValue(String field, GetRowsInfo rInfo,
OneRecord i) {
RowFieldInfo f = rInfo.getFieldInfo(field);
return getValue(f, i);
}

}

Change log

r407 by stanislawbartkowski on Jul 6, 2011   Diff
new version with attachments
Go to: 
Project members, sign in to write a code review

Older revisions

r402 by stanislawbartkowski on Jun 25, 2011   Diff
[No log message]
r362 by stanislawbartkowski on May 2, 2011   Diff
Comments added
r359 by stanislawbartkowski on May 1, 2011   Diff
Next version of SampleGwt -
refactoring and printing
All revisions of this file

File info

Size: 2697 bytes, 123 lines
Powered by Google Project Hosting