📄 metadata.java
字号:
* @param columnIndex the first column is 1, the second is 2, ... * @param columnName the designated column's name * @exception SQLException if a database access error occurs * */ public void setColumnName(int columnIndex, String columnName) throws SQLException { this.columnName[columnIndex - 1] = columnName; } /** Sets the designated column's SQL type to the one given. * * @param columnIndex the first column is 1, the second is 2, ... * @param SQLType the column's SQL type * @exception SQLException if a database access error occurs * @see java.sql.Types * */ public void setColumnType(int columnIndex, int SQLType) throws SQLException { this.columnType[columnIndex - 1] = SQLType; } /** Sets the designated column's type name that is specific to the * data source, if any, to the given <code>String</code>. * * @param columnIndex the first column is 1, the second is 2, ... * @param typeName data source specific type name. * @exception SQLException if a database access error occurs * */ public void setColumnTypeName(int columnIndex, String typeName) throws SQLException { this.columnTypeName[columnIndex - 1] = typeName; } /** Sets whether the designated column is a cash value. * The default is <code>false</code>. * * @param columnIndex the first column is 1, the second is 2, ... * @param property <code>true</code> if the column is a cash value; * <code>false</code> if it is not * * @exception SQLException if a database access error occurs * */ public void setCurrency(int columnIndex, boolean property) throws SQLException { this.currency[columnIndex - 1] = property; } /** Sets whether the designated column's value can be set to * <code>NULL</code>. * The default is <code>ResultSetMetaData.columnNullableUnknown</code> * * @param columnIndex the first column is 1, the second is 2, ... * @param property one of the following constants: * <code>ResultSetMetaData.columnNoNulls</code>, * <code>ResultSetMetaData.columnNullable</code>, or * <code>ResultSetMetaData.columnNullableUnknown</code> * * @exception SQLException if a database access error occurs * */ public void setNullable(int columnIndex, int property) throws SQLException { this.nullable[columnIndex - 1] = property; } /** Sets the designated column's number of decimal digits to the * given <code>int</code>. * * @param columnIndex the first column is 1, the second is 2, ... * @param precision the total number of decimal digits * @exception SQLException if a database access error occurs * */ public void setPrecision(int columnIndex, int precision) throws SQLException { this.precision[columnIndex - 1] = precision; } /** Sets the designated column's number of digits to the * right of the decimal point to the given <code>int</code>. * * @param columnIndex the first column is 1, the second is 2, ... * @param scale the number of digits to right of decimal point * @exception SQLException if a database access error occurs * */ public void setScale(int columnIndex, int scale) throws SQLException { this.scale[columnIndex - 1] = scale; } /** Sets the name of the designated column's table's schema, if any, to * the given <code>String</code>. * * @param columnIndex the first column is 1, the second is 2, ... * @param schemaName the schema name * @exception SQLException if a database access error occurs * */ public void setSchemaName(int columnIndex, String schemaName) throws SQLException { this.schemaName[columnIndex - 1] = schemaName; } /** Sets whether the designated column can be used in a where clause. * The default is <code>false</code>. * * @param columnIndex the first column is 1, the second is 2, ... * @param property <code>true</code> if the column can be used in a * <code>WHERE</code> clause; <code>false</code> if it cannot * * @exception SQLException if a database access error occurs * */ public void setSearchable(int columnIndex, boolean property) throws SQLException { this.searchable[columnIndex - 1] = property; } /** Sets whether the designated column is a signed number. * The default is <code>false</code>. * * @param columnIndex the first column is 1, the second is 2, ... * @param property <code>true</code> if the column is a signed number; * <code>false</code> if it is not * * @exception SQLException if a database access error occurs * */ public void setSigned(int columnIndex, boolean property) throws SQLException { this.signed[columnIndex - 1] = property; } /** Sets the designated column's table name, if any, to the given * <code>String</code>. * * @param columnIndex the first column is 1, the second is 2, ... * @param tableName the column's table name * @exception SQLException if a database access error occurs * */ public void setTableName(int columnIndex, String tableName) throws SQLException { this.tableName[columnIndex - 1] = tableName; } /** Setter for property writable. * @param writable New value of property writable. * */ public void setWritable(int columnIndex, boolean writable) { this.writable[columnIndex - 1] = writable; } /** Setter for property definitelyWritable. * @param definitelyWritable New value of property definitelyWritable. * */ public void setDefinitelyWritable(int columnIndex, boolean definitelyWritable) { this.definitelyWritable[columnIndex - 1] = definitelyWritable; } /** Setter for property columnClassName. * @param columnClassName New value of property columnClassName. * */ public void setColumnClassName(int columnIndex, java.lang.String columnClassName) { this.columnClassName[columnIndex - 1] = columnClassName; } /** Setter for property . * * @param readOnly New value of property readOnly. * */ public void setReadOnly(int columnIndex, boolean readOnly) throws SQLException { this.readOnly[columnIndex - 1] = readOnly; } /** Getter for property tables. * @return Value of property tables. * */ public java.util.Map getTables() { return tables; } /** Setter for property tables. * @param tables New value of property tables. * */ public void setTables(java.util.Map tables) { this.tables = tables; } public String getFullColumnName(int columnIndex) throws SQLException { return this.fullColumnName[columnIndex - 1]; } public void setFullColumnName(int columnIndex, String columnName) throws SQLException { this.fullColumnName[columnIndex - 1] = columnName; } public String getFieldName(int columnIndex) throws SQLException { return this.fieldName[columnIndex - 1]; } public void setFieldName(int columnIndex, String fieldName) throws SQLException { this.fieldName[columnIndex - 1] = fieldName; } public Method getWriteMethod(int columnIndex) throws SQLException { if (this.writeMethod[columnIndex - 1] == null){ populateWriteMethod(columnIndex, fieldName[columnIndex - 1]); } return this.writeMethod[columnIndex - 1]; } public void setWriteMethod(int columnIndex, Method writeMethod) { this.writeMethod[columnIndex - 1] = writeMethod; } public Method getReadMethod(int columnIndex) throws SQLException { if (this.readMethod[columnIndex - 1] == null){ populateReadMethod(columnIndex, fieldName[columnIndex - 1]); } return this.readMethod[columnIndex - 1]; } public void setReadMethod(int columnIndex, Method readMethod) { this.readMethod[columnIndex - 1] = readMethod; } public String getFieldClassName(int columnIndex) throws SQLException { return this.fieldClassName[columnIndex - 1]; } public void setFieldClassName(int columnIndex, String fieldClassName) throws SQLException { this.fieldClassName[columnIndex - 1] = fieldClassName; } public java.lang.Class getFieldClass(int columnIndex) { return this.fieldClass[columnIndex - 1]; } public void setFieldClass(int columnIndex, Class fieldClass) { this.fieldClass[columnIndex - 1] = fieldClass; } protected void populateReadMethod(int columnIndex, String fieldName) throws java.sql.SQLException{ try{ Method mRead = (new PropertyDescriptor(fieldName, this.requestor)).getReadMethod(); this.setReadMethod(columnIndex, mRead); }catch (IntrospectionException e){ e.printStackTrace(); throw new RuntimeException(e); } } protected void populateWriteMethod(int columnIndex, String fieldName) throws java.sql.SQLException{ try{ Method mWrite = (new PropertyDescriptor(fieldName, this.requestor)).getWriteMethod(); this.setWriteMethod(columnIndex, mWrite); Class[] paramTypes = mWrite.getParameterTypes(); Class paramClass = paramTypes[0]; this.setFieldClass(columnIndex, paramClass); this.setFieldClassName(columnIndex, paramClass.getName()); }catch (IntrospectionException e){ e.printStackTrace(); throw new RuntimeException(e); } } public void populate(Map mapping, Class requestor) throws java.sql.SQLException{ this.requestor = requestor; int columnCount = mapping.size(); this.setColumnCount(columnCount); this.catalogName = new String[columnCount]; this.schemaName = new String[columnCount]; this.tableName = new String[columnCount]; this.columnName = new String[columnCount]; this.columnLabel = new String[columnCount]; this.readOnly = new boolean[columnCount]; this.writable = new boolean[columnCount]; this.columnType = new int[columnCount]; this.fullColumnName = new String[columnCount]; this.fieldName = new String[columnCount]; this.readMethod = new Method[columnCount]; this.writeMethod = new Method[columnCount]; this.fieldClass = new Class[columnCount]; this.fieldClassName = new String[columnCount]; Iterator iter = mapping.keySet().iterator(); int columnIndex = 1; while(iter.hasNext()){ String catalog = null; String schema = null; String table = null; String tableId = null; String column = null; String fullColName = (String) iter.next(); StringTokenizer st = new StringTokenizer(fullColName, ".", false); int tokens = st.countTokens(); if (tokens == 2){ // only table and column names, no schema and no catalog int idx1 = fullColName.indexOf("."); tableId = fullColName.substring(0, idx1); table = tableId; }else if (tokens == 3){ // no catalog is supplied int idx1 = fullColName.indexOf("."); int idx2 = fullColName.lastIndexOf("."); tableId = fullColName.substring(0, idx2); table = fullColName.substring(idx1 + 1, idx2); schema = fullColName.substring(0, idx1); }else if (tokens == 4){ // catalog, schema table and column tableId = fullColName.substring(0, fullColName.lastIndexOf(".")); int i = 0; while (st.hasMoreTokens() && i < 3){ String token = st.nextToken(); if (i == 0){ catalog = token; }else if (i == 1){ schema = token; }else if (i == 2){ table = token; } i++; } }else{ throw new IllegalArgumentException("Invalid DB Mappings"); } this.setCatalogName(columnIndex, catalog); this.setSchemaName(columnIndex, schema); this.setTableName(columnIndex, table); this.setColumnName(columnIndex, fullColName.substring(fullColName.lastIndexOf(".") + 1)); this.setFullColumnName(columnIndex, fullColName); String fieldName = (String) mapping.get(fullColName); this.setFieldName(columnIndex, fieldName); String[] distinctTables = new String[3]; distinctTables[0] = catalog; distinctTables[1] = schema; distinctTables[2] = table; this.tables.put(tableId, distinctTables); this.setReadOnly(columnIndex, false); this.setWritable(columnIndex, true); this.populateReadMethod(columnIndex, fieldName); this.populateWriteMethod(columnIndex, fieldName); this.setColumnLabel(columnIndex, toLabel(getColumnName(columnIndex))); columnIndex++; } } public int getColumnIndexByFieldName(String searchedFieldName){ for (int i = 0;i < this.fieldName.length;i++){ if (searchedFieldName.equalsIgnoreCase(fieldName[i])){ return i + 1; } } return -1; } protected String toLabel(String columnName){ String label = ((String) columnName).toLowerCase(); StringBuffer sb = new StringBuffer(); boolean toUpper = false; for (int i = 0;i < label.length();i++){ char c = label.charAt(i); if (c != '_'){ if (i == 0){ toUpper = true; } if (toUpper){ c = Character.toUpperCase(c); }else{ } sb.append(c); toUpper = false; }else{ if (i > 0){ sb.append(' '); } toUpper = true; } } return sb.toString(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -