The Connection class, part of the org.postgresql package, is the Red Hat Database JDBC driver's implementation of java.sql.Connection. The org.postgresql.Connection defines three methods in addition to the methods required by the java.sql.Connection interface.
package org.postgresql; public class Connection implements java.sql.Connection { // Methods (new; java.sql.Connection methods not listed) public void addDataType(String type, String name); public Fastpath getFastpathAPI() throws SQLException; public LargeObjectManager getLargeObjectAPI() throws SQLException; } |
This method allows client code to add handlers for data types unique to Red Hat Database, including user-defined data types. Normally, a data type not known by the driver is returned by ResultSet.getObject() as a PGobject instance. The addDataType enables you to write a class that extends PGobject and to tell the driver the type name and class name to be used instead. Handler registration is per connection instance, so this method needs to be called each time a database connection is made.
Parameters.
The name of the data type.
The fully qualified name of the handler class that should be used for the type.
Example.
import org.postgresql.Connection; ... ((org.postgresql.Connection) con).addDataType("mytype", "my.class.name"); |
This returns the Fastpath API of the connection.
Example.
import org.postgresql.Connection; import org.postgresql.fastpath.*; ... Fastpath fp = ((org.postgresql.Connection) con).getFastpathAPI(); |
This returns the LargeObjectManager that the connection is using.
Example.
import org.postgresql.Connection; import org.postgresql.largeobject.*; ... LargeObjectManager lom = ((org.postgresql.Connection) con).getLargeObjectAPI(); |
Fastpath is an API that allows a client machine to execute a function on the database backend. Most client code will not need to use this method, but it is provided because the Large Object API uses it.
To use the Fastpath as an API, you need to import the org.postgresql.fastpath package in the preamble of the source file in which Fastpath will be used. A Fastpath object that is associated with a given database connection can be obtained by requesting one from the Connection object (cast to org.postgresql.Connection). For example:
import org.postgresql.Connection; import org.postgresql.fastpath.*; ... Fastpath fp = ((org.postgresql.Connection) con).getFastpathAPI(); |
public void addFunction(String name, int fnid) |
This method adds a function to the function name-to-OID look-up table used internally by the Fastpath API. User code should use the addFunctions method, which is based upon a query, rather than hard coding the OID as the OID for a function is not guaranteed to remain static even on different servers of the same version.
Parameters.
The name of the function.
The OID of the function.
This method takes a ResultSet containing two columns as its argument. The first column contains a function name; the second contains that function's OID. The addFunctions method reads the entire ResultSet, loading the values into its internal function name-to-OID mapping table.
Parameters.
The ResultSet.
This method sends a function call to the Red Hat Database backend that the Fastpath object is associated with. This version of Fastpath calls a function by OID.
Parameters.
The OID of the function to call.
True if the result is an integer, false for other results.
Fastpath arguments.
Returns. If no data, null; if the result of the function call is an integer, an Integer; otherwise: byte[]
The fastpath method sends a function call to the Red Hat Database backend that the Fastpath object is associated with. This version of Fastpath calls a function by name.
Parameters.
The name of the function to call.
True if the result is an integer, false for other results.
Fastpath arguments.
Returns. If no data, null; if the result of the function call is an integer, an Integer; otherwise: byte[]
getData is a wrapper method around Fastpath that assumes that the function to be called returns binary data.
Parameters.
Name of the function to call.
Fastpath arguments.
Returns. A byte array that contains the result.
getID returns the OID of the function associated with the given function name. If the function name is not in the lookup table (that is: if either addFunction() or addFunctions() has not been called), then an SQLException is thrown.
Parameters.
Name of the function to get OID of.
getInteger is a wrapper method for fastpath that assumes that the function to be called returns an integer value.
Parameters.
Name of the function to call.
Fastpath arguments.
Returns. A byte array that contains the result.
Each fastpath call requires an array of arguments, the number and type being dependent on the function being called. This class implements the methods needed to provide this capability.
package org.postgresql.fastpath; public class FastpathArg { public FastpathArg(int value); public FastpathArg(byte[] bytes); public FastpathArg(byte[] buf, int off, int len); public FastpathArg(String s); } |
Constructs an argument that consists of a single integer.
Parameters.
The value that will be used as argument.
Constructs an argument that consists of an array of bytes.
Parameters.
Array of bytes to use as argument.
Constructs an argument that consists of part of an array of bytes.
Parameters.
source array
offset within array
length of data to include
Constructs an argument that consists of a String.
Parameters.
String that will be used as argument.