public class Fastpath
extends java.lang.Object
This is a means of executing functions embedded in the backend from within a java application.
It is based around the file src/interfaces/libpq/fe-exec.c
Constructor and Description |
---|
Fastpath(org.postgresql.core.BaseConnection conn)
Initialises the fastpath system
|
Modifier and Type | Method and Description |
---|---|
void |
addFunction(java.lang.String name,
int fnid)
This adds a function to our lookup table.
|
void |
addFunctions(java.sql.ResultSet rs)
This takes a ResultSet containing two columns.
|
static FastpathArg |
createOIDArg(long oid)
Creates a FastpathArg with an oid parameter.
|
java.lang.Object |
fastpath(int fnId,
boolean resultType,
FastpathArg[] args)
Deprecated.
please use
fastpath(int, FastpathArg[]) |
byte[] |
fastpath(int fnId,
FastpathArg[] args)
Send a function call to the PostgreSQL backend
|
java.lang.Object |
fastpath(java.lang.String name,
boolean resulttype,
FastpathArg[] args)
Deprecated.
Use
getData(String, FastpathArg[]) if you expect a binary result,
or one of getInteger(String, FastpathArg[]) or getLong(String, FastpathArg[]) if you
expect a numeric one |
byte[] |
fastpath(java.lang.String name,
FastpathArg[] args)
Send a function call to the PostgreSQL backend by name.
|
byte[] |
getData(java.lang.String name,
FastpathArg[] args)
This convenience method assumes that the return value is not an Integer
|
int |
getID(java.lang.String name)
This returns the function id associated by its name.
|
int |
getInteger(java.lang.String name,
FastpathArg[] args)
This convenience method assumes that the return value is an integer
|
long |
getLong(java.lang.String name,
FastpathArg[] args)
This convenience method assumes that the return value is a long (bigint)
|
long |
getOID(java.lang.String name,
FastpathArg[] args)
This convenience method assumes that the return value is an oid.
|
public Fastpath(org.postgresql.core.BaseConnection conn)
conn
- BaseConnection to attach to@Deprecated public java.lang.Object fastpath(int fnId, boolean resultType, FastpathArg[] args) throws java.sql.SQLException
fastpath(int, FastpathArg[])
fnId
- Function idresultType
- True if the result is a numeric (Integer or Long)args
- FastpathArguments to pass to fastpathjava.sql.SQLException
- if a database-access error occurs.public byte[] fastpath(int fnId, FastpathArg[] args) throws java.sql.SQLException
fnId
- Function idargs
- FastpathArguments to pass to fastpathjava.sql.SQLException
- if a database-access error occurs.@Deprecated public java.lang.Object fastpath(java.lang.String name, boolean resulttype, FastpathArg[] args) throws java.sql.SQLException
getData(String, FastpathArg[])
if you expect a binary result,
or one of getInteger(String, FastpathArg[])
or getLong(String, FastpathArg[])
if you
expect a numeric onename
- Function nameresultType
- True if the result is a numeric (Integer or Long)args
- FastpathArguments to pass to fastpathjava.sql.SQLException
fastpath(int, FastpathArg[])
,
fastpath(String, FastpathArg[])
public byte[] fastpath(java.lang.String name, FastpathArg[] args) throws java.sql.SQLException
name
- Function nameargs
- FastpathArguments to pass to fastpathjava.sql.SQLException
- if name is unknown or if a database-access error
occurs.LargeObject
public int getInteger(java.lang.String name, FastpathArg[] args) throws java.sql.SQLException
name
- Function nameargs
- Function argumentsjava.sql.SQLException
- if a database-access error occurs or no resultpublic long getLong(java.lang.String name, FastpathArg[] args) throws java.sql.SQLException
name
- Function nameargs
- Function argumentsjava.sql.SQLException
- if a database-access error occurs or no resultpublic long getOID(java.lang.String name, FastpathArg[] args) throws java.sql.SQLException
name
- Function nameargs
- Function argumentsjava.sql.SQLException
- if a database-access error occurs or no resultpublic byte[] getData(java.lang.String name, FastpathArg[] args) throws java.sql.SQLException
name
- Function nameargs
- Function argumentsjava.sql.SQLException
- if a database-access error occurs or no resultpublic void addFunction(java.lang.String name, int fnid)
User code should use the addFunctions method, which is based upon a query, rather than hard coding the oid. The oid for a function is not guaranteed to remain static, even on different servers of the same version.
name
- Function namefnid
- Function idpublic void addFunctions(java.sql.ResultSet rs) throws java.sql.SQLException
It reads the entire ResultSet, loading the values into the function table.
REMEMBER to close() the resultset after calling this!!
Implementation note about function name lookups:
PostgreSQL stores the function id's and their corresponding names in the pg_proc table. To speed things up locally, instead of querying each function from that table when required, a HashMap is used. Also, only the function's required are entered into this table, keeping connection times as fast as possible.
The org.postgresql.largeobject.LargeObject class performs a query upon it's startup, and passes the returned ResultSet to the addFunctions() method here.
Once this has been done, the LargeObject api refers to the functions by name.
Dont think that manually converting them to the oid's will work. Ok, they will for now, but they can change during development (there was some discussion about this for V7.0), so this is implemented to prevent any unwarranted headaches in the future.
rs
- ResultSetjava.sql.SQLException
- if a database-access error occurs.LargeObjectManager
public int getID(java.lang.String name) throws java.sql.SQLException
If addFunction() or addFunctions() have not been called for this name, then an SQLException is thrown.
name
- Function name to lookupjava.sql.SQLException
- is function is unknown.public static FastpathArg createOIDArg(long oid)