ByteColumn.java

biz/hammurapi/sql/columns/ByteColumn.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 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 089 Undocumented method 2 145: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 138:24
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 142:24

Source code

1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
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 * @author Pavel Vlasov
36 *
37 * @version $Revision: 1.12 $
38 */
39public class ByteColumn extends Column {
40 private byte value;
41
42 // Original stuff
43 private byte originalValue;
44 private boolean isOriginalValueSet;
45
46 public byte getOriginalValue() {
47 return isOriginalValueSet ? originalValue : value;
48 }
49
50 public void parameterizeOriginal(PreparedStatement ps, int idx) throws SQLException {
51 ps.setByte(idx, getOriginalValue());
52 }
53
54 public void setOriginal() {
55 originalValue=value;
56 isOriginalValueSet=true;
57 }
58 // End of original stuff
59
60 public byte getValue() {
61 return value;
62 }
63
64 public void setValue(byte value) {
65 if (force || this.value!=value) {
66 this.value = value;
67 onChange();
68 }
69 }
70
71 public ByteColumn(String name, boolean isPrimaryKey) {
72 super(name, isPrimaryKey);
73 }
74
75 public ByteColumn(String name, boolean isPrimaryKey, byte value) {
76 super(name, isPrimaryKey);
77 this.value=value;
78 }
79
80 public ByteColumn(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.getByte(i);
86 break;
87 }
88 }
89 }
90
91 protected void parameterizeInternal(PreparedStatement ps, int idx) throws SQLException {
92 ps.setByte(idx, value);
93 }
94
95 public Object getObjectValue(boolean ov) {
96 if (ov) {
97 return isOriginalValueSet ? new Byte(originalValue) : null;
98 }
99 return new Byte(value);
100 }
101
102 public String toString() {
103 return getName()+(isModified() ? "*" : "")+"="+value;
104 }
105
106 public boolean equals(Object otherColumn) {
107 if (otherColumn instanceof ByteColumn) {
108 return value==((ByteColumn) otherColumn).value;
109 }
110
111 return false;
112 }
113
114 public int hashCode() {
115 return getName().hashCode() ^ value;
116 }
117
118 /* (non-Javadoc)
119 * @see biz.hammurapi.sql.columns.Column#load(java.lang.String)
120 */
121 public void load(String textValue) {
122 setValue(Byte.parseByte(textValue));
123 }
124
125 public void clear() {
126 setValue((byte) 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(((Number) converter.convert(o, byte.class, null)).byteValue());
134 }
135 }
136
137 protected String getAlignment() {
138 return "right";
139 }
140
141 protected String getType() {
142 return "byte";
143 }
144
145 public void set(Column source) {
146 setValue(((ByteColumn) source).getValue());
147 }
148
149 /**
150 * Clears modified flag and sets original value to current value.
151 */
152 public void clearModified() {
153 super.clearModified();
154 originalValue=value;
155 }
156}
157