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

Annotation of /Sprout/ERDBTypeHashString.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (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 :     considerably shorted than the data from which they are digested. It is not,
34 :     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 :     my $typeString = $et->sqlType();
186 :    
187 :     Return the SQL data type for this field type.
188 :    
189 :     =cut
190 :    
191 :     sub sqlType {
192 :     return "CHAR(22)";
193 :     }
194 :    
195 :     =head3 indexMod
196 :    
197 :     my $length = $et->indexMod();
198 :    
199 :     Return the index modifier for this field type. The index modifier is the number of
200 :     characters to be indexed. If it is undefined, the field cannot be indexed. If it
201 :     is an empty string, the entire field is indexed. The default is an empty string.
202 :    
203 :     =cut
204 :    
205 :     sub indexMod {
206 :     return '';
207 :     }
208 :    
209 :     =head3 sortType
210 :    
211 :     my $letter = $et->sortType();
212 :    
213 :     Return the sorting type for this field type. The sorting type is C<n> for integers,
214 :     C<g> for floating-point numbers, and the empty string for character fields.
215 :     The default is the empty string.
216 :    
217 :     =cut
218 :    
219 :     sub sortType {
220 :     return "";
221 :     }
222 :    
223 :     =head3 documentation
224 :    
225 :     my $docText = $et->documentation();
226 :    
227 :     Return the documentation text for this field type. This should be in TWiki markup
228 :     format, though HTML will also work.
229 :    
230 :     =cut
231 :    
232 :     sub documentation() {
233 :     return 'A Base64 Digest MD5 code.';
234 :     }
235 :    
236 :     =head3 name
237 :    
238 :     my $name = $et->name();
239 :    
240 :     Return the name of this type, as it will appear in the XML database definition.
241 :    
242 :     =cut
243 :    
244 :     sub name() {
245 :     return "hash-string";
246 :     }
247 :    
248 :     =head3 default
249 :    
250 :     my $defaultValue = $et->default();
251 :    
252 :     Default value to be used for fields of this type if no default value is
253 : parrello 1.2 specified in the database definition or in an L<ERDBLoadGroup/Put>
254 : parrello 1.1 call during a loader operation. The default is undefined, which means
255 :     an error will be thrown during the load.
256 :    
257 :     =cut
258 :    
259 :     sub default {
260 :     return ' ';
261 :     }
262 :    
263 :     =head3 align
264 :    
265 :     my $alignment = $et->align();
266 :    
267 :     Return the display alignment for fields of this type: either C<left>, C<right>, or
268 :     C<center>. The default is C<left>.
269 :    
270 :     =cut
271 :    
272 :     sub align {
273 :     return 'left';
274 :     }
275 :    
276 :    
277 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3