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

📄 databasemetadata.java

📁 在资料浩瀚的互联网中
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * <li>     * <B>FK_NAME</B> String => foreign key identifier (may be null)     * </li>     * <li>     * <B>PK_NAME</B> String => primary key identifier (may be null)     * </li>     * </ol>     * </p>     *     * @param catalog a catalog name; "" retrieves those without a catalog     * @param schema a schema name pattern; "" retrieves those without a schema     * @param table a table name     *     * @return ResultSet each row is a foreign key column description     *     * @throws SQLException if a database access error occurs     *     * @see #getImportedKeys     */    public java.sql.ResultSet getExportedKeys(String catalog, String schema,        String table) throws SQLException {        if (table == null) {            throw new SQLException("Table not specified.",                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);        }        Field[] fields = new Field[14];        fields[0] = new Field("", "PKTABLE_CAT", Types.CHAR, 255);        fields[1] = new Field("", "PKTABLE_SCHEM", Types.CHAR, 0);        fields[2] = new Field("", "PKTABLE_NAME", Types.CHAR, 255);        fields[3] = new Field("", "PKCOLUMN_NAME", Types.CHAR, 32);        fields[4] = new Field("", "FKTABLE_CAT", Types.CHAR, 255);        fields[5] = new Field("", "FKTABLE_SCHEM", Types.CHAR, 0);        fields[6] = new Field("", "FKTABLE_NAME", Types.CHAR, 255);        fields[7] = new Field("", "FKCOLUMN_NAME", Types.CHAR, 32);        fields[8] = new Field("", "KEY_SEQ", Types.SMALLINT, 2);        fields[9] = new Field("", "UPDATE_RULE", Types.SMALLINT, 2);        fields[10] = new Field("", "DELETE_RULE", Types.SMALLINT, 2);        fields[11] = new Field("", "FK_NAME", Types.CHAR, 255);        fields[12] = new Field("", "PK_NAME", Types.CHAR, 0);        fields[13] = new Field("", "DEFERRABILITY", Types.INTEGER, 2);        if (this.conn.versionMeetsMinimum(3, 23, 0)) {            Statement stmt = null;            ResultSet fkresults = null;            try {                stmt = this.conn.createStatement();                stmt.setEscapeProcessing(false);                /*                 * Get foreign key information for table                 */                if (this.conn.versionMeetsMinimum(3, 23, 50)) {                    // we can use 'SHOW CREATE TABLE'                    String db = this.database;                    if (catalog != null) {                        if (!catalog.equals("")) {                            db = catalog;                        }                    }                    fkresults = extractForeignKeyFromCreateTable(this.conn,                            this, db, null);                } else {                    String databasePart = "";                    if (catalog != null) {                        if (!catalog.equals("")) {                            databasePart = " FROM " + catalog;                        }                    } else {                        databasePart = " FROM " + this.database;                    }                    fkresults = stmt.executeQuery("show table status " +                            databasePart);                }                // lower-case table name might be turned on                String tableNameWithCase = getTableNameWithCase(table);                /*                * Parse imported foreign key information                */                ArrayList tuples = new ArrayList();                while (fkresults.next()) {                    String tableType = fkresults.getString("Type");                    if ((tableType != null) &&                            (tableType.equalsIgnoreCase("innodb") ||                            tableType.equalsIgnoreCase(SUPPORTS_FK))) {                        String comment = fkresults.getString("Comment").trim();                        if (comment != null) {                            StringTokenizer commentTokens = new StringTokenizer(comment,                                    ";", false);                            if (commentTokens.hasMoreTokens()) {                                commentTokens.nextToken(); // Skip InnoDB comment                                while (commentTokens.hasMoreTokens()) {                                    String keys = commentTokens.nextToken();                                    getExportKeyResults(catalog,                                        tableNameWithCase, keys, tuples,                                        fkresults.getString("Name"));                                }                            }                        }                    }                }                return buildResultSet(fields, tuples);            } finally {                if (fkresults != null) {                    try {                        fkresults.close();                    } catch (SQLException sqlEx) {                        AssertionFailedException.shouldNotHappen(sqlEx);                    }                    fkresults = null;                }                if (stmt != null) {                    try {                        stmt.close();                    } catch (Exception ex) {                        AssertionFailedException.shouldNotHappen(ex);                    }                    stmt = null;                }            }        }        return buildResultSet(fields, new ArrayList());    }    /**     * Get all the "extra" characters that can be used in unquoted identifier     * names (those beyond a-z, 0-9 and _).     *     * @return the string containing the extra characters     *     * @throws SQLException DOCUMENT ME!     */    public String getExtraNameCharacters() throws SQLException {        return "#@";    }    /**     * What's the string used to quote SQL identifiers? This returns a space "     * " if identifier quoting isn't supported. A JDBC compliant driver always     * uses a double quote character.     *     * @return the quoting string     *     * @throws SQLException DOCUMENT ME!     */    public String getIdentifierQuoteString() throws SQLException {        if (this.conn.supportsQuotedIdentifiers()) {            if (!this.conn.useAnsiQuotedIdentifiers()) {                return "`";            }            return "\"";        }        return " ";    }    /**     * Get a description of the primary key columns that are referenced by a     * table's foreign key columns (the primary keys imported by a table).     * They are ordered by PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, and     * KEY_SEQ.     *     * <P>     * Each primary key column description has the following columns:     *     * <OL>     * <li>     * <B>PKTABLE_CAT</B> String => primary key table catalog being imported     * (may be null)     * </li>     * <li>     * <B>PKTABLE_SCHEM</B> String => primary key table schema being imported     * (may be null)     * </li>     * <li>     * <B>PKTABLE_NAME</B> String => primary key table name being imported     * </li>     * <li>     * <B>PKCOLUMN_NAME</B> String => primary key column name being imported     * </li>     * <li>     * <B>FKTABLE_CAT</B> String => foreign key table catalog (may be null)     * </li>     * <li>     * <B>FKTABLE_SCHEM</B> String => foreign key table schema (may be null)     * </li>     * <li>     * <B>FKTABLE_NAME</B> String => foreign key table name     * </li>     * <li>     * <B>FKCOLUMN_NAME</B> String => foreign key column name     * </li>     * <li>     * <B>KEY_SEQ</B> short => sequence number within foreign key     * </li>     * <li>     * <B>UPDATE_RULE</B> short => What happens to foreign key when primary is     * updated:     *     * <UL>     * <li>     * importedKeyCascade - change imported key to agree with primary key     * update     * </li>     * <li>     * importedKeyRestrict - do not allow update of primary key if it has been     * imported     * </li>     * <li>     * importedKeySetNull - change imported key to NULL if its primary key has     * been updated     * </li>     * </ul>     *     * </li>     * <li>     * <B>DELETE_RULE</B> short => What happens to the foreign key when primary     * is deleted.     *     * <UL>     * <li>     * importedKeyCascade - delete rows that import a deleted key     * </li>     * <li>     * importedKeyRestrict - do not allow delete of primary key if it has been     * imported     * </li>     * <li>     * importedKeySetNull - change imported key to NULL if its primary key has     * been deleted     * </li>     * </ul>     *     * </li>     * <li>     * <B>FK_NAME</B> String => foreign key name (may be null)     * </li>     * <li>     * <B>PK_NAME</B> String => primary key name (may be null)     * </li>     * </ol>     * </p>     *     * @param catalog a catalog name; "" retrieves those without a catalog     * @param schema a schema name pattern; "" retrieves those without a schema     * @param table a table name     *     * @return ResultSet each row is a primary key column description     *     * @throws SQLException if a database access error occurs     *     * @see #getExportedKeys     */    public java.sql.ResultSet getImportedKeys(String catalog, String schema,        String table) throws SQLException {        if (table == null) {            throw new SQLException("Table not specified.",                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);        }        Field[] fields = new Field[14];        fields[0] = new Field("", "PKTABLE_CAT", Types.CHAR, 255);        fields[1] = new Field("", "PKTABLE_SCHEM", Types.CHAR, 0);        fields[2] = new Field("", "PKTABLE_NAME", Types.CHAR, 255);        fields[3] = new Field("", "PKCOLUMN_NAME", Types.CHAR, 32);        fields[4] = new Field("", "FKTABLE_CAT", Types.CHAR, 255);        fields[5] = new Field("", "FKTABLE_SCHEM", Types.CHAR, 0);        fields[6] = new Field("", "FKTABLE_NAME", Types.CHAR, 255);        fields[7] = new Field("", "FKCOLUMN_NAME", Types.CHAR, 32);        fields[8] = new Field("", "KEY_SEQ", Types.SMALLINT, 2);        fields[9] = new Field("", "UPDATE_RULE", Types.SMALLINT, 2);        fields[10] = new Field("", "DELETE_RULE", Types.SMALLINT, 2);        fields[11] = new Field("", "FK_NAME", Types.CHAR, 255);        fields[12] = new Field("", "PK_NAME", Types.CHAR, 0);        fields[13] = new Field("", "DEFERRABILITY", Types.INTEGER, 2);        if (this.conn.versionMeetsMinimum(3, 23, 0)) {            Statement stmt = null;            ResultSet fkresults = null;            try {                stmt = this.conn.createStatement();                stmt.setEscapeProcessing(false);                /*                 * Get foreign key information for table                 */                if (this.conn.versionMeetsMinimum(3, 23, 50)) {                    // we can use 'SHOW CREATE TABLE'                    String db = this.database;                    if (catalog != null) {                        if (!catalog.equals("")) {                            db = catalog;                        }                    }                    fkresults = extractForeignKeyFromCreateTable(this.conn,                            this, db, table);                } else {                    String databasePart = "";                    if (catalog != null) {                        if (!catalog.equals("")) {                            databasePart = " FROM " + catalog;                        }                    } else {                        databasePart = " FROM " + this.database;                    }                    fkresults = stmt.executeQuery("show table status " +                            databasePart + " like '" + table + "'");                }                /*                * Parse imported foreign key information                */                ArrayList tuples = new ArrayList();                while (fkresults.next()) {                    String tableType = fkresults.getString("Type");                    if ((tableType != null) &&                            (tableType.equalsIgnoreCase("innodb") ||                            tableType.equalsIgnoreCase(SUPPORTS_FK))) {                        String comment = fkresults.getString("Comment").trim();                        if (comment != null) {                            StringTokenizer commentTokens = new StringTokenizer(comment,                                    ";", false);                            if (commentTokens.hasMoreTokens()) {                                commentTokens.nextToken(); // Skip InnoDB comment                                while (commentTokens.hasMoreTokens()) {                                    String keys = commentTokens.nextToken();                                    getImportKeyResults(catalog, table, keys,                                        tuples);                                }                            }                        }                    }                }                r

⌨️ 快捷键说明

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