KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > util > Criteria


1 package org.apache.torque.util;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements. See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership. The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License. You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied. See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */

21
22 import java.io.IOException JavaDoc;
23 import java.io.ObjectInputStream JavaDoc;
24 import java.io.ObjectOutputStream JavaDoc;
25 import java.io.Serializable JavaDoc;
26 import java.lang.reflect.Array JavaDoc;
27 import java.math.BigDecimal JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Arrays JavaDoc;
30 import java.util.GregorianCalendar JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Hashtable JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.Map JavaDoc;
36
37 import org.apache.commons.collections.OrderedMap;
38 import org.apache.commons.collections.map.ListOrderedMap;
39 import org.apache.commons.lang.ObjectUtils;
40 import org.apache.commons.lang.StringUtils;
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43 import org.apache.torque.Torque;
44 import org.apache.torque.TorqueException;
45 import org.apache.torque.adapter.DB;
46 import org.apache.torque.om.DateKey;
47 import org.apache.torque.om.ObjectKey;
48
49 /**
50  * This is a utility class that is used for retrieving different types
51  * of values from a hashtable based on a simple name string. This
52  * class is meant to minimize the amount of casting that needs to be
53  * done when working with Hashtables.
54  *
55  * NOTE: other methods will be added as needed and as time permits.
56  *
57  * @author <a HREF="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
58  * @author <a HREF="mailto:jmcnally@collab.net">John D. McNally</a>
59  * @author <a HREF="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
60  * @author <a HREF="mailto:eric@dobbse.net">Eric Dobbs</a>
61  * @author <a HREF="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
62  * @author <a HREF="mailto:sam@neurogrid.com">Sam Joseph</a>
63  * @author <a HREF="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
64  * @author <a HREF="mailto:fischer@seitenbau.de">Thomas Fischer</a>
65  * @author <a HREF="mailto:seade@backstagetech.com.au">Scott Eade</a>
66  * @author <a HREF="mailto:tv@apache.org">Thomas Vandahl</a>
67  * @version $Id: Criteria.java 476550 2006-11-18 16:08:37Z tfischer $
68  */

