Parent Directory
|
Revision Log
Revision 1.1 - (view) (download) (as text)
1 : | parrello | 1.1 | #!/usr/bin/perl -w |
2 : | |||
3 : | # | ||
4 : | # Copyright (c) 2003-2006 University of Chicago and Fellowship | ||
5 : | # for Interpretations of Genomes. All Rights Reserved. | ||
6 : | # | ||
7 : | # This file is part of the SEED Toolkit. | ||
8 : | # | ||
9 : | # The SEED Toolkit is free software. You can redistribute | ||
10 : | # it and/or modify it under the terms of the SEED Toolkit | ||
11 : | # Public License. | ||
12 : | # | ||
13 : | # You should have received a copy of the SEED Toolkit Public License | ||
14 : | # along with this program; if not write to the University of Chicago | ||
15 : | # at info@ci.uchicago.edu or the Fellowship for Interpretation of | ||
16 : | # Genomes at veronika@thefig.info or download a copy from | ||
17 : | # http://www.theseed.org/LICENSE.TXT. | ||
18 : | # | ||
19 : | |||
20 : | package ERDBTypeCounter; | ||
21 : | |||
22 : | use strict; | ||
23 : | use Tracer; | ||
24 : | use ERDB; | ||
25 : | use base qw(ERDBType); | ||
26 : | |||
27 : | =head1 ERDB Counter Type Definition | ||
28 : | |||
29 : | =head2 Introduction | ||
30 : | |||
31 : | This object represents the primitive data type for large unsigned integers. The | ||
32 : | values range from 0 to 9223372036854775807. Although it is possible to store | ||
33 : | larger numbers, the MySQL arithmetic is always performed using signed 64-bit | ||
34 : | integers, so it's not really safe. | ||
35 : | |||
36 : | =head3 new | ||
37 : | |||
38 : | my $et = ERDBTypeCounter->new(); | ||
39 : | |||
40 : | Construct a new ERDBTypeCounter descriptor. | ||
41 : | |||
42 : | =cut | ||
43 : | |||
44 : | sub new { | ||
45 : | # Get the parameters. | ||
46 : | my ($class) = @_; | ||
47 : | # Create the ERDBTypeCounter object. | ||
48 : | my $retVal = { }; | ||
49 : | # Bless and return it. | ||
50 : | bless $retVal, $class; | ||
51 : | return $retVal; | ||
52 : | } | ||
53 : | |||
54 : | =head2 Virtual Methods | ||
55 : | |||
56 : | =head3 numeric | ||
57 : | |||
58 : | my $flag = $et->numeric(); | ||
59 : | |||
60 : | Return TRUE if this is a numeric type and FALSE otherwise. The default is | ||
61 : | FALSE. | ||
62 : | |||
63 : | =cut | ||
64 : | |||
65 : | sub numeric { | ||
66 : | # Get the parameters. | ||
67 : | my ($self) = @_; | ||
68 : | # Return the result. | ||
69 : | return 1; | ||
70 : | } | ||
71 : | |||
72 : | =head3 averageLength | ||
73 : | |||
74 : | my $value = $et->averageLength(); | ||
75 : | |||
76 : | Return the average length of a data item of this field type when it is stored in the | ||
77 : | database. This value is used to compute the expected size of a database table. | ||
78 : | |||
79 : | =cut | ||
80 : | |||
81 : | sub averageLength { | ||
82 : | return 8; | ||
83 : | } | ||
84 : | |||
85 : | =head3 prettySortValue | ||
86 : | |||
87 : | my $value = $et->prettySortValue(); | ||
88 : | |||
89 : | Number indicating where fields of this type should go in relation to other | ||
90 : | fields. The value should be somewhere between C<1> and C<5>. A value outside | ||
91 : | that range will make terrible things happen. | ||
92 : | |||
93 : | =cut | ||
94 : | |||
95 : | sub prettySortValue() { | ||
96 : | return 1; | ||
97 : | } | ||
98 : | |||
99 : | =head3 validate | ||
100 : | |||
101 : | my $okFlag = $et->validate($value); | ||
102 : | |||
103 : | Return an error message if the specified value is invalid for this field type. | ||
104 : | |||
105 : | The parameters are as follows. | ||
106 : | |||
107 : | =over 4 | ||
108 : | |||
109 : | =item value | ||
110 : | |||
111 : | Value of this type, for validation. | ||
112 : | |||
113 : | =item RETURN | ||
114 : | |||
115 : | Returns an empty string if the specified field is valid, and an error message | ||
116 : | otherwise. | ||
117 : | |||
118 : | =back | ||
119 : | |||
120 : | =cut | ||
121 : | |||
122 : | sub validate { | ||
123 : | # Get the parameters. | ||
124 : | my ($self, $value) = @_; | ||
125 : | # Assume it's valid until we prove otherwise. | ||
126 : | my $retVal = ""; | ||
127 : | if ($value =~ /\./) { | ||
128 : | $retVal = "Counter values cannot have decimal points."; | ||
129 : | } elsif ($value =~ /^-/) { | ||
130 : | $retVal = "Counter values cannot be negative."; | ||
131 : | } elsif (not $value =~ /^[+]?\d+$/) { | ||
132 : | $retVal = "Counter value is not numeric."; | ||
133 : | } elsif ($value > 9223372036854775807 || $value < 0) { | ||
134 : | $retVal = "Counter value is out of range."; | ||
135 : | } | ||
136 : | # Return the determination. | ||
137 : | return $retVal; | ||
138 : | } | ||
139 : | |||
140 : | =head3 encode | ||
141 : | |||
142 : | my $string = $et->encode($value, $mode); | ||
143 : | |||
144 : | Encode a value of this field type for storage in the database (or in a database load | ||
145 : | file.) | ||
146 : | |||
147 : | The parameters are as follows. | ||
148 : | |||
149 : | =over 4 | ||
150 : | |||
151 : | =item value | ||
152 : | |||
153 : | Value of this type, for encoding. | ||
154 : | |||
155 : | =item mode | ||
156 : | |||
157 : | TRUE if the value is being encoding for placement in a load file, FALSE if it | ||
158 : | is being encoded for use as an SQL statement parameter. In most cases, the | ||
159 : | encoding is the same for both modes. | ||
160 : | |||
161 : | =back | ||
162 : | |||
163 : | =cut | ||
164 : | |||
165 : | sub encode { | ||
166 : | # Get the parameters. | ||
167 : | my ($self, $value, $mode) = @_; | ||
168 : | # Declare the return variable. | ||
169 : | my $retVal = $value; | ||
170 : | # Return the result. | ||
171 : | return $retVal; | ||
172 : | } | ||
173 : | |||
174 : | =head3 decode | ||
175 : | |||
176 : | my $value = $et->decode($string); | ||
177 : | |||
178 : | Decode a string from the database into a value of this field type. | ||
179 : | |||
180 : | The parameters are as follows. | ||
181 : | |||
182 : | =over 4 | ||
183 : | |||
184 : | =item string | ||
185 : | |||
186 : | String from the database to be decoded. | ||
187 : | |||
188 : | =item RETURN | ||
189 : | |||
190 : | Returns a value of the desired type. | ||
191 : | |||
192 : | =back | ||
193 : | |||
194 : | =cut | ||
195 : | |||
196 : | sub decode { | ||
197 : | # Get the parameters. | ||
198 : | my ($self, $string) = @_; | ||
199 : | # Declare the return variable. | ||
200 : | my $retVal = $string; | ||
201 : | # Return the result. | ||
202 : | return $retVal; | ||
203 : | } | ||
204 : | |||
205 : | =head3 sqlType | ||
206 : | |||
207 : | my $typeString = $et->sqlType(); | ||
208 : | |||
209 : | Return the SQL data type for this field type. | ||
210 : | |||
211 : | =cut | ||
212 : | |||
213 : | sub sqlType { | ||
214 : | return "BIGINT UNSIGNED"; | ||
215 : | } | ||
216 : | |||
217 : | =head3 indexMod | ||
218 : | |||
219 : | my $length = $et->indexMod(); | ||
220 : | |||
221 : | Return the index modifier for this field type. The index modifier is the number of | ||
222 : | characters to be indexed. If it is undefined, the field cannot be indexed. If it | ||
223 : | is an empty string, the entire field is indexed. The default is an empty string. | ||
224 : | |||
225 : | =cut | ||
226 : | |||
227 : | sub indexMod { | ||
228 : | return ''; | ||
229 : | } | ||
230 : | |||
231 : | =head3 sortType | ||
232 : | |||
233 : | my $letter = $et->sortType(); | ||
234 : | |||
235 : | Return the sorting type for this field type. The sorting type is C<n> for integers, | ||
236 : | C<g> for floating-point numbers, and the empty string for character fields. | ||
237 : | The default is the empty string. | ||
238 : | |||
239 : | =cut | ||
240 : | |||
241 : | sub sortType { | ||
242 : | return "n"; | ||
243 : | } | ||
244 : | |||
245 : | =head3 documentation | ||
246 : | |||
247 : | my $docText = $et->documentation(); | ||
248 : | |||
249 : | Return the documentation text for this field type. This should be in TWiki markup | ||
250 : | format, though HTML will also work. | ||
251 : | |||
252 : | =cut | ||
253 : | |||
254 : | sub documentation() { | ||
255 : | return 'Large, unsigned integer, ranging from 0 to 9 quintillion.'; | ||
256 : | } | ||
257 : | |||
258 : | =head3 name | ||
259 : | |||
260 : | my $name = $et->name(); | ||
261 : | |||
262 : | Return the name of this type, as it will appear in the XML database definition. | ||
263 : | |||
264 : | =cut | ||
265 : | |||
266 : | sub name() { | ||
267 : | return "counter"; | ||
268 : | } | ||
269 : | |||
270 : | =head3 default | ||
271 : | |||
272 : | my $defaultValue = $et->default(); | ||
273 : | |||
274 : | Return the default value to be used for fields of this type if no default value | ||
275 : | is specified in the database definition or in an [[ERDBLoadGroup#Put]] call | ||
276 : | during a loader operation. The default is undefined, which means an error will | ||
277 : | be thrown during the load. | ||
278 : | |||
279 : | =cut | ||
280 : | |||
281 : | sub default { | ||
282 : | return 0; | ||
283 : | } | ||
284 : | |||
285 : | =head3 align | ||
286 : | |||
287 : | my $alignment = $et->align(); | ||
288 : | |||
289 : | Return the display alignment for fields of this type: either C<left>, C<right>, or | ||
290 : | C<center>. The default is C<left>. | ||
291 : | |||
292 : | =cut | ||
293 : | |||
294 : | sub align { | ||
295 : | return 'right'; | ||
296 : | } | ||
297 : | |||
298 : | =head3 html | ||
299 : | |||
300 : | my $html = $et->html($value); | ||
301 : | |||
302 : | Return the HTML for displaying the content of a field of this type in an output | ||
303 : | table. The default is the raw value, html-escaped. | ||
304 : | |||
305 : | =cut | ||
306 : | |||
307 : | sub html { | ||
308 : | my ($self, $value) = @_; | ||
309 : | return $value; | ||
310 : | } | ||
311 : | |||
312 : | |||
313 : | 1; |
MCS Webmaster | ViewVC Help |
Powered by ViewVC 1.0.3 |