NOTE: This is not part of JDBC, but allows access to * functions on the org.postgresql backend itself. * *
It is primarily used by the LargeObject API * *
The best way to use this is as follows: * *
     * import org.postgresql.fastpath.*;
     * ...
     * Fastpath fp = ((org.postgresql.Connection)myconn).getFastpathAPI();
     * 
     *
     * where myconn is an open Connection to org.postgresql. * * @return Fastpath object allowing access to functions on the org.postgresql * backend. * @exception SQLException by Fastpath when initialising for first time */ public Fastpath getFastpathAPI() throws SQLException { if(fastpath==null) fastpath = new Fastpath(this,pg_stream); return fastpath; } // This holds a reference to the Fastpath API if already open private Fastpath fastpath = null; /** * This returns the LargeObject API for the current connection. * *
NOTE: This is not part of JDBC, but allows access to * functions on the org.postgresql backend itself. * *
The best way to use this is as follows: * *
     * import org.postgresql.largeobject.*;
     * ...
     * LargeObjectManager lo = ((org.postgresql.Connection)myconn).getLargeObjectAPI();
     * 
     *
     * where myconn is an open Connection to org.postgresql. * * @return LargeObject object that implements the API * @exception SQLException by LargeObject when initialising for first time */ public LargeObjectManager getLargeObjectAPI() throws SQLException { if(largeobject==null) largeobject = new LargeObjectManager(this); return largeobject; } // This holds a reference to the LargeObject API if already open private LargeObjectManager largeobject = null; /** * This method is used internally to return an object based around * org.postgresql's more unique data types. * *
It uses an internal Hashtable to get the handling class. If the * type is not supported, then an instance of org.postgresql.util.PGobject * is returned. * * You can use the getValue() or setValue() methods to handle the returned * object. Custom objects can have their own methods. * * In 6.4, this is extended to use the org.postgresql.util.Serialize class to * allow the Serialization of Java Objects into the database without using * Blobs. Refer to that class for details on how this new feature works. * * @return PGobject for this type, and set to value * @exception SQLException if value is not correct for this type * @see org.postgresql.util.Serialize */ public Object getObject(String type,String value) throws SQLException { try { Object o = objectTypes.get(type); // If o is null, then the type is unknown, so check to see if type // is an actual table name. If it does, see if a Class is known that // can handle it if(o == null) { Serialize ser = new Serialize(this,type); objectTypes.put(type,ser); return ser.fetch(Integer.parseInt(value)); } // If o is not null, and it is a String, then its a class name that // extends PGobject. // // This is used to implement the org.postgresql unique types (like lseg, // point, etc). if(o instanceof String) { // 6.3 style extending PG_Object PGobject obj = null; obj = (PGobject)(Class.forName((String)o).newInstance()); obj.setType(type); obj.setValue(value); return (Object)obj; } else { // If it's an object, it should be an instance of our Serialize class // If so, then call it's fetch method. if(o instanceof Serialize) return ((Serialize)o).fetch(Integer.parseInt(value)); } } catch(SQLException sx) { // rethrow the exception. Done because we capture any others next sx.fillInStackTrace(); throw sx; } catch(Exception ex) { throw new PSQLException("postgresql.con.creobj",type,ex); } // should never be reached return null; } /** * This stores an object into the database. * @param o Object to store * @return OID of the new rectord * @exception SQLException if value is not correct for this type * @see org.postgresql.util.Serialize */ public int putObject(Object o) throws SQLException { try { String type = o.getClass().getName(); Object x = objectTypes.get(type); // If x is null, then the type is unknown, so check to see if type // is an actual table name. If it does, see if a Class is known that // can handle it if(x == null) { Serialize ser = new Serialize(this,type); objectTypes.put(type,ser); return ser.store(o); } // If it's an object, it should be an instance of our Serialize class // If so, then call it's fetch method. if(x instanceof Serialize) return ((Serialize)x).store(o); // Thow an exception because the type is unknown throw new PSQLException("postgresql.con.strobj"); } catch(SQLException sx) { // rethrow the exception. Done because we capture any others next sx.fillInStackTrace(); throw sx; } catch(Exception ex) { throw new PSQLException("postgresql.con.strobjex",ex); } } /** * This allows client code to add a handler for one of org.postgresql's * more unique data types. * *
NOTE: This is not part of JDBC, but an extension. * *
The best way to use this is as follows: * *
     * ...
     * ((org.postgresql.Connection)myconn).addDataType("mytype","my.class.name");
     * ...
     * 
     *
     * where myconn is an open Connection to org.postgresql. * *
The handling class must extend org.postgresql.util.PGobject
     *
     * @see org.postgresql.util.PGobject
     */
    public void addDataType(String type,String name)
    {
	objectTypes.put(type,name);
    }
    
    // This holds the available types
    private Hashtable objectTypes = new Hashtable();
    
    // This array contains the types that are supported as standard.
    //
    // The first entry is the types name on the database, the second
    // the full class name of the handling class.
    //
    private static final String defaultObjectTypes[][] = {
	{"box",		"org.postgresql.geometric.PGbox"},
	{"circle",	"org.postgresql.geometric.PGcircle"},
	{"line",	"org.postgresql.geometric.PGline"},
	{"lseg",	"org.postgresql.geometric.PGlseg"},
	{"path",	"org.postgresql.geometric.PGpath"},
	{"point",	"org.postgresql.geometric.PGpoint"},
	{"polygon",	"org.postgresql.geometric.PGpolygon"},
	{"money",	"org.postgresql.util.PGmoney"}
    };
    
    // This initialises the objectTypes hashtable
    private void initObjectTypes()
    {
	for(int i=0;i