KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > PostgreSQLTypeInfo


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: PostgreSQLTypeInfo.java,v 1.2 2004/03/22 04:58:13 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import java.sql.ResultSet JavaDoc;
14 import java.sql.Types JavaDoc;
15
16
17 /**
18  * Represents the metadata of a PostgreSQL data type.
19  *
20  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
21  * @version $Revision: 1.2 $
22  */

23
24 class PostgreSQLTypeInfo extends TypeInfo
25 {
26     /** The maximum precision we allow to be reported. */
27     public static final int MAX_PRECISION = 65000;
28
29
30     /**
31      * Constructs a type information object from the current row of the given
32      * result set. The {@link ResultSet} object passed must have been obtained
33      * from a call to DatabaseMetaData.getTypeInfo().
34      *
35      * <p>This method only retrieves the values from the current row; the caller
36      * is required to advance to the next row with {@link ResultSet#next}.
37      *
38      * @param rs The result set returned from DatabaseMetaData.getTypeInfo().
39      */

40
41     public PostgreSQLTypeInfo(ResultSet JavaDoc rs)
42     {
43         super(rs);
44
45         /*
46          * Not really sure what we should do about the precision field. None of
47          * the drivers that I've tried return a sensible value for it (the 7.2
48          * driver returned -1 for all types, the 7.3 driver returned 9 (!) for
49          * all types, both tried against a 7.2.1 server). The best I can think
50          * to do for now is make sure it has a decent value for those types
51          * where I know TJDO cares, namely VARCHAR and NUMERIC.
52          */

53
54         if (typeName.equalsIgnoreCase("varchar"))
55         {
56             /*
57              * VARCHAR gets an arbitrary maximum precision assigned to it.
58              * Requests fo anything larger than this will be converted to
59              * LONGVARCHAR (i.e. TEXT) in StringMapping.
60              */

61             precision = MAX_PRECISION;
62         }
63         else if (typeName.equalsIgnoreCase("numeric"))
64         {
65             precision = 64; // pulled from thin air
66
}
67         else if (typeName.equalsIgnoreCase("text"))
68         {
69             /* TEXT is equated to Types.LONGVARCHAR (as it should be). */
70             dataType = Types.LONGVARCHAR;
71         }
72         else if (typeName.equalsIgnoreCase("bytea"))
73         {
74             /* BYTEA is equated to Types.LONGVARBINARY (as it should be). */
75             dataType = Types.LONGVARBINARY;
76         }
77
78         if (precision > MAX_PRECISION)
79             precision = MAX_PRECISION;
80     }
81 }
82
Popular Tags