CharColumn.java
biz/hammurapi/sql/columns/CharColumn.java
Violations
Inspector |
Message |
Severity |
Location |
Java Inspector 048 |
Copyrights information should be present in each file. |
1 |
|
Java Inspector 089 |
Type is not documented |
2 |
39:1
|
Java Inspector 089 |
Undocumented method |
2 |
46:9
|
Java Inspector 089 |
Undocumented method |
2 |
50:9
|
Java Inspector 089 |
Undocumented method |
2 |
54:9
|
Java Inspector 089 |
Undocumented method |
2 |
60:9
|
Java Inspector 089 |
Undocumented method |
2 |
64:9
|
Java Inspector 089 |
Undocumented constructor |
2 |
71:9
|
Java Inspector 089 |
Undocumented constructor |
2 |
75:9
|
Java Inspector 089 |
Undocumented constructor |
2 |
80:9
|
Java Inspector 089 |
Undocumented method |
2 |
94:9
|
Java Inspector 089 |
Undocumented method |
2 |
98:9
|
Java Inspector 089 |
Undocumented method |
2 |
105:9
|
Java Inspector 089 |
Undocumented method |
2 |
109:5
|
Java Inspector 089 |
Undocumented method |
2 |
117:9
|
Java Inspector 089 |
Undocumented method |
2 |
121:9
|
Java Inspector 089 |
Undocumented method |
2 |
125:9
|
Java Inspector 089 |
Undocumented method |
2 |
130:9
|
Java Inspector 089 |
Undocumented method |
2 |
137:9
|
Java Inspector 089 |
Undocumented method |
2 |
141:9
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
106:50
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
106:56
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
106:60
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
106:71
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
138:24
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23package biz.hammurapi.sql.columns;
24
25import java.sql.PreparedStatement;
26import java.sql.ResultSet;
27import java.sql.ResultSetMetaData;
28import java.sql.SQLException;
29
30import biz.hammurapi.config.Context;
31import biz.hammurapi.convert.Converter;
32
33
34
35
36
37
38
39public class CharColumn extends Column {
40 private char value;
41
42
43 private char originalValue;
44 private boolean isOriginalValueSet;
45
46 public char getOriginalValue() {
47 return isOriginalValueSet ? originalValue : value;
48 }
49
50 public void parameterizeOriginal(PreparedStatement ps, int idx) throws SQLException {
51 ps.setInt(idx, getOriginalValue());
52 }
53
54 public void setOriginal() {
55 originalValue=value;
56 isOriginalValueSet=true;
57 }
58
59
60 public char getValue() {
61 return value;
62 }
63
64 public void setValue(char value) {
65 if (force || this.value!=value) {
66 this.value = value;
67 onChange();
68 }
69 }
70
71 public CharColumn(String name, boolean isPrimaryKey) {
72 super(name, isPrimaryKey);
73 }
74
75 public CharColumn(String name, boolean isPrimaryKey, char value) {
76 super(name, isPrimaryKey);
77 this.value=value;
78 }
79
80 public CharColumn(String name, boolean isPrimaryKey, ResultSet rs) throws SQLException {
81 super(name, isPrimaryKey);
82 ResultSetMetaData metaData = rs.getMetaData();
83 for (int i=1, c=metaData.getColumnCount(); i<=c; i++) {
84 if (name.equals(metaData.getColumnName(i))) {
85 String strVal = rs.getString(i);
86 if (strVal!=null && strVal.length()>=1) {
87 this.value=strVal.charAt(0);
88 }
89 break;
90 }
91 }
92 }
93
94 protected void parameterizeInternal(PreparedStatement ps, int idx) throws SQLException {
95 ps.setInt(idx, value);
96 }
97
98 public Object getObjectValue(boolean ov) {
99 if (ov) {
100 return isOriginalValueSet ? new Character(originalValue) : null;
101 }
102 return new Character(value);
103 }
104
105 public String toString() {
106 return getName()+(isModified() ? "*" : "")+"='"+value+"'";
107 }
108
109 public boolean equals(Object otherColumn) {
110 if (otherColumn instanceof CharColumn) {
111 return value==((CharColumn) otherColumn).value;
112 }
113
114 return false;
115 }
116
117 public int hashCode() {
118 return getName().hashCode() ^ value;
119 }
120
121 public void load(String textValue) {
122 setValue(textValue.length()==0 ? 0 : textValue.charAt(0));
123 }
124
125 public void clear() {
126 setValue((char) 0);
127 clearModified();
128 }
129
130 public void configure(Context context, Converter converter) {
131 Object o=context.get(getName());
132 if (o!=null) {
133 setValue(((Character) converter.convert(o, char.class, null)).charValue());
134 }
135 }
136
137 protected String getType() {
138 return "char";
139 }
140
141 public void set(Column source) {
142 setValue(((CharColumn) source).getValue());
143 }
144
145
146
147
148 public void clearModified() {
149 super.clearModified();
150 originalValue=value;
151 }
152}
153