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

Annotation of /Sprout/ERDBTypeText.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 :     package ERDBTypeText;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use ERDB;
25 :     use base qw(ERDBType);
26 :    
27 :     =head1 ERDB Text Type Definition
28 :    
29 :     =head2 Introduction
30 :    
31 :     This object represents the primitive data type for long strings (0 to 64K
32 :     characters). These are stored with tabs, newlines, and backslashes escaped, and
33 :     unlike normal strings they are large enough that it is impractical to index the
34 :     entire length.
35 :    
36 :     =head3 new
37 :    
38 :     my $et = ERDBTypeText->new();
39 :    
40 :     Construct a new ERDBTypeText descriptor.
41 :    
42 :     =cut
43 :    
44 :     sub new {
45 :     # Get the parameters.
46 :     my ($class) = @_;
47 :     # Create the ERDBTypeText 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 averageLength
57 :    
58 :     my $value = $et->averageLength();
59 :    
60 :     Return the average length of a data item of this field type when it is stored in the
61 :     database. This value is used to compute the expected size of a database table.
62 :    
63 :     =cut
64 :    
65 :     sub averageLength {
66 :     return 1000;
67 :     }
68 :    
69 :     =head3 prettySortValue
70 :    
71 :     my $value = $et->prettySortValue();
72 :    
73 :     Number indicating where fields of this type should go in relation to other
74 :     fields. The value should be somewhere between C<1> and C<5>. A value outside
75 :     that range will make terrible things happen.
76 :    
77 :     =cut
78 :    
79 :     sub prettySortValue() {
80 :     return 4;
81 :     }
82 :    
83 :     =head3 validate
84 :    
85 :     my $okFlag = $et->validate($value);
86 :    
87 :     Return an error message if the specified value is invalid for this field type.
88 :    
89 :     The parameters are as follows.
90 :    
91 :     =over 4
92 :    
93 :     =item value
94 :    
95 :     Value of this type, for validation.
96 :    
97 :     =item RETURN
98 :    
99 :     Returns an empty string if the specified field is valid, and an error message
100 :     otherwise.
101 :    
102 :     =back
103 :    
104 :     =cut
105 :    
106 :     sub validate {
107 :     # Get the parameters.
108 :     my ($self, $value) = @_;
109 :     # Assume it's valid until we prove otherwise.
110 :     my $retVal = "";
111 :     # Escape the text.
112 :     my $text = Tracer::Escape($value);
113 :     # Verify the length.
114 :     if (length $text > 65535) {
115 :     $retVal = "Text string too long.";
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 :     # Declare the return variable.
150 :     my $retVal = Tracer::Escape($value);
151 :     # Return the result.
152 :     return $retVal;
153 :     }
154 :    
155 :     =head3 decode
156 :    
157 :     my $value = $et->decode($string);
158 :    
159 :     Decode a string from the database into a value of this field type.
160 :    
161 :     The parameters are as follows.
162 :    
163 :     =over 4
164 :    
165 :     =item string
166 :    
167 :     String from the database to be decoded.
168 :    
169 :     =item RETURN
170 :    
171 :     Returns a value of the desired type.
172 :    
173 :     =back
174 :    
175 :     =cut
176 :    
177 :     sub decode {
178 :     # Get the parameters.
179 :     my ($self, $string) = @_;
180 :     # Declare the return variable.
181 :     my $retVal = Tracer::UnEscape($string);
182 :     # Return the result.
183 :     return $retVal;
184 :     }
185 :    
186 :     =head3 sqlType
187 :    
188 :     my $typeString = $et->sqlType();
189 :    
190 :     Return the SQL data type for this field type.
191 :    
192 :     =cut
193 :    
194 :     sub sqlType {
195 :     return "TEXT";
196 :     }
197 :    
198 :     =head3 indexMod
199 :    
200 :     my $length = $et->indexMod();
201 :    
202 :     Return the index modifier for this field type. The index modifier is the number of
203 :     characters to be indexed. If it is undefined, the field cannot be indexed. If it
204 :     is an empty string, the entire field is indexed. The default is an empty string.
205 :    
206 :     =cut
207 :    
208 :     sub indexMod {
209 :     return 250;
210 :     }
211 :    
212 :     =head3 sortType
213 :    
214 :     my $letter = $et->sortType();
215 :    
216 :     Return the sorting type for this field type. The sorting type is C<n> for integers,
217 :     C<g> for floating-point numbers, and the empty string for character fields.
218 :     The default is the empty string.
219 :    
220 :     =cut
221 :    
222 :     sub sortType {
223 :     return "";
224 :     }
225 :    
226 :     =head3 documentation
227 :    
228 :     my $docText = $et->documentation();
229 :    
230 :     Return the documentation text for this field type. This should be in TWiki markup
231 :     format, though HTML will also work.
232 :    
233 :     =cut
234 :    
235 :     sub documentation() {
236 :     return 'Long character string, from 0 to approximately 65000 characters, not generally indexable.';
237 :     }
238 :    
239 :     =head3 name
240 :    
241 :     my $name = $et->name();
242 :    
243 :     Return the name of this type, as it will appear in the XML database definition.
244 :    
245 :     =cut
246 :    
247 :     sub name() {
248 :     return "text";
249 :     }
250 :    
251 :     =head3 default
252 :    
253 :     my $defaultValue = $et->default();
254 :    
255 :     Default value to be used for fields of this type if no default value is
256 :     specified in the database definition or in an [[ERDBLoadGroup#Put]]
257 :     call during a loader operation. The default is undefined, which means
258 :     an error will be thrown during the load.
259 :    
260 :     =cut
261 :    
262 :     sub default {
263 :     return '';
264 :     }
265 :    
266 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3