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

Annotation of /Sprout/ERDBTypeShortString.pm

Parent Directory Parent Directory | Revision Log 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 :    
21 :     package ERDBTypeShortString;
22 :    
23 :     use strict;
24 :     use Tracer;
25 :     use ERDB;
26 :     use base qw(ERDBType);
27 :    
28 :     =head1 ERDB Short String Type Definition
29 :    
30 :     =head2 Introduction
31 :    
32 :     This object represents the data type for short strings of 32 characters or less
33 :     with no odd control characters needing translation. Such strings are very limited,
34 :     but more of them can be crowded into an index and they do not require encoding or
35 :     decoding.
36 :    
37 :     =head3 new
38 :    
39 :     my $et = ERDBTypeShortString->new();
40 :    
41 :     Construct a new ERDBTypeShortString descriptor.
42 :    
43 :     =cut
44 :    
45 :     sub new {
46 :     # Get the parameters.
47 :     my ($class) = @_;
48 :     # Create the ERDBTypeShortString object.
49 :     my $retVal = { };
50 :     # Bless and return it.
51 :     bless $retVal, $class;
52 :     return $retVal;
53 :     }
54 :    
55 :     =head2 Virtual Methods
56 :    
57 :     =head3 averageLength
58 :    
59 :     my $value = $et->averageLength();
60 :    
61 :     Return the average length of a data item of this field type when it is stored in the
62 :     database. This value is used to compute the expected size of a database table.
63 :    
64 :     =cut
65 :    
66 :     sub averageLength {
67 :     return 24;
68 :     }
69 :    
70 :     =head3 prettySortValue
71 :    
72 :     my $value = $et->prettySortValue();
73 :    
74 :     Number indicating where fields of this type should go in relation to other
75 :     fields. The value should be somewhere between C<1> and C<5>. A value outside
76 :     that range will make terrible things happen.
77 :    
78 :     =cut
79 :    
80 :     sub prettySortValue() {
81 :     return 1;
82 :     }
83 :    
84 :     =head3 validate
85 :    
86 :     my $okFlag = $et->validate($value);
87 :    
88 :     Return an error message if the specified value is invalid for this field type.
89 :    
90 :     The parameters are as follows.
91 :    
92 :     =over 4
93 :    
94 :     =item value
95 :    
96 :     Value of this type, for validation.
97 :    
98 :     =item RETURN
99 :    
100 :     Returns an empty string if the specified field is valid, and an error message
101 :     otherwise.
102 :    
103 :     =back
104 :    
105 :     =cut
106 :    
107 :     sub validate {
108 :     # Get the parameters.
109 :     my ($self, $value) = @_;
110 :     # Assume it's valid until we prove otherwise.
111 :     my $retVal = "";
112 :     if (length($value) > 32) {
113 :     $retVal = "Invalid short string field.";
114 :     } elsif ($value =~ /[\%\\\x00-\x1F\x80-\xFF]/) {
115 :     $retVal = "Invalid character in short-string field.";
116 :     }
117 :     # Return the determination.
118 :     return $retVal;
119 :     }
120 :    
121 :     =head3 encode
122 :    
123 :     my $string = $et->encode($value, $mode);
124 :    
125 :     Encode a value of this field type for storage in the database (or in a database load
126 :     file.)
127 :    
128 :     The parameters are as follows.
129 :    
130 :     =over 4
131 :    
132 :     =item value
133 :    
134 :     Value of this type, for encoding.
135 :    
136 :     =item mode
137 :    
138 :     TRUE if the value is being encoding for placement in a load file, FALSE if it
139 :     is being encoded for use as an SQL statement parameter. In most cases, the
140 :     encoding is the same for both modes.
141 :    
142 :     =back
143 :    
144 :     =cut
145 :    
146 :     sub encode {
147 :     # Get the parameters.
148 :     my ($self, $value, $mode) = @_;
149 :     # Return the input value.
150 :     return $value;
151 :     }
152 :    
153 :     =head3 decode
154 :    
155 :     my $value = $et->decode($string);
156 :    
157 :     Decode a string from the database into a value of this field type.
158 :    
159 :     The parameters are as follows.
160 :    
161 :     =over 4
162 :    
163 :     =item string
164 :    
165 :     String from the database to be decoded.
166 :    
167 :     =item RETURN
168 :    
169 :     Returns a value of the desired type.
170 :    
171 :     =back
172 :    
173 :     =cut
174 :    
175 :     sub decode {
176 :     # Get the parameters.
177 :     my ($self, $string) = @_;
178 :     # Return the input value.
179 :     return $string;
180 :     }
181 :    
182 :     =head3 sqlType
183 :    
184 :     my $typeString = $et->sqlType($dbh);
185 :    
186 :     Return the SQL data type for this field type.
187 :    
188 :     =over 4
189 :    
190 :     =item dbh
191 :    
192 :     Open L<DBKernel> handle for the database in question. This is used when the
193 :     datatype may be different depending on the DBMS used.
194 :    
195 :     =item RETURN
196 :    
197 :     Returns the datatype string to be used when creating a field of this type in
198 :     an SQL table.
199 :    
200 :     =back
201 :    
202 :     =cut
203 :    
204 :     sub sqlType {
205 :     return "VARCHAR(32)";
206 :     }
207 :    
208 :     =head3 indexMod
209 :    
210 :     my $length = $et->indexMod();
211 :    
212 :     Return the index modifier for this field type. The index modifier is the number of
213 :     characters to be indexed. If it is undefined, the field cannot be indexed. If it
214 :     is an empty string, the entire field is indexed. The default is an empty string.
215 :    
216 :     =cut
217 :    
218 :     sub indexMod {
219 :     return '';
220 :     }
221 :    
222 :     =head3 sortType
223 :    
224 :     my $letter = $et->sortType();
225 :    
226 :     Return the sorting type for this field type. The sorting type is C<n> for integers,
227 :     C<g> for floating-point numbers, and the empty string for character fields.
228 :     The default is the empty string.
229 :    
230 :     =cut
231 :    
232 :     sub sortType {
233 :     return "";
234 :     }
235 :    
236 :     =head3 documentation
237 :    
238 :     my $docText = $et->documentation();
239 :    
240 :     Return the documentation text for this field type. This should be in TWiki markup
241 :     format, though HTML will also work.
242 :    
243 :     =cut
244 :    
245 :     sub documentation() {
246 :     return 'A short string of 32 or fewer chaaracters.';
247 :     }
248 :    
249 :     =head3 name
250 :    
251 :     my $name = $et->name();
252 :    
253 :     Return the name of this type, as it will appear in the XML database definition.
254 :    
255 :     =cut
256 :    
257 :     sub name() {
258 :     return "short-string";
259 :     }
260 :    
261 :     =head3 default
262 :    
263 :     my $defaultValue = $et->default();
264 :    
265 :     Default value to be used for fields of this type if no default value is
266 :     specified in the database definition or in an L<ERDBLoadGroup/Put>
267 :     call during a loader operation. The default is undefined, which means
268 :     an error will be thrown during the load.
269 :    
270 :     =cut
271 :    
272 :     sub default {
273 :     return '';
274 :     }
275 :    
276 :     =head3 align
277 :    
278 :     my $alignment = $et->align();
279 :    
280 :     Return the display alignment for fields of this type: either C<left>, C<right>, or
281 :     C<center>. The default is C<left>.
282 :    
283 :     =cut
284 :    
285 :     sub align {
286 :     return 'left';
287 :     }
288 :    
289 :    
290 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3