KickJava   Java API By Example, From Geeks To Geeks.

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


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: PostgreSQLColumnInfo.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 specific table column in PostgreSQL.
19  *
20  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
21  * @version $Revision: 1.2 $
22  */

23
24 class PostgreSQLColumnInfo extends ColumnInfo
25 {
26     /**
27      * Constructs a column information object from the current row of the given
28      * result set. The {@link ResultSet} object passed must have been obtained
29      * from a call to DatabaseMetaData.getColumns().
30      *
31      * <p>This method only retrieves the values from the current row; the caller
32      * is required to advance to the next row with {@link ResultSet#next}.
33      *
34      * @param rs The result set returned from DatabaseMetaData.getColumns().
35      */

36
37     public PostgreSQLColumnInfo(ResultSet JavaDoc rs)
38     {
39         super(rs);
40
41         if (typeName.equalsIgnoreCase("text"))
42             dataType = Types.LONGVARCHAR;
43         else if (typeName.equalsIgnoreCase("bytea"))
44             dataType = Types.LONGVARBINARY;
45
46         /*
47          * The PostgreSQL drivers sometimes produce some truly funky metadata.
48          * I saw these next two occur during unit testing when
49          * decimal_widget.big_decimal_field reported a columnSize of 65535 and
50          * a decimalDigits of 65534, instead of the correct answers of 18 and 2.
51          *
52          * A -1 for either of these will cause their validation to be bypassed,
53          * which is a shame but it's all we can do. No one should be surprised
54          * if we end up needing more of these.
55          */

56         if (columnSize > PostgreSQLTypeInfo.MAX_PRECISION)
57             columnSize = -1;
58
59         if (decimalDigits > PostgreSQLTypeInfo.MAX_PRECISION)
60             decimalDigits = -1;
61     }
62 }
63
Popular Tags