2
* Copyright (c) 2004, 2005 TADA AB - Taby Sweden
2
* Copyright (c) 2004, 2005, 2006 TADA AB - Taby Sweden
3
3
* Distributed under the terms shown in the file COPYRIGHT
4
4
* found in the root folder of this project or at
5
5
* http://eng.tada.se/osprojects/COPYRIGHT.html
36
private static final HashMap s_class2typeId = new HashMap();
37
private static final HashMap s_typeId2class = new HashMap();
40
* Finds the PostgreSQL well known Oid for the given class.
41
* @param clazz The class.
42
* @return The well known Oid or null if no such Oid could be found.
44
public static Oid forJavaClass(Class clazz)
46
return (Oid)s_class2typeId.get(clazz);
50
* Finds the PostgreSQL well known Oid for a type name.
51
* @param typeString The name of the type, optionally qualified with a namespace.
52
* @return The well known Oid.
53
* @throws SQLException if the type could not be found
55
public static Oid forTypeName(String typeString)
57
synchronized(Backend.THREADLOCK)
59
return new Oid(_forTypeName(typeString));
64
* Finds the PostgreSQL well known Oid for the XOPEN Sql type.
65
* @param sqlType The XOPEN type code.
66
* @throws SQLException if the type could not be found
68
public static Oid forSqlType(int sqlType)
70
synchronized(Backend.THREADLOCK)
72
return new Oid(_forSqlType(sqlType));
77
* Returns the PostgreSQL type id for the Oid type.
79
public static Oid getTypeId()
81
synchronized(Backend.THREADLOCK)
88
* A Type well known to PostgreSQL but not known as a standard XOPEN
89
* SQL type can be registered here. This includes types like the Oid
90
* itself and all the geometry related types.
91
* @param clazz The Java class that corresponds to the type id.
92
* @param typeId The well known type id.
94
public static void registerType(Class clazz, Oid typeId)
96
s_class2typeId.put(clazz, typeId);
97
if(!s_typeId2class.containsKey(typeId))
98
s_typeId2class.put(typeId, clazz);
40
102
* The native Oid represented as a 32 bit quantity.
59
126
return (o == this) || ((o instanceof Oid) && ((Oid)o).m_native == m_native);
129
public float floatValue()
134
public Class getJavaClass()
137
Class c = (Class)s_typeId2class.get(this);
141
synchronized(Backend.THREADLOCK)
143
className = _getJavaClassName(m_native);
147
c = Class.forName(getCanonicalClassName(className, 0));
149
catch(ClassNotFoundException e)
151
throw new SQLException(e.getMessage());
153
s_typeId2class.put(this, c);
154
s_class2typeId.put(c, this);
160
* The native value is used as the hash code.
161
* @return The hashCode for this <code>Oid</code>.
163
public int hashCode()
168
public int intValue()
173
public long longValue()
179
* Returns a string representation of this OID.
181
public String toString()
183
return "OID(" + m_native + ')';
62
186
private static String getCanonicalClassName(String name, int nDims)
64
188
if(name.endsWith("[]"))
105
public Class getJavaClass()
108
Class c = (Class)s_typeId2class.get(this);
112
synchronized(Backend.THREADLOCK)
114
className = this._getJavaClassName();
118
c = Class.forName(getCanonicalClassName(className, 0));
120
catch(ClassNotFoundException e)
122
throw new SQLException(e.getMessage());
124
s_typeId2class.put(this, c);
125
s_class2typeId.put(c, this);
131
* The native value is used as the hash code.
132
* @return The hashCode for this <code>Oid</code>.
134
public int hashCode()
140
* A Type well known to PostgreSQL but not known as a standard XOPEN
141
* SQL type can be registered here. This includes types like the Oid
142
* itself and all the geometry related types.
143
* @param clazz The Java class that corresponds to the type id.
144
* @param typeId The well known type id.
146
public static void registerType(Class clazz, Oid typeId)
148
s_class2typeId.put(clazz, typeId);
149
if(!s_typeId2class.containsKey(typeId))
150
s_typeId2class.put(typeId, clazz);
154
* Finds the PostgreSQL well known Oid for the given class.
155
* @param clazz The class.
156
* @return The well known Oid or null if no such Oid could be found.
158
public static Oid forJavaClass(Class clazz)
160
return (Oid)s_class2typeId.get(clazz);
164
* Finds the PostgreSQL well known Oid for the XOPEN Sql type.
165
* @param sqlType The XOPEN type code.
166
* @return The well known Oid or null if no such Oid could be found.
168
public static Oid forSqlType(int sqlType)
170
synchronized(Backend.THREADLOCK)
172
return _forSqlType(sqlType);
177
* Returns the PostgreSQL type id for the Oid type.
179
public static Oid getTypeId()
181
synchronized(Backend.THREADLOCK)
188
* Returns a string representation of this OID.
190
public String toString()
192
return "OID(" + m_native + ')';
195
private native static Oid _forSqlType(int sqlType);
229
private native static int _forTypeName(String typeString);
231
private native static int _forSqlType(int sqlType);
196
233
private native static Oid _getTypeId();
198
private native String _getJavaClassName()
235
private native static String _getJavaClassName(int nativeOid)
199
236
throws SQLException;