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

Annotation of /Sprout/ERDBTypeHashString.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3