1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/*-------------------------------------------------------------------------
*
* Copyright (c) 2003-2011, PostgreSQL Global Development Group
*
*
*-------------------------------------------------------------------------
*/
package org.postgresql.core;
import java.sql.ResultSetMetaData;
/*
*/
public class Field
{
//The V3 protocol defines two constants for the format of data
public static final int TEXT_FORMAT = 0;
public static final int BINARY_FORMAT = 1;
private final int length; // Internal Length of this field
private final int oid; // OID of the type
private final int mod; // type modifier of this field
private final String columnLabel; // Column label
private String columnName; // Column name
private int format = TEXT_FORMAT; // In the V3 protocol each field has a format
// 0 = text, 1 = binary
// In the V2 protocol all fields in a
// binary cursor are binary and all
// others are text
private final int tableOid; // OID of table ( zero if no table )
private final int positionInTable;
// Cache fields filled in by AbstractJdbc2ResultSetMetaData.fetchFieldMetaData.
// Don't use unless that has been called.
private String tableName = "";
private String schemaName = "";
private int nullable = ResultSetMetaData.columnNullableUnknown;
private boolean autoIncrement = false;
/*
* Construct a field based on the information fed to it.
*
* @param name the name (column name and label) of the field
* @param oid the OID of the field
* @param len the length of the field
*/
public Field(String name, int oid, int length, int mod)
{
this(name, name, oid, length, mod, 0, 0);
}
/*
* Constructor without mod parameter.
*
* @param name the name (column name and label) of the field
* @param oid the OID of the field
* @param len the length of the field
*/
public Field(String name, int oid)
{
this(name, oid, 0, -1);
}
/*
* Construct a field based on the information fed to it.
*
* @param columnLabel the column label of the field
* @param columnName the column label the name of the field
* @param oid the OID of the field
* @param length the length of the field
* @param tableOid the OID of the columns' table
* @param positionInTable the position of column in the table (first column is 1, second column is 2, etc...)
*/
public Field(String columnLabel, String columnName, int oid, int length, int mod, int tableOid, int positionInTable)
{
this.columnLabel = columnLabel;
this.columnName = columnName;
this.oid = oid;
this.length = length;
this.mod = mod;
this.tableOid = tableOid;
this.positionInTable = positionInTable;
}
/*
* @return the oid of this Field's data type
*/
public int getOID()
{
return oid;
}
/*
* @return the mod of this Field's data type
*/
public int getMod()
{
return mod;
}
/*
* @return the column label of this Field's data type
*/
public String getColumnLabel()
{
return columnLabel;
}
/*
* @return the length of this Field's data type
*/
public int getLength()
{
return length;
}
/*
* @return the format of this Field's data (text=0, binary=1)
*/
public int getFormat()
{
return format;
}
/*
* @param format the format of this Field's data (text=0, binary=1)
*/
public void setFormat(int format)
{
this.format = format;
}
/*
* @return the columns' table oid, zero if no oid available
*/
public int getTableOid()
{
return tableOid;
}
public int getPositionInTable()
{
return positionInTable;
}
public void setNullable(int nullable)
{
this.nullable = nullable;
}
public int getNullable()
{
return nullable;
}
public void setAutoIncrement(boolean autoIncrement)
{
this.autoIncrement = autoIncrement;
}
public boolean getAutoIncrement()
{
return autoIncrement;
}
public void setColumnName(String columnName)
{
this.columnName = columnName;
}
public String getColumnName()
{
return columnName;
}
public void setTableName(String tableName)
{
this.tableName = tableName;
}
public String getTableName()
{
return tableName;
}
public void setSchemaName(String schemaName)
{
this.schemaName = schemaName;
}
public String getSchemaName()
{
return schemaName;
}
public String toString() {
return "Field("+ (columnName != null ? columnName : "") + "," +
Oid.toString(oid) + "," + length + "," +
(format == TEXT_FORMAT ? 'T' : 'B') + ")";
}
}
|