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