Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.postgresql.fastpath
Class Fastpath  view Fastpath download Fastpath.java

java.lang.Object
  extended byorg.postgresql.fastpath.Fastpath

public class Fastpath
extends java.lang.Object

This class implements the Fastpath api.

This is a means of executing functions imbeded in the org.postgresql backend from within a java application.

It is based around the file src/interfaces/libpq/fe-exec.c

Implementation notes:

Network protocol:

The code within the backend reads integers in reverse.

There is work in progress to convert all of the protocol to network order but it may not be there for v6.3

When fastpath switches, simply replace SendIntegerReverse() with SendInteger()


Field Summary
protected  org.postgresql.Connection conn
           
protected  java.util.Hashtable func
           
protected  org.postgresql.PG_Stream stream
           
 
Constructor Summary
Fastpath(org.postgresql.Connection conn, org.postgresql.PG_Stream stream)
          Initialises the fastpath system
 
Method Summary
 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.
 java.lang.Object fastpath(int fnid, boolean resulttype, FastpathArg[] args)
          Send a function call to the PostgreSQL backend
 java.lang.Object fastpath(java.lang.String name, boolean resulttype, 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 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

func

protected java.util.Hashtable func

conn

protected org.postgresql.Connection conn

stream

protected org.postgresql.PG_Stream stream
Constructor Detail

Fastpath

public Fastpath(org.postgresql.Connection conn,
                org.postgresql.PG_Stream stream)
Initialises the fastpath system

Important Notice
This is called from org.postgresql.Connection, and should not be called from client code.

Method Detail

fastpath

public java.lang.Object fastpath(int fnid,
                                 boolean resulttype,
                                 FastpathArg[] args)
                          throws java.sql.SQLException
Send a function call to the PostgreSQL backend


fastpath

public java.lang.Object fastpath(java.lang.String name,
                                 boolean resulttype,
                                 FastpathArg[] args)
                          throws java.sql.SQLException
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 prefered 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


getInteger

public int getInteger(java.lang.String name,
                      FastpathArg[] args)
               throws java.sql.SQLException
This convenience method assumes that the return value is an Integer


getData

public byte[] getData(java.lang.String name,
                      FastpathArg[] args)
               throws java.sql.SQLException
This convenience method assumes that the return value is an Integer


addFunction

public void addFunction(java.lang.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.


addFunctions

public void addFunctions(java.sql.ResultSet rs)
                  throws java.sql.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 Hashtable is used. Also, only the function's required are entered into this table, keeping connection times as fast as possible.

The org.postgresql.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.


getID

public int getID(java.lang.String name)
          throws java.sql.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.