IntColumn.java
biz/hammurapi/sql/columns/IntColumn.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 |
91:9
|
Java Inspector 089 |
Undocumented method |
2 |
95:9
|
Java Inspector 089 |
Undocumented method |
2 |
102:9
|
Java Inspector 089 |
Undocumented method |
2 |
106:5
|
Java Inspector 089 |
Undocumented method |
2 |
114:9
|
Java Inspector 089 |
Undocumented method |
2 |
118:9
|
Java Inspector 089 |
Undocumented method |
2 |
122:9
|
Java Inspector 089 |
Undocumented method |
2 |
127:9
|
Java Inspector 089 |
Undocumented method |
2 |
134:9
|
Java Inspector 089 |
Undocumented method |
2 |
138:9
|
Java Inspector 089 |
Undocumented method |
2 |
142:9
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
103:50
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
103:56
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
103:60
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
135:24
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
139: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 IntColumn extends Column {
40 private int value;
41
42
43 private int originalValue;
44 private boolean isOriginalValueSet;
45
46 public int 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 int getValue() {
61 return value;
62 }
63
64 public void setValue(int value) {
65 if (force || this.value!=value) {
66 this.value = value;
67 onChange();
68 }
69 }
70
71 public IntColumn(String name, boolean isPrimaryKey) {
72 super(name, isPrimaryKey);
73 }
74
75 public IntColumn(String name, boolean isPrimaryKey, int value) {
76 super(name, isPrimaryKey);
77 this.value=value;
78 }
79
80 public IntColumn(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 this.value=rs.getInt(i);
86 break;
87 }
88 }
89 }
90
91 protected void parameterizeInternal(PreparedStatement ps, int idx) throws SQLException {
92 ps.setInt(idx, value);
93 }
94
95 public Object getObjectValue(boolean ov) {
96 if (ov) {
97 return isOriginalValueSet ? new Integer(originalValue) : null;
98 }
99 return new Integer(value);
100 }
101
102 public String toString() {
103 return getName()+(isModified() ? "*" : "")+"="+value;
104 }
105
106 public boolean equals(Object otherColumn) {
107 if (otherColumn instanceof IntColumn) {
108 return value==((IntColumn) otherColumn).value;
109 }
110
111 return false;
112 }
113
114 public int hashCode() {
115 return getName().hashCode() ^ value;
116 }
117
118 public void load(String textValue) {
119 setValue(Integer.parseInt(textValue));
120 }
121
122 public void clear() {
123 setValue(0);
124 clearModified();
125 }
126
127 public void configure(Context context, Converter converter) {
128 Object o=context.get(getName());
129 if (o!=null) {
130 setValue(((Number) converter.convert(o, int.class, null)).intValue());
131 }
132 }
133
134 protected String getAlignment() {
135 return "right";
136 }
137
138 protected String getType() {
139 return "int";
140 }
141
142 public void set(Column source) {
143 setValue(((IntColumn) source).getValue());
144 }
145
146
147
148
149 public void clearModified() {
150 super.clearModified();
151 originalValue=value;
152 }
153}
154