Top Description Fields Constructors Methods
org.postgresql.fastpath

public Class Fastpath

extends Object
Class Inheritance
Annotations
@Deprecated
Static Imports
org.postgresql.util.internal.Nullness.castNonNull

Deprecated

This API is somewhat obsolete, as one may achieve similar performance and greater functionality by setting up a prepared statement to define the function call. Then, executing the statement with binary transmission of parameters and results substitutes for a fast-path function call.

This class implements the Fastpath api.

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

Field Summary

Modifier and TypeField and Description
private final BaseConnection
private final QueryExecutor
private final Map<String, Integer>
private static final long

Constructor Summary

AccessConstructor and Description
public
Fastpath(BaseConnection
BaseConnection to attach to
conn
)

Initialises the fastpath system.

Method Summary

Modifier and TypeMethod and Description
public void
addFunction(String
Function name
name
,
int
Function id
fnid
)

This adds a function to our lookup table.

public void
addFunctions(ResultSet
ResultSet
rs
)

This takes a ResultSet containing two columns.

public static FastpathArg

Returns:

FastpathArg with an oid parameter
createOIDArg
(long
input oid
oid
)
References Deprecated FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

Creates a FastpathArg with an oid parameter.

public @Nullable Object

Returns:

null if no data, Integer if an integer result, Long if a long result, or byte[] otherwise
fastpath
(int
Function id
fnId
,
boolean
True if the result is a numeric (Integer or Long)
resultType
,
FastpathArg[]
FastpathArguments to pass to fastpath
args
)
Deprecated please use fastpath(int, FastpathArg[])

Send a function call to the PostgreSQL backend.

public @Nullable byte[]

Returns:

null if no data, byte[] otherwise
fastpath
(int
Function id
fnId
,
FastpathArg[]
FastpathArguments to pass to fastpath
args
)
References Deprecated FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

Send a function call to the PostgreSQL backend.

public @Nullable Object

Returns:

