BooleanColumn.java
biz/hammurapi/sql/columns/BooleanColumn.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 |
86: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 |
Method is not properly documented |
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 |
138:9
|
Java Inspector 089 |
Undocumented method |
2 |
142:9
|
Java Inspector 093 |
Do not instantiate Boolean, use Boolean.TRUE and Boolean.FALSE. |
2 |
97:53
|
Java Inspector 093 |
Do not instantiate Boolean, use Boolean.TRUE and Boolean.FALSE. |
2 |
99:24
|
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 |
122:26
|
Java Inspector 026 |
Avoid hardwired string literals. Allowed literals: [] |
3 |
122:63
|
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 BooleanColumn extends Column {
40 private boolean value;
41
42
43 private boolean originalValue;
44 private boolean isOriginalValueSet;
45
46 public boolean getOriginalValue() {
47 return isOriginalValueSet ? originalValue : value;
48 }
49
50 public void parameterizeOriginal(PreparedStatement ps, int idx) throws SQLException {
51 ps.setBoolean(idx, getOriginalValue());
52 }
53
54 public void setOriginal() {
55 originalValue=value;
56 isOriginalValueSet=true;
57 }
58
59
60 public boolean getValue() {
61 return value;
62 }
63
64 public void setValue(boolean value) {
65 if (force || this.value!=value) {
66 this.value = value;
67 onChange();
68 }
69 }
70
71 public BooleanColumn(String name, boolean isPrimaryKey) {
72 super(name, isPrimaryKey);
73 }
74
75 public BooleanColumn(String name, boolean isPrimaryKey, ResultSet rs) throws SQLException {
76 super(name, isPrimaryKey);
77 ResultSetMetaData metaData = rs.getMetaData();
78 for (int i=1, c=metaData.getColumnCount(); i<=c; i++) {
79 if (name.equals(metaData.getColumnName(i))) {
80 this.value=rs.getBoolean(i);
81 break;
82 }
83 }
84 }
85
86 public BooleanColumn(String name, boolean isPrimaryKey, boolean value) {
87 super(name, isPrimaryKey);
88 this.value=value;
89 }
90
91 protected void parameterizeInternal(PreparedStatement ps, int idx) throws SQLException {
92 ps.setBoolean(idx, value);
93 }
94
95 public Object getObjectValue(boolean ov) {
96 if (ov) {
97 return isOriginalValueSet ? new Boolean(originalValue) : null;
98 }
99 return new Boolean(value);
100 }
101
102 public String toString() {
103 return getName()+(isModified() ? "*" : "")+"="+value;
104 }
105
106 public boolean equals(Object otherColumn) {
107 if (otherColumn instanceof BooleanColumn) {
108 return value==((BooleanColumn) otherColumn).value;
109 }
110
111 return false;
112 }
113
114 public int hashCode() {
115 return getName().hashCode() ^ (value ? 0 : 1);
116 }
117
118
119
120
121 public void load(String textValue) {
122 setValue("yes".equalsIgnoreCase(textValue) || "true".equalsIgnoreCase(textValue));
123 }
124
125 public void clear() {
126 setValue(false);
127 clearModified();
128 }
129
130 public void configure(Context context, Converter converter) {
131 Object o=context.get(getName());
132 if (o!=null) {
133 setValue(((Boolean) converter.convert(o, boolean.class, null)).booleanValue());
134 }
135
136 }
137
138 protected String getType() {
139 return "boolean";
140 }
141
142 public void set(Column source) {
143 setValue(((BooleanColumn) source).getValue());
144 }
145
146
147
148
149 public void clearModified() {
150 super.clearModified();
151 originalValue=value;
152 }
153
154}
155