abstractjdbc1databasemetadata.java

来自「PostgreSQL7.4.6 for Linux」· Java 代码 · 共 2,128 行 · 第 1/5 页

JAVA
2,128
字号
package org.postgresql.jdbc1;import java.sql.*;import java.util.*;import org.postgresql.core.BaseStatement;import org.postgresql.core.Field;import org.postgresql.core.Encoding;import org.postgresql.util.PSQLException;import org.postgresql.util.PSQLState;import org.postgresql.Driver;public abstract class AbstractJdbc1DatabaseMetaData{	private static final String keywords = "abort,acl,add,aggregate,append,archive," +										   "arch_store,backward,binary,boolean,change,cluster," +										   "copy,database,delimiter,delimiters,do,extend," +										   "explain,forward,heavy,index,inherits,isnull," +										   "light,listen,load,merge,nothing,notify," +										   "notnull,oids,purge,rename,replace,retrieve," +										   "returns,rule,recipe,setof,stdin,stdout,store," +										   "vacuum,verbose,version";	protected AbstractJdbc1Connection connection; // The connection association	protected Encoding encoding;	// These define various OID's. Hopefully they will stay constant.	protected static final int iVarcharOid = 1043;	// OID for varchar	protected static final int iBoolOid = 16; // OID for bool	protected static final int iInt2Oid = 21; // OID for int2	protected static final int iInt4Oid = 23; // OID for int4	protected static final int VARHDRSZ = 4;	// length for int4	private int NAMEDATALEN = 0;	// length for name datatype	private int INDEX_MAX_KEYS = 0; // maximum number of keys in an index.	protected int getMaxIndexKeys() throws SQLException {		if (INDEX_MAX_KEYS == 0) {			String from;			if (connection.haveMinimumServerVersion("7.3")) {				from = "pg_catalog.pg_namespace n, pg_catalog.pg_type t1, pg_catalog.pg_type t2 WHERE t1.typnamespace=n.oid AND n.nspname='pg_catalog' AND ";			} else {				from = "pg_type t1, pg_type t2 WHERE ";			}			String sql = "SELECT t1.typlen/t2.typlen FROM "+from+" t1.typelem=t2.oid AND t1.typname='oidvector'";			ResultSet rs = connection.createStatement().executeQuery(sql);			if (!rs.next()) {				throw new PSQLException("postgresql.unexpected", PSQLState.UNEXPECTED_ERROR);			}			INDEX_MAX_KEYS = rs.getInt(1);			rs.close();		}		return INDEX_MAX_KEYS;	}	protected int getMaxNameLength() throws SQLException {		if (NAMEDATALEN == 0) {			String sql;			if (connection.haveMinimumServerVersion("7.3")) {				sql = "SELECT t.typlen FROM pg_catalog.pg_type t, pg_catalog.pg_namespace n WHERE t.typnamespace=n.oid AND t.typname='name' AND n.nspname='pg_catalog'";			} else {				sql = "SELECT typlen FROM pg_type WHERE typname='name'";			}			ResultSet rs = connection.createStatement().executeQuery(sql);			if (!rs.next()) {				throw new PSQLException("postgresql.unexpected", PSQLState.UNEXPECTED_ERROR);			}			NAMEDATALEN = rs.getInt("typlen");			rs.close();		}		return NAMEDATALEN - 1;	}	public AbstractJdbc1DatabaseMetaData(AbstractJdbc1Connection conn)	{		this.connection = conn;		try {			this.encoding = conn.getEncoding();		}		catch (SQLException sqle) {			this.encoding = Encoding.defaultEncoding();		}	}	/*	 * Can all the procedures returned by getProcedures be called	 * by the current user?	 *	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean allProceduresAreCallable() throws SQLException	{		if (Driver.logDebug)			Driver.debug("allProceduresAreCallable");		return true;		// For now...	}	/*	 * Can all the tables returned by getTable be SELECTed by	 * the current user?	 *	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean allTablesAreSelectable() throws SQLException	{		if (Driver.logDebug)			Driver.debug("allTablesAreSelectable");		return true;		// For now...	}	/*	 * What is the URL for this database?	 *	 * @return the url or null if it cannott be generated	 * @exception SQLException if a database access error occurs	 */	public String getURL() throws SQLException	{		String url = connection.getURL();		if (Driver.logDebug)			Driver.debug("getURL " + url);		return url;	}	/*	 * What is our user name as known to the database?	 *	 * @return our database user name	 * @exception SQLException if a database access error occurs	 */	public String getUserName() throws SQLException	{		String userName = connection.getUserName();		if (Driver.logDebug)			Driver.debug("getUserName " + userName);		return userName;	}	/*	 * Is the database in read-only mode?	 *	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean isReadOnly() throws SQLException	{		boolean isReadOnly = connection.isReadOnly();		if (Driver.logDebug)			Driver.debug("isReadOnly " + isReadOnly);		return isReadOnly;	}	/*	 * Are NULL values sorted high?	 *	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean nullsAreSortedHigh() throws SQLException	{		boolean nullSortedHigh = connection.haveMinimumServerVersion("7.2");		if (Driver.logDebug)			Driver.debug("nullsAreSortedHigh " + nullSortedHigh);		return nullSortedHigh;	}	/*	 * Are NULL values sorted low?	 *	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean nullsAreSortedLow() throws SQLException	{		if (Driver.logDebug)			Driver.debug("nullsAreSortedLow false");		return false;	}	/*	 * Are NULL values sorted at the start regardless of sort order?	 *	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean nullsAreSortedAtStart() throws SQLException	{		if (Driver.logDebug)			Driver.debug("nullsAreSortedAtStart false");		return false;	}	/*	 * Are NULL values sorted at the end regardless of sort order?	 *	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean nullsAreSortedAtEnd() throws SQLException	{		boolean nullsAreSortedAtEnd = ! connection.haveMinimumServerVersion("7.2");		if (Driver.logDebug)			Driver.debug("nullsAreSortedAtEnd " + nullsAreSortedAtEnd);		return nullsAreSortedAtEnd;	}	/*	 * What is the name of this database product - we hope that it is	 * PostgreSQL, so we return that explicitly.	 *	 * @return the database product name	 * @exception SQLException if a database access error occurs	 */	public String getDatabaseProductName() throws SQLException	{		if (Driver.logDebug)			Driver.debug("getDatabaseProductName PostgresSQL");		return "PostgreSQL";	}	/*	 * What is the version of this database product.	 *	 * @return the database version	 * @exception SQLException if a database access error occurs	 */	public String getDatabaseProductVersion() throws SQLException	{		String versionNumber = connection.getDBVersionNumber();		if (Driver.logDebug)			Driver.debug("getDatabaseProductVersion " + versionNumber);		return versionNumber;	}	/*	 * What is the name of this JDBC driver?  If we don't know this	 * we are doing something wrong!	 *	 * @return the JDBC driver name	 * @exception SQLException why?	 */	public String getDriverName() throws SQLException	{		String driverName = "PostgreSQL Native Driver";		if (Driver.logDebug)			Driver.debug("getDriverName" + driverName);		return driverName;	}	/*	 * What is the version string of this JDBC driver?	Again, this is	 * static.	 *	 * @return the JDBC driver name.	 * @exception SQLException why?	 */	public String getDriverVersion() throws SQLException	{		String driverVersion = Driver.getVersion();		if (Driver.logDebug)			Driver.debug("getDriverVersion " + driverVersion);		return driverVersion;	}	/*	 * What is this JDBC driver's major version number?	 *	 * @return the JDBC driver major version	 */	public int getDriverMajorVersion()	{		int majorVersion = connection.this_driver.getMajorVersion();		if (Driver.logDebug)			Driver.debug("getMajorVersion " + majorVersion);		return majorVersion;	}	/*	 * What is this JDBC driver's minor version number?	 *	 * @return the JDBC driver minor version	 */	public int getDriverMinorVersion()	{		int minorVersion = connection.this_driver.getMinorVersion();		if (Driver.logDebug)			Driver.debug("getMinorVersion " + minorVersion);		return minorVersion;	}	/*	 * Does the database store tables in a local file?	No - it	 * stores them in a file on the server.	 *	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean usesLocalFiles() throws SQLException	{		if (Driver.logDebug)			Driver.debug("usesLocalFiles " + false);		return false;	}	/*	 * Does the database use a file for each table?  Well, not really,	 * since it doesnt use local files.	 *	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean usesLocalFilePerTable() throws SQLException	{		if (Driver.logDebug)			Driver.debug("usesLocalFilePerTable " + false);		return false;	}	/*	 * Does the database treat mixed case unquoted SQL identifiers	 * as case sensitive and as a result store them in mixed case?	 * A JDBC-Compliant driver will always return false.	 *	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean supportsMixedCaseIdentifiers() throws SQLException	{		if (Driver.logDebug)			Driver.debug("supportsMixedCaseIdentifiers " + false);		return false;	}	/*	 * Does the database treat mixed case unquoted SQL identifiers as	 * case insensitive and store them in upper case?	 *	 * @return true if so	 */	public boolean storesUpperCaseIdentifiers() throws SQLException	{		if (Driver.logDebug)			Driver.debug("storesUpperCaseIdentifiers " + false);		return false;	}	/*	 * Does the database treat mixed case unquoted SQL identifiers as	 * case insensitive and store them in lower case?	 *	 * @return true if so	 */	public boolean storesLowerCaseIdentifiers() throws SQLException	{		if (Driver.logDebug)			Driver.debug("storesLowerCaseIdentifiers " + true);		return true;	}	/*	 * Does the database treat mixed case unquoted SQL identifiers as	 * case insensitive and store them in mixed case?	 *	 * @return true if so	 */	public boolean storesMixedCaseIdentifiers() throws SQLException	{		if (Driver.logDebug)			Driver.debug("storesMixedCaseIdentifiers " + false);		return false;	}	/*	 * Does the database treat mixed case quoted SQL identifiers as	 * case sensitive and as a result store them in mixed case?  A	 * JDBC compliant driver will always return true.	 *	 * @return true if so	 * @exception SQLException if a database access error occurs	 */	public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException	{		if (Driver.logDebug)			Driver.debug("supportsMixedCaseQuotedIdentifiers " + true);		return true;	}	/*	 * Does the database treat mixed case quoted SQL identifiers as	 * case insensitive and store them in upper case?	 *	 * @return true if so	 */	public boolean storesUpperCaseQuotedIdentifiers() throws SQLException	{		if (Driver.logDebug)			Driver.debug("storesUpperCaseQuotedIdentifiers " + false);		return false;	}	/*	 * Does the database treat mixed case quoted SQL identifiers as case	 * insensitive and store them in lower case?	 *	 * @return true if so	 */	public boolean storesLowerCaseQuotedIdentifiers() throws SQLException	{		if (Driver.logDebug)			Driver.debug("storesLowerCaseQuotedIdentifiers " + false);		return false;	}	/*	 * Does the database treat mixed case quoted SQL identifiers as case	 * insensitive and store them in mixed case?	 *	 * @return true if so	 */	public boolean storesMixedCaseQuotedIdentifiers() throws SQLException	{		if (Driver.logDebug)

⌨️ 快捷键说明

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