null if no data, Integer if an integer result, Long if a long result, or byte[] otherwise
fastpath
(String
Function name
name
,
boolean
True if the result is a numeric (Integer or Long)
resulttype
,
FastpathArg[]
FastpathArguments to pass to fastpath
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

public @Nullable byte[]

Returns:

null if no data, byte[] otherwise
fastpath
(String
Function name
name
,
FastpathArg[]
FastpathArguments to pass to fastpath
args
)
References Deprecated FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

Send a function call to the PostgreSQL backend by name.

public @Nullable byte[]

Returns:

byte[] array containing result
getData
(String
Function name
name
,
FastpathArg[]
Function arguments
args
)
References Deprecated FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

This convenience method assumes that the return value is not an Integer.

public int

Returns:

Function ID for fastpath call
getID
(String
Function name to lookup
name
)

This returns the function id associated by its name.

public int

Returns:

integer result
getInteger
(String
Function name
name
,
FastpathArg[]
Function arguments
args
)
References Deprecated FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

This convenience method assumes that the return value is an integer.

public long

Returns:

long result
getLong
(String
Function name
name
,
FastpathArg[]
Function arguments
args
)
References Deprecated FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

This convenience method assumes that the return value is a long (bigint).

public long

Returns:

oid of the given call
getOID
(String
Function name
name
,
FastpathArg[]
Function arguments
args
)
References Deprecated FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

This convenience method assumes that the return value is an oid.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionback to summary
private final BaseConnection connection
executorback to summary
private final QueryExecutor executor
funcback to summary
private final Map<String, Integer> func
NUM_OIDSback to summary
private static final long NUM_OIDS

Constructor Detail

Fastpathback to summary
public Fastpath(BaseConnection conn)

Initialises the fastpath system.

Parameters
conn:BaseConnection

BaseConnection to attach to

Method Detail

addFunctionback to summary
public void addFunction(String name, int fnid)

This adds a function to our lookup table.

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.

Parameters
name:String

Function name

fnid:int

Function id

addFunctionsback to summary
public void addFunctions(ResultSet rs) throws SQLException

This takes a ResultSet containing two columns. Column 1 contains the function name, Column 2 the oid.

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.

Don't 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.

Parameters
rs:ResultSet

ResultSet

Exceptions
SQLException:
if a database-access error occurs.
See Also
org.postgresql.largeobject.LargeObjectManager
createOIDArgback to summary
public static FastpathArg createOIDArg(long oid)

References Deprecated

FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Creates a FastpathArg with an oid parameter. This is here instead of a constructor of FastpathArg because the constructor can't tell the difference between an long that's really int8 and a long thats an oid.

Parameters
oid:long

input oid

Returns:FastpathArg

FastpathArg with an oid parameter

fastpathback to summary
public @Nullable Object fastpath(int fnId, boolean resultType, FastpathArg[] args) throws SQLException

Deprecated

please use fastpath(int, FastpathArg[])

Send a function call to the PostgreSQL backend.

Parameters
fnId:int

Function id

resultType:boolean

True if the result is a numeric (Integer or Long)

args:FastpathArg[]

FastpathArguments to pass to fastpath

Returns:@Nullable Object

null if no data, Integer if an integer result, Long if a long result, or byte[] otherwise

Annotations
@Deprecated
Exceptions
SQLException:
if a database-access error occurs.
fastpathback to summary
public @Nullable byte[] fastpath(int fnId, FastpathArg[] args) throws SQLException

References Deprecated

FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Send a function call to the PostgreSQL backend.

Parameters
fnId:int

Function id

args:FastpathArg[]

FastpathArguments to pass to fastpath

Returns:@Nullable byte[]

null if no data, byte[] otherwise

Exceptions
SQLException:
if a database-access error occurs.
fastpathback to summary
public @Nullable Object fastpath(String name, boolean resulttype, FastpathArg[] args) throws SQLException

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

Parameters
name:String

Function name

resulttype:boolean

True if the result is a numeric (Integer or Long)

args:FastpathArg[]

FastpathArguments to pass to fastpath

Returns:@Nullable Object

null if no data, Integer if an integer result, Long if a long result, or byte[] otherwise

Annotations
@Deprecated
Exceptions
SQLException:
if something goes wrong
See Also
fastpath(int, FastpathArg[]), fastpath(String, FastpathArg[])
fastpathback to summary
public @Nullable byte[] fastpath(String name, FastpathArg[] args) throws SQLException

References Deprecated

FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Send a function call to the PostgreSQL backend by name.

Note

the mapping for the procedure name to function id needs to exist, usually to an earlier call to addfunction().

This is the preferred method to call, as function id's can/may change between versions of the backend.

For an example of how this works, refer to org.postgresql.largeobject.LargeObject

Parameters
name:String

Function name

args:FastpathArg[]

FastpathArguments to pass to fastpath

Returns:@Nullable byte[]

null if no data, byte[] otherwise

Exceptions
SQLException:
if name is unknown or if a database-access error occurs.
See Also
org.postgresql.largeobject.LargeObject
getDataback to summary
public @Nullable byte[] getData(String name, FastpathArg[] args) throws SQLException

References Deprecated

FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

This convenience method assumes that the return value is not an Integer.

Parameters
name:String

Function name

args:FastpathArg[]

Function arguments

Returns:@Nullable byte[]

byte[] array containing result

Exceptions
SQLException:
if a database-access error occurs or no result
getIDback to summary
public int getID(String name) throws SQLException

This returns the function id associated by its name.

If addFunction() or addFunctions() have not been called for this name, then an SQLException is thrown.

Parameters
name:String

Function name to lookup

Returns:int

Function ID for fastpath call

Exceptions
SQLException:
is function is unknown.
getIntegerback to summary
public int getInteger(String name, FastpathArg[] args) throws SQLException

References Deprecated

FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

This convenience method assumes that the return value is an integer.

Parameters
name:String

Function name

args:FastpathArg[]

Function arguments

Returns:int

integer result

Exceptions
SQLException:
if a database-access error occurs or no result
getLongback to summary
public long getLong(String name, FastpathArg[] args) throws SQLException

References Deprecated

FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

This convenience method assumes that the return value is a long (bigint).

Parameters
name:String

Function name

args:FastpathArg[]

Function arguments

Returns:long

long result

Exceptions
SQLException:
if a database-access error occurs or no result
getOIDback to summary
public long getOID(String name, FastpathArg[] args) throws SQLException

References Deprecated

FastpathArg is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

This convenience method assumes that the return value is an oid.

Parameters
name:String

Function name

args:FastpathArg[]

Function arguments

Returns:long

oid of the given call

Exceptions
SQLException:
if a database-access error occurs or no result