⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connection.java

📁 关系型数据库 Postgresql 6.5.2
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				    fqp++;				}			    break;			case 'D':	// Text Data Transfer			    if (fields == null)				throw new PSQLException("postgresql.con.tuple");			    tup = pg_stream.ReceiveTuple(fields.length, false);			    // This implements Statement.setMaxRows()			    if(maxrows==0 || tuples.size()<maxrows)				tuples.addElement(tup);			    break;			case 'E':	// Error Message			    msg = pg_stream.ReceiveString(4096);			    final_error = new SQLException(msg);			    hfr = true;			    break;			case 'I':	// Empty Query			    int t = pg_stream.ReceiveChar();			    			    if (t != 0)				throw new PSQLException("postgresql.con.garbled");			    if (fqp > 0)				fqp--;			    if (fqp == 0)				hfr = true;			    break;			case 'N':	// Error Notification			    addWarning(pg_stream.ReceiveString(4096));			    break;			case 'P':	// Portal Name			    String pname = pg_stream.ReceiveString(8192);			    break;			case 'T':	// MetaData Field Description			    if (fields != null)				throw new PSQLException("postgresql.con.multres");			    fields = ReceiveFields();			    break;			default:			    throw new PSQLException("postgresql.con.type",new Character((char)c));			}		}	    if (final_error != null)		throw final_error;			    return getResultSet(this, fields, tuples, recv_status, update_count);	}    }    /**     * Receive the field descriptions from the back end     *     * @return an array of the Field object describing the fields     * @exception SQLException if a database error occurs     */    private Field[] ReceiveFields() throws SQLException    {	int nf = pg_stream.ReceiveIntegerR(2), i;	Field[] fields = new Field[nf];		for (i = 0 ; i < nf ; ++i)	    {		String typname = pg_stream.ReceiveString(8192);		int typid = pg_stream.ReceiveIntegerR(4);		int typlen = pg_stream.ReceiveIntegerR(2);		fields[i] = new Field(this, typname, typid, typlen);	    }	return fields;    }        /**     * In SQL, a result table can be retrieved through a cursor that     * is named.  The current row of a result can be updated or deleted     * using a positioned update/delete statement that references the     * cursor name.     *     * We support one cursor per connection.     *     * setCursorName sets the cursor name.     *     * @param cursor the cursor name     * @exception SQLException if a database access error occurs     */    public void setCursorName(String cursor) throws SQLException    {	this.cursor = cursor;    }        /**     * getCursorName gets the cursor name.     *     * @return the current cursor name     * @exception SQLException if a database access error occurs     */    public String getCursorName() throws SQLException    {	return cursor;    }        /**     * We are required to bring back certain information by     * the DatabaseMetaData class.  These functions do that.     *     * Method getURL() brings back the URL (good job we saved it)     *     * @return the url     * @exception SQLException just in case...     */    public String getURL() throws SQLException    {	return this_url;    }        /**     * Method getUserName() brings back the User Name (again, we     * saved it)     *     * @return the user name     * @exception SQLException just in case...     */    public String getUserName() throws SQLException    {	return PG_USER;    }        /**     * This returns the Fastpath API for the current connection.     *     * <p><b>NOTE:</b> This is not part of JDBC, but allows access to     * functions on the postgresql backend itself.     *     * <p>It is primarily used by the LargeObject API     *     * <p>The best way to use this is as follows:     *     * <p><pre>     * import postgresql.fastpath.*;     * ...     * Fastpath fp = ((postgresql.Connection)myconn).getFastpathAPI();     * </pre>     *     * <p>where myconn is an open Connection to postgresql.     *     * @return Fastpath object allowing access to functions on the 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.     *     * <p><b>NOTE:</b> This is not part of JDBC, but allows access to     * functions on the postgresql backend itself.     *     * <p>The best way to use this is as follows:     *     * <p><pre>     * import postgresql.largeobject.*;     * ...     * LargeObjectManager lo = ((postgresql.Connection)myconn).getLargeObjectAPI();     * </pre>     *     * <p>where myconn is an open Connection to 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     * postgresql's more unique data types.     *     * <p>It uses an internal Hashtable to get the handling class. If the     * type is not supported, then an instance of 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 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 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 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 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 postgresql's     * more unique data types.     *     * <p><b>NOTE:</b> This is not part of JDBC, but an extension.     *     * <p>The best way to use this is as follows:     *     * <p><pre>     * ...     * ((postgresql.Connection)myconn).addDataType("mytype","my.class.name");     * ...     * </pre>     *     * <p>where myconn is an open Connection to postgresql.     *     * <p>The handling class must extend postgresql.util.PGobject     *     * @see 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",		"postgresql.geometric.PGbox"},	{"circle",	"postgresql.geometric.PGcircle"},	{"line",	"postgresql.geometric.PGline"},	{"lseg",	"postgresql.geometric.PGlseg"},	{"path",	"postgresql.geometric.PGpath"},	{"point",	"postgresql.geometric.PGpoint"},	{"polygon",	"postgresql.geometric.PGpolygon"},	{"money",	"postgresql.util.PGmoney"}    };        // This initialises the objectTypes hashtable    private void initObjectTypes()    {	for(int i=0;i<defaultObjectTypes.length;i++)	    objectTypes.put(defaultObjectTypes[i][0],defaultObjectTypes[i][1]);    }        // These are required by other common classes    public abstract java.sql.Statement createStatement() throws SQLException;        /**     * This returns a resultset. It must be overridden, so that the correct     * version (from jdbc1 or jdbc2) are returned.     */    protected abstract java.sql.ResultSet getResultSet(postgresql.Connection conn, Field[] fields, Vector tuples, String status, int updateCount) throws SQLException;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -