[Bio] / Sprout / ERDBTypeCounter.pm Repository:
ViewVC logotype

Annotation of /Sprout/ERDBTypeCounter.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (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 : parrello 1.3 my $typeString = $et->sqlType($dbh);
208 : parrello 1.1
209 :     Return the SQL data type for this field type.
210 :    
211 : parrello 1.3 =over 4
212 :    
213 :     =item dbh
214 :    
215 :     Open L<DBKernel> handle for the database in question. This is used when the
216 :     datatype may be different depending on the DBMS used.
217 :    
218 :     =item RETURN
219 :    
220 :     Returns the datatype string to be used when creating a field of this type in
221 :     an SQL table.
222 :    
223 :     =back
224 :    
225 : parrello 1.1 =cut
226 :    
227 :     sub sqlType {
228 : parrello 1.3 my ($self, $dbh) = @_;
229 :     my $retVal = "BIGINT";
230 :     if ($dbh->dbms eq 'mysql') {
231 :     $retVal = "BIGINT UNSIGNED";
232 :     }
233 :     return $retVal;
234 : parrello 1.1 }
235 :    
236 :     =head3 indexMod
237 :    
238 :     my $length = $et->indexMod();
239 :    
240 :     Return the index modifier for this field type. The index modifier is the number of
241 :     characters to be indexed. If it is undefined, the field cannot be indexed. If it
242 :     is an empty string, the entire field is indexed. The default is an empty string.
243 :    
244 :     =cut
245 :    
246 :     sub indexMod {
247 :     return '';
248 :     }
249 :    
250 :     =head3 sortType
251 :    
252 :     my $letter = $et->sortType();
253 :    
254 :     Return the sorting type for this field type. The sorting type is C<n> for integers,
255 :     C<g> for floating-point numbers, and the empty string for character fields.
256 :     The default is the empty string.
257 :    
258 :     =cut
259 :    
260 :     sub sortType {
261 :     return "n";
262 :     }
263 :    
264 :     =head3 documentation
265 :    
266 :     my $docText = $et->documentation();
267 :    
268 :     Return the documentation text for this field type. This should be in TWiki markup
269 :     format, though HTML will also work.
270 :    
271 :     =cut
272 :    
273 :     sub documentation() {
274 :     return 'Large, unsigned integer, ranging from 0 to 9 quintillion.';
275 :     }
276 :    
277 :     =head3 name
278 :    
279 :     my $name = $et->name();
280 :    
281 :     Return the name of this type, as it will appear in the XML database definition.
282 :    
283 :     =cut
284 :    
285 :     sub name() {
286 :     return "counter";
287 :     }
288 :    
289 :     =head3 default
290 :    
291 :     my $defaultValue = $et->default();
292 :    
293 :     Return the default value to be used for fields of this type if no default value
294 : parrello 1.2 is specified in the database definition or in an L<ERDBLoadGroup/Put> call
295 : parrello 1.1 during a loader operation. The default is undefined, which means an error will
296 :     be thrown during the load.
297 :    
298 :     =cut
299 :    
300 :     sub default {
301 :     return 0;
302 :     }
303 :    
304 :     =head3 align
305 :    
306 :     my $alignment = $et->align();
307 :    
308 :     Return the display alignment for fields of this type: either C<left>, C<right>, or
309 :     C<center>. The default is C<left>.
310 :    
311 :     =cut
312 :    
313 :     sub align {
314 :     return 'right';
315 :     }
316 :    
317 :     =head3 html
318 :    
319 :     my $html = $et->html($value);
320 :    
321 :     Return the HTML for displaying the content of a field of this type in an output
322 :     table. The default is the raw value, html-escaped.
323 :    
324 :     =cut
325 :    
326 :     sub html {
327 :     my ($self, $value) = @_;
328 :     return $value;
329 :     }
330 :    
331 :    
332 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3