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 package org.melati.poem;
47
48 import java.sql.Types;
49 import java.sql.PreparedStatement;
50 import java.sql.ResultSet;
51 import java.sql.SQLException;
52 import java.util.Enumeration;
53 import org.melati.poem.util.IntegerEnumeration;
54
55
56
57
58 public class IntegerPoemType extends AtomPoemType<Integer> {
59
60
61 public static final IntegerPoemType nullableInstance = new IntegerPoemType(true);
62
63
64
65
66
67 public IntegerPoemType(boolean nullable) {
68 super(Types.INTEGER, "INT", nullable);
69 }
70
71 protected IntegerPoemType(int sqlTypeCode, String sqlTypeName,
72 boolean nullable) {
73 super(sqlTypeCode, sqlTypeName, nullable);
74 }
75
76
77
78
79 protected Enumeration<Integer> _possibleRaws() {
80 Integer low = (Integer)getLowRaw();
81 Integer limit = (Integer)getLimitRaw();
82 return low == null ?
83 null :
84 new IntegerEnumeration(low.intValue(),
85 limit == null ?
86 Integer.MAX_VALUE : limit.intValue());
87 }
88
89 protected void _assertValidRaw(Object raw) {
90 if (raw != null && !(raw instanceof Integer))
91 throw new TypeMismatchPoemException(raw, this);
92 }
93
94 protected Integer _getRaw(ResultSet rs, int col) throws SQLException {
95 synchronized (rs) {
96 int i = rs.getInt(col);
97 return i == 0 && rs.wasNull() ? null : new Integer(i); }
98 }
99
100 protected void _setRaw(PreparedStatement ps, int col, Object integer)
101 throws SQLException {
102 ps.setInt(col, ((Integer)integer).intValue());
103 }
104
105 @Override
106 protected Integer _rawOfString(String rawString)
107 throws ParsingPoemException {
108 try {
109 return new Integer(rawString);
110 }
111 catch (NumberFormatException e) {
112 throw new ParsingPoemException(this, rawString, e);
113 }
114 }
115
116
117
118
119
120 protected boolean _canRepresent(SQLPoemType<?> other) {
121 return other instanceof IntegerPoemType;
122 }
123
124
125
126
127
128 public String toDsdType() {
129 return "Integer";
130 }
131
132 protected void _saveColumnInfo(ColumnInfo columnInfo)
133 throws AccessPoemException {
134 columnInfo.setTypefactory(PoemTypeFactory.INTEGER);
135 }
136
137 }