69 public class Criteria extends Hashtable JavaDoc
70 {
71     /** Serial version. */
72     private static final long serialVersionUID = -9001666575933085601L;
73
74     /** Comparison type. */
75     public static final SqlEnum EQUAL = SqlEnum.EQUAL;
76
77     /** Comparison type. */
78     public static final SqlEnum NOT_EQUAL = SqlEnum.NOT_EQUAL;
79
80     /** Comparison type. */
81     public static final SqlEnum ALT_NOT_EQUAL = SqlEnum.ALT_NOT_EQUAL;
82
83     /** Comparison type. */
84     public static final SqlEnum GREATER_THAN = SqlEnum.GREATER_THAN;
85
86     /** Comparison type. */
87     public static final SqlEnum LESS_THAN = SqlEnum.LESS_THAN;
88
89     /** Comparison type. */
90     public static final SqlEnum GREATER_EQUAL = SqlEnum.GREATER_EQUAL;
91
92     /** Comparison type. */
93     public static final SqlEnum LESS_EQUAL = SqlEnum.LESS_EQUAL;
94
95     /** Comparison type. */
96     public static final SqlEnum LIKE = SqlEnum.LIKE;
97
98     /** Comparison type. */
99     public static final SqlEnum NOT_LIKE = SqlEnum.NOT_LIKE;
100
101     /** Comparison type. */
102     public static final SqlEnum ILIKE = SqlEnum.ILIKE;
103
104     /** Comparison type. */
105     public static final SqlEnum NOT_ILIKE = SqlEnum.NOT_ILIKE;
106
107     /** Comparison type. */
108     public static final SqlEnum CUSTOM = SqlEnum.CUSTOM;
109
110     /** Comparison type. */
111     public static final SqlEnum DISTINCT = SqlEnum.DISTINCT;
112
113     /** Comparison type. */
114     public static final SqlEnum IN = SqlEnum.IN;
115
116     /** Comparison type. */
117     public static final SqlEnum NOT_IN = SqlEnum.NOT_IN;
118
119     /** Comparison type. */
120     public static final SqlEnum ALL = SqlEnum.ALL;
121
122     /** Comparison type. */
123     public static final SqlEnum JOIN = SqlEnum.JOIN;
124
125     /** &quot;Order by&quot; qualifier - ascending */
126     private static final SqlEnum ASC = SqlEnum.ASC;
127
128     /** &quot;Order by&quot; qualifier - descending */
129     private static final SqlEnum DESC = SqlEnum.DESC;
130
131     /** &quot;IS NULL&quot; null comparison */
132     public static final SqlEnum ISNULL = SqlEnum.ISNULL;
133
134     /** &quot;IS NOT NULL&quot; null comparison */
135     public static final SqlEnum ISNOTNULL = SqlEnum.ISNOTNULL;
136
137     /** &quot;CURRENT_DATE&quot; ANSI SQL function */
138     public static final SqlEnum CURRENT_DATE = SqlEnum.CURRENT_DATE;
139
140     /** &quot;CURRENT_TIME&quot; ANSI SQL function */
141     public static final SqlEnum CURRENT_TIME = SqlEnum.CURRENT_TIME;
142
143     /** &quot;LEFT JOIN&quot; SQL statement */
144     public static final SqlEnum LEFT_JOIN = SqlEnum.LEFT_JOIN;
145
146     /** &quot;RIGHT JOIN&quot; SQL statement */
147     public static final SqlEnum RIGHT_JOIN = SqlEnum.RIGHT_JOIN;
148
149     /** &quot;INNER JOIN&quot; SQL statement */
150     public static final SqlEnum INNER_JOIN = SqlEnum.INNER_JOIN;
151
152     private static final int DEFAULT_CAPACITY = 10;
153
154     private boolean ignoreCase = false;
155     private boolean singleRecord = false;
156     private boolean cascade = false;
157     private UniqueList selectModifiers = new UniqueList();
158     private UniqueList selectColumns = new UniqueList();
159     private UniqueList orderByColumns = new UniqueList();
160     private UniqueList groupByColumns = new UniqueList();
161     private Criterion having = null;
162     private OrderedMap asColumns = ListOrderedMap.decorate(new HashMap JavaDoc());
163     private transient List JavaDoc joins = null;
164
165     /** The name of the database. */
166     private String JavaDoc dbName;
167
168     /** The name of the database as given in the contructor. */
169     private String JavaDoc originalDbName;
170
171     /**
172      * To limit the number of rows to return. <code>-1</code> means return all
173      * rows.
174      */

175     private int limit = -1;
176
177     /** To start the results at a row other than the first one. */
178     private int offset = 0;
179
180     private HashMap JavaDoc aliases = null;
181
182     private boolean useTransaction = false;
183
184     /** the log. */
185     private static Log log = LogFactory.getLog(Criteria.class);
186
187     /**
188      * Creates a new instance with the default capacity.
189      */

190     public Criteria()
191     {
192         this(DEFAULT_CAPACITY);
193     }
194
195     /**
196      * Creates a new instance with the specified capacity.
197      *
198      * @param initialCapacity An int.
199      */

200     public Criteria(int initialCapacity)
201     {
202         this(Torque.getDefaultDB(), initialCapacity);
203     }
204
205     /**
206      * Creates a new instance with the default capacity which corresponds to
207      * the specified database.
208      *
209      * @param dbName The dabase name.
210      */

211     public Criteria(String JavaDoc dbName)
212     {
213         this(dbName, DEFAULT_CAPACITY);
214     }
215
216     /**
217      * Creates a new instance with the specified capacity which corresponds to
218      * the specified database.
219      *
220      * @param dbName The dabase name.
221      * @param initialCapacity The initial capacity.
222      */

223     public Criteria(String JavaDoc dbName, int initialCapacity)
224     {
225         super(initialCapacity);
226         this.dbName = dbName;
227         this.originalDbName = dbName;
228     }
229
230     /**
231      * Brings this criteria back to its initial state, so that it
232      * can be reused as if it was new. Except if the criteria has grown in
233      * capacity, it is left at the current capacity.
234      */

235     public void clear()
236     {
237         super.clear();
238         ignoreCase = false;
239         singleRecord = false;
240         cascade = false;
241         selectModifiers.clear();
242         selectColumns.clear();
243         orderByColumns.clear();
244         groupByColumns.clear();
245         having = null;
246         asColumns.clear();
247         joins = null;
248         dbName = originalDbName;
249         offset = 0;
250         limit = -1;
251         aliases = null;
252         useTransaction = false;
253     }
254
255     /**
256      * Add an AS clause to the select columns. Usage:
257      * <p>
258      * <code>
259      *
260      * Criteria myCrit = new Criteria();
261      * myCrit.addAsColumn(&quot;alias&quot;, &quot;ALIAS(&quot;+MyPeer.ID+&quot;)&quot;);
262      *
263      * </code>
264      *
265      * @param name wanted Name of the column
266      * @param clause SQL clause to select from the table
267      *
268      * If the name already exists, it is replaced by the new clause.
269      *
270      * @return A modified Criteria object.
271      */

272     public Criteria addAsColumn(String JavaDoc name, String JavaDoc clause)
273     {
274         asColumns.put(name, clause);
275         return this;
276     }
277
278     /**
279      * Get the column aliases.
280      *
281      * @return A Map which map the column alias names
282      * to the alias clauses.
283      */

284     public Map JavaDoc getAsColumns()
285     {
286         return asColumns;
287     }
288
289     /**
290      * Get the table aliases.
291      *
292      * @return A Map which maps the table alias names to the actual table names.
293      */

294     public Map JavaDoc getAliases()
295     {
296         return aliases;
297     }
298
299     /**
300      * Allows one to specify an alias for a table that can
301      * be used in various parts of the SQL.
302      *
303      * @param alias a <code>String</code> value
304      * @param table a <code>String</code> value
305      */

306     public void addAlias(String JavaDoc alias, String JavaDoc table)
307     {
308         if (aliases == null)
309         {
310             aliases = new HashMap JavaDoc(8);
311         }
312         aliases.put(alias, table);
313     }
314
315     /**
316      * Returns the table name associated with an alias.
317      *
318      * @param alias a <code>String</code> value
319      * @return a <code>String</code> value
320      */

321     public String JavaDoc getTableForAlias(String JavaDoc alias)
322     {
323         if (aliases == null)
324         {
325             return null;
326         }
327         return (String JavaDoc) aliases.get(alias);
328     }
329
330     /**
331      * Does this Criteria Object contain the specified key?
332      *
333      * @param table The name of the table.
334      * @param column The name of the column.
335      * @return True if this Criteria Object contain the specified key.
336      */

337     public boolean containsKey(String JavaDoc table, String JavaDoc column)
338     {
339         return containsKey(table + '.' + column);
340     }
341
342     /**
343      * Convenience method to return value as a boolean.
344      *
345      * @param column String name of column.
346      * @return A boolean.
347      */

348     public boolean getBoolean(String JavaDoc column)
349     {
350         return ((Boolean JavaDoc) getCriterion(column).getValue()).booleanValue();
351     }
352
353     /**
354      * Convenience method to return value as a boolean.
355      *
356      * @param table String name of table.
357      * @param column String name of column.
358      * @return A boolean.
359      */

360     public boolean getBoolean(String JavaDoc table, String JavaDoc column)
361     {
362         return getBoolean(new StringBuffer JavaDoc(table.length() + column.length() + 1)
363                 .append(table).append('.').append(column)
364                 .toString());
365     }
366
367     /**
368      * Will force the sql represented by this criteria to be executed within
369      * a transaction. This is here primarily to support the oid type in
370      * postgresql. Though it can be used to require any single sql statement
371      * to use a transaction.
372      */

373     public void setUseTransaction(boolean v)
374     {
375         useTransaction = v;
376     }
377
378     /**
379      * called by BasePeer to determine whether the sql command specified by
380      * this criteria must be wrapped in a transaction.
381      *
382      * @return a <code>boolean</code> value
383      */

384     protected boolean isUseTransaction()
385     {
386         return useTransaction;
387     }
388
389     /**
390      * Method to return criteria related to columns in a table.
391      *
392      * @param column String name of column.
393      * @return A Criterion.
394      */

395     public Criterion getCriterion(String JavaDoc column)
396     {
397         return (Criterion) super.get(column);
398     }
399
400     /**
401      * Method to return criteria related to a column in a table.
402      *
403      * @param table String name of table.
404      * @param column String name of column.
405      * @return A Criterion.
406      */

407     public Criterion getCriterion(String JavaDoc table, String JavaDoc column)
408     {
409         return getCriterion(
410                 new StringBuffer JavaDoc(table.length() + column.length() + 1)
411                 .append(table).append('.').append(column)
412                 .toString());
413     }
414
415     /**
416      * Method to return criterion that is not added automatically
417      * to this Criteria. This can be used to chain the
418      * Criterions to form a more complex where clause.
419      *
420      * @param column String full name of column (for example TABLE.COLUMN).
421      * @return A Criterion.
422      */

423     public Criterion getNewCriterion(String JavaDoc column, Object JavaDoc value,
424             SqlEnum comparison)
425     {
426         return new Criterion(column, value, comparison);
427     }
428
429     /**
430      * Method to return criterion that is not added automatically
431      * to this Criteria. This can be used to chain the
432      * Criterions to form a more complex where clause.
433      *
434      * @param table String name of table.
435      * @param column String name of column.
436      * @return A Criterion.
437      */

438     public Criterion getNewCriterion(String JavaDoc table, String JavaDoc column,
439             Object JavaDoc value, SqlEnum comparison)
440     {
441         return new Criterion(table, column, value, comparison);
442     }
443
444     /**
445      * This method adds a prepared Criterion object to the Criteria.
446      * You can get a new, empty Criterion object with the
447      * getNewCriterion() method. If a criterion for the requested column
448      * already exists, it is replaced. This is used as follows:
449      *
450      * <p>
451      * <code>
452      * Criteria crit = new Criteria();
453      * Criteria.Criterion c = crit
454      * .getNewCriterion(BasePeer.ID, new Integer(5), Criteria.LESS_THAN);
455      * crit.add(c);
456      * </code>
457      *
458      * @param c A Criterion object
459      *
460      * @return A modified Criteria object.
461      */

462     public Criteria add(Criterion c)
463     {
464         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(c.getTable().length()
465                 + c.getColumn().length() + 1);
466         sb.append(c.getTable());
467         sb.append('.');
468         sb.append(c.getColumn());
469         super.put(sb.toString(), c);
470         return this;
471     }
472
473     /**
474      * Method to return a String table name.
475      *
476      * @param name A String with the name of the key.
477      * @return A String with the value of the object at key.
478      */

479     public String JavaDoc getColumnName(String JavaDoc name)
480     {
481         return getCriterion(name).getColumn();
482     }
483
484     /**
485      * Method to return a comparison String.
486      *
487      * @param key String name of the key.
488      * @return A String with the value of the object at key.
489      */

490     public SqlEnum getComparison(String JavaDoc key)
491     {
492         return getCriterion(key).getComparison();
493     }
494
495     /**
496      * Method to return a comparison String.
497      *
498      * @param table String name of table.
499      * @param column String name of column.
500      * @return A String with the value of the object at key.
501      */

502     public SqlEnum getComparison(String JavaDoc table, String JavaDoc column)
503     {
504         return getComparison(
505                 new StringBuffer JavaDoc(table.length() + column.length() + 1)
506                 .append(table).append('.').append(column)
507                 .toString());
508     }
509
510     /**
511      * Convenience method to return a Date.
512      *
513      * @param name column name (TABLE.COLUMN)
514      * @return A java.util.Date with the value of object at key.
515      */

516     public java.util.Date JavaDoc getDate(String JavaDoc name)
517     {
518         return (java.util.Date JavaDoc) getCriterion(name).getValue();
519     }
520
521     /**
522      * Convenience method to return a Date.
523      *
524      * @param table String name of table.
525      * @param column String name of column.
526      * @return A java.util.Date with the value of object at key.
527      */

528     public java.util.Date JavaDoc getDate(String JavaDoc table, String JavaDoc column)
529     {
530         return getDate(
531                 new StringBuffer JavaDoc(table.length() + column.length() + 1)
532                 .append(table).append('.').append(column)
533                 .toString());
534     }
535
536     /**
537      * Get the Database(Map) name.
538      *
539      * @return A String with the Database(Map) name. By default, this
540      * is PoolBrokerService.DEFAULT.
541      */

542     public String JavaDoc getDbName()
543     {
544         return dbName;
545     }
546
547     /**
548      * Set the DatabaseMap name. If <code>null</code> is supplied, uses value
549      * provided by <code>Torque.getDefaultDB()</code>.
550      *
551      * @param dbName A String with the Database(Map) name.
552      */

553     public void setDbName(String JavaDoc dbName)
554     {
555         this.dbName = (dbName == null ? Torque.getDefaultDB() : dbName.trim());
556     }
557
558     /**
559      * Convenience method to return a double.
560      *
561      * @param name A String with the name of the key.
562      * @return A double with the value of object at key.
563      */

564     public double getDouble(String JavaDoc name)
565     {
566         Object JavaDoc obj = getCriterion(name).getValue();
567         if (obj instanceof String JavaDoc)
568         {
569             return new Double JavaDoc((String JavaDoc) obj).doubleValue();
570         }
571         return ((Double JavaDoc) obj).doubleValue();
572     }
573
574     /**
575      * Convenience method to return a double.
576      *
577      * @param table String name of table.
578      * @param column String name of column.
579      * @return A double with the value of object at key.
580      */

581     public double getDouble(String JavaDoc table, String JavaDoc column)
582     {
583         return getDouble(new StringBuffer JavaDoc(table.length() + column.length() + 1)
584                 .append(table).append('.').append(column)
585                 .toString());
586     }
587
588     /**
589      * Convenience method to return a float.
590      *
591      * @param name A String with the name of the key.
592      * @return A float with the value of object at key.
593      */

594     public float getFloat(String JavaDoc name)
595     {
596         Object JavaDoc obj = getCriterion(name).getValue();
597         if (obj instanceof String JavaDoc)
598         {
599             return new Float JavaDoc((String JavaDoc) obj).floatValue();
600         }
601         return ((Float JavaDoc) obj).floatValue();
602     }
603
604     /**
605      * Convenience method to return a float.
606      *
607      * @param table String name of table.
608      * @param column String name of column.
609      * @return A float with the value of object at key.
610      */

611     public float getFloat(String JavaDoc table, String JavaDoc column)
612     {
613         return getFloat(new StringBuffer JavaDoc(table.length() + column.length() + 1)
614                 .append(table).append('.').append(column)
615                 .toString());
616     }
617
618     /**
619      * Convenience method to return an Integer.
620      *
621      * @param name A String with the name of the key.
622      * @return An Integer with the value of object at key.
623      */

624     public Integer JavaDoc getInteger(String JavaDoc name)
625     {
626         Object JavaDoc obj = getCriterion(name).getValue();
627         if (obj instanceof String JavaDoc)
628         {
629             return new Integer JavaDoc((String JavaDoc) obj);
630         }
631         return ((Integer JavaDoc) obj);
632     }
633
634     /**
635      * Convenience method to return an Integer.
636      *
637      * @param table String name of table.
638      * @param column String name of column.
639      * @return An Integer with the value of object at key.
640      */

641     public Integer JavaDoc getInteger(String JavaDoc table, String JavaDoc column)
642     {
643         return getInteger(
644                 new StringBuffer JavaDoc(table.length() + column.length() + 1)
645                 .append(table).append('.').append(column)
646                 .toString());
647     }
648
649     /**
650      * Convenience method to return an int.
651      *
652      * @param name A String with the name of the key.
653      * @return An int with the value of object at key.
654      */

655     public int getInt(String JavaDoc name)
656     {
657         Object JavaDoc obj = getCriterion(name).getValue();
658         if (obj instanceof String JavaDoc)
659         {
660             return new Integer JavaDoc((String JavaDoc) obj).intValue();
661         }
662         return ((Integer JavaDoc) obj).intValue();
663     }
664
665     /**
666      * Convenience method to return an int.
667      *
668      * @param table String name of table.
669      * @param column String name of column.
670      * @return An int with the value of object at key.
671      */

672     public int getInt(String JavaDoc table, String JavaDoc column)
673     {
674         return getInt(
675                 new StringBuffer JavaDoc(table.length() + column.length() + 1)
676                 .append(table).append('.').append(column)
677                 .toString());
678     }
679
680     /**
681      * Convenience method to return a BigDecimal.
682      *
683      * @param name A String with the name of the key.
684      * @return A BigDecimal with the value of object at key.
685      */

686     public BigDecimal JavaDoc getBigDecimal(String JavaDoc name)
687     {
688         Object JavaDoc obj = getCriterion(name).getValue();
689         if (obj instanceof String JavaDoc)
690         {
691             return new BigDecimal JavaDoc((String JavaDoc) obj);
692         }
693         return (BigDecimal JavaDoc) obj;
694     }
695
696     /**
697      * Convenience method to return a BigDecimal.
698      *
699      * @param table String name of table.
700      * @param column String name of column.
701      * @return A BigDecimal with the value of object at key.
702      */

703     public BigDecimal JavaDoc getBigDecimal(String JavaDoc table, String JavaDoc column)
704     {
705         return getBigDecimal(
706                 new StringBuffer JavaDoc(table.length() + column.length() + 1)
707                 .append(table).append('.').append(column)
708                 .toString());
709     }
710
711     /**
712      * Convenience method to return a long.
713      *
714      * @param name A String with the name of the key.
715      * @return A long with the value of object at key.
716      */

717     public long getLong(String JavaDoc name)
718     {
719         Object JavaDoc obj = getCriterion(name).getValue();
720         if (obj instanceof String JavaDoc)
721         {
722             return new Long JavaDoc((String JavaDoc) obj).longValue();
723         }
724         return ((Long JavaDoc) obj).longValue();
725     }
726
727     /**
728      * Convenience method to return a long.
729      *
730      * @param table String name of table.
731      * @param column String name of column.
732      * @return A long with the value of object at key.
733      */

734     public long getLong(String JavaDoc table, String JavaDoc column)
735     {
736         return getLong(
737                 new StringBuffer JavaDoc(table.length() + column.length() + 1)
738                 .append(table).append('.').append(column)
739                 .toString());
740     }
741
742     /**
743      * Convenience method to return a String.
744      *
745      * @param name A String with the name of the key.
746      * @return A String with the value of object at key.
747      */

748     public String JavaDoc getString(String JavaDoc name)
749     {
750         return (String JavaDoc) getCriterion(name).getValue();
751     }
752
753     /**
754      * Convenience method to return a String.
755      *
756      * @param table String name of table.
757      * @param column String name of column.
758      * @return A String with the value of object at key.
759      */

760     public String JavaDoc getString(String JavaDoc table, String JavaDoc column)
761     {
762         return getString(
763                 new StringBuffer JavaDoc(table.length() + column.length() + 1)
764                 .append(table).append('.').append(column)
765                 .toString());
766     }
767
768     /**
769      * Method to return a String table name.
770      *
771      * @param name A String with the name of the key.
772      * @return A String with the value of object at key.
773      */

774     public String JavaDoc getTableName(String JavaDoc name)
775     {
776         return getCriterion(name).getTable();
777     }
778
779     /**
780      * Convenience method to return a List.
781      *
782      * @param name A String with the name of the key.
783      * @return A List with the value of object at key.
784      */

785     public List JavaDoc getList(String JavaDoc name)
786     {
787         return (List JavaDoc) getCriterion(name).getValue();
788     }
789
790     /**
791      * Convenience method to return a List.
792      *
793      * @param table String name of table.
794      * @param column String name of column.
795      * @return A List with the value of object at key.
796      */

797     public List JavaDoc getList(String JavaDoc table, String JavaDoc column)
798     {
799         return getList(
800                 new StringBuffer JavaDoc(table.length() + column.length() + 1)
801                 .append(table).append('.').append(column)
802                 .toString());
803     }
804
805     /**
806      * Method to return the value that was added to Criteria.
807      *
808      * @param name A String with the name of the key.
809      * @return An Object with the value of object at key.
810      */

811     public Object JavaDoc getValue(String JavaDoc name)
812     {
813         return getCriterion(name).getValue();
814     }
815
816     /**
817      * Method to return the value that was added to Criteria.
818      *
819      * @param table String name of table.
820      * @param column String name of column.
821      * @return An Object with the value of object at key.
822      */

823     public Object JavaDoc getValue(String JavaDoc table, String JavaDoc column)
824     {
825         return getValue(
826                 new StringBuffer JavaDoc(table.length() + column.length() + 1)
827                 .append(table).append('.').append(column)
828                 .toString());
829     }
830
831     /**
832      * Convenience method to return an ObjectKey.
833      *
834      * @param name A String with the name of the key.
835      * @return An ObjectKey with the value of object at key.
836      */

837     public ObjectKey getObjectKey(String JavaDoc name)
838     {
839         return (ObjectKey) getCriterion(name).getValue();
840     }
841
842     /**
843      * Convenience method to return an ObjectKey.
844      *
845      * @param table String name of table.
846      * @param column String name of column.
847      * @return A String with the value of object at key.
848      */

849     public ObjectKey getObjectKey(String JavaDoc table, String JavaDoc column)
850     {
851         return getObjectKey(
852                 new StringBuffer JavaDoc(table.length() + column.length() + 1)
853                 .append(table).append('.').append(column)
854                 .toString());
855     }
856
857     /**
858      * Overrides Hashtable get, so that the value placed in the
859      * Criterion is returned instead of the Criterion.
860      *
861      * @param key An Object.
862      * @return An Object.
863      */

864     public Object JavaDoc get(Object JavaDoc key)
865     {
866         return getValue((String JavaDoc) key);
867     }
868
869     /**
870      * Overrides Hashtable put, so that this object is returned
871      * instead of the value previously in the Criteria object.
872      * The reason is so that it more closely matches the behavior
873      * of the add() methods. If you want to get the previous value
874      * then you should first Criteria.get() it yourself. Note, if
875      * you attempt to pass in an Object that is not a String, it will
876      * throw a NPE. The reason for this is that none of the add()
877      * methods support adding anything other than a String as a key.
878      *
879      * @param key An Object. Must be instanceof String!
880      * @param value An Object.
881      * @throws NullPointerException if key != String