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

📄 databasemetadata.java

📁 mysql5.0 JDBC 驱动 放在glassfish或者tomcat的lib文件夹下就可以了
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				rowData[1] = null;				rowData[2] = s2b(procedureName);				rowData[3] = null;				rowData[4] = null;				rowData[5] = null;				rowData[6] = null;				boolean isFunction = fromSelect ? "FUNCTION"						.equalsIgnoreCase(proceduresRs.getString("type"))						: false;				rowData[7] = s2b(isFunction ? Integer						.toString(procedureReturnsResult) : Integer						.toString(procedureResultUnknown));				rowData[8] = s2b(procedureName);								procedureRowsOrderedByName.put(procedureName, new ByteArrayRow(rowData));			}		}	}	private ResultSetRow convertTypeDescriptorToProcedureRow(			byte[] procNameAsBytes, String paramName, boolean isOutParam,			boolean isInParam, boolean isReturnParam, TypeDescriptor typeDesc,			boolean forGetFunctionColumns,			int ordinal)			throws SQLException {		byte[][] row = forGetFunctionColumns ? new byte[17][] : new byte[14][];		row[0] = null; // PROCEDURE_CAT		row[1] = null; // PROCEDURE_SCHEM		row[2] = procNameAsBytes; // PROCEDURE/NAME		row[3] = s2b(paramName); // COLUMN_NAME		// COLUMN_TYPE				// NOTE: For JDBC-4.0, we luck out here for functions		// because the values are the same for functionColumn....		// and they're not using Enumerations....				if (isInParam && isOutParam) {			row[4] = s2b(String.valueOf(procedureColumnInOut));		} else if (isInParam) {			row[4] = s2b(String.valueOf(procedureColumnIn));		} else if (isOutParam) {			row[4] = s2b(String.valueOf(procedureColumnOut));		} else if (isReturnParam) {			row[4] = s2b(String.valueOf(procedureColumnReturn));		} else {			row[4] = s2b(String.valueOf(procedureColumnUnknown));		}		row[5] = s2b(Short.toString(typeDesc.dataType)); // DATA_TYPE		row[6] = s2b(typeDesc.typeName); // TYPE_NAME		row[7] = typeDesc.columnSize == null ? null : s2b(typeDesc.columnSize.toString()); // PRECISION		row[8] = s2b(Integer.toString(typeDesc.bufferLength)); // LENGTH		row[9] = typeDesc.decimalDigits == null ? null : s2b(typeDesc.decimalDigits.toString()); // SCALE		row[10] = s2b(Integer.toString(typeDesc.numPrecRadix)); // RADIX		// Map 'column****' to 'procedure****'		switch (typeDesc.nullability) {		case columnNoNulls:			row[11] = s2b(String.valueOf(procedureNoNulls)); // NULLABLE			break;		case columnNullable:			row[11] = s2b(String.valueOf(procedureNullable)); // NULLABLE			break;		case columnNullableUnknown:			row[11] = s2b(String.valueOf(procedureNullableUnknown)); // nullable			break;		default:			throw SQLError.createSQLException(					"Internal error while parsing callable statement metadata (unknown nullability value fount)",					SQLError.SQL_STATE_GENERAL_ERROR);		}				row[12] = null;				if (forGetFunctionColumns) {			// CHAR_OCTECT_LENGTH			row[13] = null;						// ORDINAL_POSITION			row[14] = s2b(String.valueOf(ordinal));						// IS_NULLABLE			row[15] = Constants.EMPTY_BYTE_ARRAY;						row[16] = s2b(paramName);		}				return new ByteArrayRow(row);	}	/**	 * Does a data definition statement within a transaction force the	 * transaction to commit?	 * 	 * @return true if so	 * @throws SQLException	 *             DOCUMENT ME!	 */	public boolean dataDefinitionCausesTransactionCommit() throws SQLException {		return true;	}	/**	 * Is a data definition statement within a transaction ignored?	 * 	 * @return true if so	 * @throws SQLException	 *             DOCUMENT ME!	 */	public boolean dataDefinitionIgnoredInTransactions() throws SQLException {		return false;	}	/**	 * JDBC 2.0 Determine whether or not a visible row delete can be detected by	 * calling ResultSet.rowDeleted(). If deletesAreDetected() returns false,	 * then deleted rows are removed from the result set.	 * 	 * @param type	 *            set type, i.e. ResultSet.TYPE_XXX	 * @return true if changes are detected by the resultset type	 * @exception SQLException	 *                if a database-access error occurs.	 */	public boolean deletesAreDetected(int type) throws SQLException {		return false;	}	// ----------------------------------------------------------------------	/**	 * Did getMaxRowSize() include LONGVARCHAR and LONGVARBINARY blobs?	 * 	 * @return true if so	 * @throws SQLException	 *             DOCUMENT ME!	 */	public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {		return true;	}	/**	 * Extracts foreign key info for one table.	 * 	 * @param rows	 *            the list of rows to add to	 * @param rs	 *            the result set from 'SHOW CREATE TABLE'	 * @param catalog	 *            the database name	 * @return the list of rows with new rows added	 * @throws SQLException	 *             if a database access error occurs	 */	public List extractForeignKeyForTable(ArrayList rows,			java.sql.ResultSet rs, String catalog) throws SQLException {		byte[][] row = new byte[3][];		row[0] = rs.getBytes(1);		row[1] = s2b(SUPPORTS_FK);			String createTableString = rs.getString(2);		StringTokenizer lineTokenizer = new StringTokenizer(createTableString,				"\n");		StringBuffer commentBuf = new StringBuffer("comment; ");		boolean firstTime = true;			String quoteChar = getIdentifierQuoteString();			if (quoteChar == null) {			quoteChar = "`";		}			while (lineTokenizer.hasMoreTokens()) {			String line = lineTokenizer.nextToken().trim();				String constraintName = null;				if (StringUtils.startsWithIgnoreCase(line, "CONSTRAINT")) {				boolean usingBackTicks = true;				int beginPos = line.indexOf(quoteChar);					if (beginPos == -1) {					beginPos = line.indexOf("\"");					usingBackTicks = false;				}					if (beginPos != -1) {					int endPos = -1;						if (usingBackTicks) {						endPos = line.indexOf(quoteChar, beginPos + 1);					} else {						endPos = line.indexOf("\"", beginPos + 1);					}						if (endPos != -1) {						constraintName = line.substring(beginPos + 1, endPos);						line = line.substring(endPos + 1, line.length()).trim();					}				}			}							if (line.startsWith("FOREIGN KEY")) {				if (line.endsWith(",")) {					line = line.substring(0, line.length() - 1);				}					char quote = this.quotedId.charAt(0);								int indexOfFK = line.indexOf("FOREIGN KEY");								String localColumnName = null;				String referencedCatalogName = this.quotedId + catalog + this.quotedId;				String referencedTableName = null;				String referencedColumnName = null;												if (indexOfFK != -1) {					int afterFk = indexOfFK + "FOREIGN KEY".length();										int indexOfRef = StringUtils.indexOfIgnoreCaseRespectQuotes(afterFk, line, "REFERENCES", quote, true);										if (indexOfRef != -1) {												int indexOfParenOpen = line.indexOf('(', afterFk);						int indexOfParenClose = StringUtils.indexOfIgnoreCaseRespectQuotes(indexOfParenOpen, line, ")", quote, true);												if (indexOfParenOpen == -1 || indexOfParenClose == -1) {							// throw SQLError.createSQLException();						}												localColumnName = line.substring(indexOfParenOpen + 1, indexOfParenClose);												int afterRef = indexOfRef + "REFERENCES".length();												int referencedColumnBegin = StringUtils.indexOfIgnoreCaseRespectQuotes(afterRef, line, "(", quote, true);												if (referencedColumnBegin != -1) {							referencedTableName = line.substring(afterRef, referencedColumnBegin);								int referencedColumnEnd = StringUtils.indexOfIgnoreCaseRespectQuotes(referencedColumnBegin + 1, line, ")", quote, true);														if (referencedColumnEnd != -1) {								referencedColumnName = line.substring(referencedColumnBegin + 1, referencedColumnEnd);							}														int indexOfCatalogSep = StringUtils.indexOfIgnoreCaseRespectQuotes(0, referencedTableName, ".", quote, true);														if (indexOfCatalogSep != -1) {								referencedCatalogName = referencedTableName.substring(0, indexOfCatalogSep);								referencedTableName = referencedTableName.substring(indexOfCatalogSep + 1);							}						}					}				}												if (!firstTime) {					commentBuf.append("; ");				} else {					firstTime = false;				}					if (constraintName != null) {					commentBuf.append(constraintName);				} else {					commentBuf.append("not_available");				}					commentBuf.append("(");				commentBuf.append(localColumnName);				commentBuf.append(") REFER ");				commentBuf.append(referencedCatalogName);				commentBuf.append("/");				commentBuf.append(referencedTableName);				commentBuf.append("(");				commentBuf.append(referencedColumnName);				commentBuf.append(")");					int lastParenIndex = line.lastIndexOf(")");					if (lastParenIndex != (line.length() - 1)) {					String cascadeOptions = line							.substring(lastParenIndex + 1);					commentBuf.append(" ");					commentBuf.append(cascadeOptions);				}			}		}			row[2] = s2b(commentBuf.toString());		rows.add(new ByteArrayRow(row));			return rows;	}	/**	 * Creates a result set similar enough to 'SHOW TABLE STATUS' to allow the	 * same code to work on extracting the foreign key data	 * 	 * @param connToUse	 *            the database connection to use	 * @param metadata	 *            the DatabaseMetaData instance calling this method	 * @param catalog	 *            the database name to extract foreign key info for	 * @param tableName	 *            the table to extract foreign key info for	 * @return A result set that has the structure of 'show table status'	 * @throws SQLException	 *             if a database access error occurs.	 */	public ResultSet extractForeignKeyFromCreateTable(String catalog,			String tableName) throws SQLException {		ArrayList tableList = new ArrayList();		java.sql.ResultSet rs = null;		java.sql.Statement stmt = null;		if (tableName != null) {			tableList.add(tableName);		} else {			try {				rs = getTables(catalog, "", "%", new String[] { "TABLE" });				while (rs.next()) {					tableList.add(rs.getString("TABLE_NAME"));				}			} finally {				if (rs != null) {					rs.close();				}				rs = null;			}		}		ArrayList rows = new ArrayList();		Field[] fields = new Field[3];		fields[0] = new Field("", "Name", Types.CHAR, Integer.MAX_VALUE);		fields[1] = new Field("", "Type", Types.CHAR, 255);		fields[2] = new Field("", "Comment", Types.CHAR, Integer.MAX_VALUE);		int numTables = tableList.size();		stmt = this.conn.getMetadataSafeStatement();		String quoteChar = getIdentifierQuoteString();		if (quoteChar == null) {			quoteChar = "`";		}		try {			for (int i = 0; i < numTables; i++) {				String tableToExtract = (String) tableList.get(i);				String query = new StringBuffer("SHOW CREATE TABLE ").append(						quoteChar).append(catalog).append(quoteChar)						.append(".").append(quoteChar).append(tableToExtract)						.append(quoteChar).toString();								try {					rs = stmt.executeQuery(query);				} catch (SQLException sqlEx) {					// Table might've disappeared on us, not really an error					String sqlState = sqlEx.getSQLState();										if (!"42S02".equals(sqlState) && 							sqlEx.getErrorCode() != MysqlErrorNumbers.ER_NO_SUCH_TABLE) {						throw sqlEx;					}										continue;				}				while (rs.next()) {					extractForeignKeyForTable(rows, rs, catalog);				}			}		} finally {			if (rs != null) {				rs.close();			}			rs = null;			if (stmt != null) {				stmt.close();			}			stmt = null;		}		return buildResultSet(fields, rows);	}	/**	 * @see DatabaseMetaData#getAttributes(String, String, String, String)

⌨️ 快捷键说明

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