Source Code Cross Referenced for Field.java in  » Database-JDBC-Connection-Pool » postgresql » org » postgresql » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » postgresql » org.postgresql.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*-------------------------------------------------------------------------
002:         *
003:         * Copyright (c) 2003-2005, PostgreSQL Global Development Group
004:         *
005:         * IDENTIFICATION
006:         *   $PostgreSQL: pgjdbc/org/postgresql/core/Field.java,v 1.11 2005/12/03 21:44:08 jurka Exp $
007:         *
008:         *-------------------------------------------------------------------------
009:         */
010:        package org.postgresql.core;
011:
012:        import java.sql.*;
013:
014:        /*
015:         */
016:        public class Field {
017:            //The V3 protocol defines two constants for the format of data
018:            public static final int TEXT_FORMAT = 0;
019:            public static final int BINARY_FORMAT = 1;
020:
021:            private final int length; // Internal Length of this field
022:            private final int oid; // OID of the type
023:            private final int mod; // type modifier of this field
024:            private final String columnLabel; // Column label
025:            private String columnName; // Column name; null if undetermined
026:            private Integer nullable; // Is this column nullable? null if undetermined.
027:            private Boolean autoIncrement; // Is this column automatically numbered?
028:
029:            private int format = TEXT_FORMAT; // In the V3 protocol each field has a format
030:            // 0 = text, 1 = binary
031:            // In the V2 protocol all fields in a
032:            // binary cursor are binary and all
033:            // others are text
034:
035:            private final int tableOid; // OID of table ( zero if no table )
036:            private final int positionInTable;
037:
038:            // cache-fields
039:
040:            /*
041:             * Construct a field based on the information fed to it.
042:             *
043:             * @param name the name (column name and label) of the field
044:             * @param oid the OID of the field
045:             * @param len the length of the field
046:             */
047:            public Field(String name, int oid, int length, int mod) {
048:                this (name, name, oid, length, mod, 0, 0);
049:            }
050:
051:            /*
052:             * Constructor without mod parameter.
053:             *
054:             * @param name the name (column name and label) of the field
055:             * @param oid the OID of the field
056:             * @param len the length of the field
057:             */
058:            public Field(String name, int oid) {
059:                this (name, oid, 0, -1);
060:            }
061:
062:            /*
063:             * Construct a field based on the information fed to it.
064:             *
065:             * @param columnLabel the column label of the field
066:             * @param columnName the column label the name of the field
067:             * @param oid the OID of the field
068:             * @param length the length of the field
069:             * @param tableOid the OID of the columns' table
070:             * @param positionInTable the position of column in the table (first column is 1, second column is 2, etc...)
071:             */
072:            public Field(String columnLabel, String columnName, int oid,
073:                    int length, int mod, int tableOid, int positionInTable) {
074:                this .columnLabel = columnLabel;
075:                this .columnName = columnName;
076:                this .oid = oid;
077:                this .length = length;
078:                this .mod = mod;
079:                this .tableOid = tableOid;
080:                this .positionInTable = positionInTable;
081:            }
082:
083:            /*
084:             * @return the oid of this Field's data type
085:             */
086:            public int getOID() {
087:                return oid;
088:            }
089:
090:            /*
091:             * @return the mod of this Field's data type
092:             */
093:            public int getMod() {
094:                return mod;
095:            }
096:
097:            /*
098:             * @return the column label of this Field's data type
099:             */
100:            public String getColumnLabel() {
101:                return columnLabel;
102:            }
103:
104:            /*
105:             * @return the length of this Field's data type
106:             */
107:            public int getLength() {
108:                return length;
109:            }
110:
111:            /*
112:             * @return the format of this Field's data (text=0, binary=1)
113:             */
114:            public int getFormat() {
115:                return format;
116:            }
117:
118:            /*
119:             * @param format the format of this Field's data (text=0, binary=1)
120:             */
121:            public void setFormat(int format) {
122:                this .format = format;
123:            }
124:
125:            /*
126:             * @return the columns' table oid, zero if no oid available
127:             */
128:            public int getTableOid() {
129:                return tableOid;
130:            }
131:
132:            public int getPositionInTable() {
133:                return positionInTable;
134:            }
135:
136:            public int getNullable(Connection con) throws SQLException {
137:                if (nullable != null)
138:                    return nullable.intValue();
139:
140:                if (tableOid == 0 || positionInTable == 0) {
141:                    nullable = new Integer(
142:                            ResultSetMetaData.columnNullableUnknown);
143:                    return nullable.intValue();
144:                }
145:
146:                ResultSet res = null;
147:                PreparedStatement ps = null;
148:                try {
149:                    ps = con
150:                            .prepareStatement("SELECT attnotnull FROM pg_catalog.pg_attribute WHERE attrelid = ? AND attnum = ?;");
151:                    ps.setInt(1, tableOid);
152:                    ps.setInt(2, positionInTable);
153:                    res = ps.executeQuery();
154:
155:                    int nullResult = ResultSetMetaData.columnNullableUnknown;
156:                    if (res.next())
157:                        nullResult = res.getBoolean(1) ? ResultSetMetaData.columnNoNulls
158:                                : ResultSetMetaData.columnNullable;
159:
160:                    nullable = new Integer(nullResult);
161:                    return nullResult;
162:                } finally {
163:                    if (res != null)
164:                        res.close();
165:                    if (ps != null)
166:                        ps.close();
167:                }
168:            }
169:
170:            public boolean getAutoIncrement(Connection con) throws SQLException {
171:                if (autoIncrement != null)
172:                    return autoIncrement.booleanValue();
173:
174:                if (tableOid == 0 || positionInTable == 0) {
175:                    autoIncrement = Boolean.FALSE;
176:                    return autoIncrement.booleanValue();
177:                }
178:
179:                ResultSet res = null;
180:                PreparedStatement ps = null;
181:                try {
182:                    final String sql = "SELECT def.adsrc FROM pg_catalog.pg_class c "
183:                            + "JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid) "
184:                            + "LEFT JOIN pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) "
185:                            + "WHERE c.oid = ? and a.attnum = ? AND def.adsrc LIKE '%nextval(%'";
186:
187:                    ps = con.prepareStatement(sql);
188:
189:                    ps.setInt(1, tableOid);
190:                    ps.setInt(2, positionInTable);
191:                    res = ps.executeQuery();
192:
193:                    if (res.next()) {
194:                        autoIncrement = Boolean.TRUE;
195:                    } else {
196:                        autoIncrement = Boolean.FALSE;
197:                    }
198:                    return autoIncrement.booleanValue();
199:
200:                } finally {
201:                    if (res != null)
202:                        res.close();
203:                    if (ps != null)
204:                        ps.close();
205:                }
206:            }
207:
208:            public String getColumnName(Connection con) throws SQLException {
209:                if (columnName != null)
210:                    return columnName;
211:
212:                columnName = "";
213:                if (tableOid == 0 || positionInTable == 0) {
214:                    return columnName;
215:                }
216:
217:                ResultSet res = null;
218:                PreparedStatement ps = null;
219:                try {
220:                    ps = con
221:                            .prepareStatement("SELECT attname FROM pg_catalog.pg_attribute WHERE attrelid = ? AND attnum = ?");
222:                    ps.setInt(1, tableOid);
223:                    ps.setInt(2, positionInTable);
224:                    res = ps.executeQuery();
225:                    if (res.next())
226:                        columnName = res.getString(1);
227:
228:                    return columnName;
229:                } finally {
230:                    if (res != null)
231:                        res.close();
232:                    if (ps != null)
233:                        ps.close();
234:                }
235:            }
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.