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

📄 webrowsetdataprovider.java

📁 ADO.NET在Java中的使用 ADO.NET最大的特性在于对断开数据库连接方式的全方位支持
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                 * @param value
                 * @throws Exception
                 */
                private void setValue(int columnIndex, String value) throws Exception {
                    //TODO Take into account the possiblity of a collision, and notify listeners if necessary
                    if (wasNull || value == null) {
                        rowValues[columnIndex - 1] = null;
                    } else {
                        switch (metaData.getColumnType(columnIndex)) {
                            case Types.TINYINT:
                                rowValues[columnIndex - 1] = Byte.valueOf(value.trim());
                                break;
                            case Types.SMALLINT:
                                rowValues[columnIndex - 1] = Short.valueOf(value.trim());
                                break;
                            case Types.INTEGER:
                                rowValues[columnIndex - 1] = Integer.valueOf(value.trim());
                                break;
                            case Types.BIGINT:
                                rowValues[columnIndex - 1] = Long.valueOf(value.trim());
                                break;
                            case Types.REAL:
                                rowValues[columnIndex - 1] = Float.valueOf(value.trim());
                                break;
                            case Types.FLOAT:
                            case Types.DOUBLE:
                                rowValues[columnIndex - 1] = Double.valueOf(value.trim());
                                break;
                            case Types.DECIMAL:
                            case Types.NUMERIC:
                                rowValues[columnIndex - 1] = new BigDecimal(value.trim());
                                break;
                            case Types.BOOLEAN:
                            case Types.BIT:
                                rowValues[columnIndex - 1] = Boolean.valueOf(value.trim());
                                break;
                            case Types.CHAR:
                            case Types.VARCHAR:
                            case Types.LONGVARCHAR:
                                rowValues[columnIndex - 1] = value;
                                break;
                            case Types.VARBINARY:
                            case Types.LONGVARBINARY:
                            case Types.BINARY:
                                byte[] bytes = Base64.decode(value);
                                rowValues[columnIndex - 1] = bytes;
                                break;
                            case Types.DATE:
                            case Types.TIME:
                            case Types.TIMESTAMP:
                                rowValues[columnIndex - 1] = new Timestamp(Long.parseLong(value.trim()));
                                break;
                            case Types.ARRAY:
                            case Types.BLOB:
                            case Types.CLOB:
                            case Types.DATALINK:
                            case Types.DISTINCT:
                            case Types.JAVA_OBJECT:
                            case Types.OTHER:
                            case Types.REF:
                            case Types.STRUCT:
                                //what to do with this?
                                break;
                            default :
                                //do nothing
                        }
                    }
                }
                
                /**
                 * @inheritDoc
                 */
                public void endDocument() throws SAXException {
                    doLoad(table, dataToLoad);
                    if (completionRunnable != null) {
                        SwingUtilities.invokeLater(completionRunnable);
                    }
                }
                
                /**
                 * @inheritDoc
                 */
                public void endElement(String uri, String localName, String qName) throws SAXException {
                    if (tagStack.size() == 0) {
                        return;
                    }
                    //get the last tag seen
                    String tag = tagStack.pop();
                    //handle each tag. Handle the data tags first since those will be called most frequently
                    try {
                        if (tag.equals("null")) {
                            wasNull = true;
                        } else if (tag.equals("columnvalue")) {
                            //set the current column value
                            setValue(columnIndex++, wasNull ? null : data);
                        } else if (tag.equals("updatevalue")) {
                            //set the update column value (the column to
                            //apply the update to is the previous
                            //columnIndex)
                            setValue(columnIndex-1, wasNull ? null : data);
                        } else if (tag.equals("currentrow")) {
                            RowLoadItem loadItem = new RowLoadItem();
                            loadItem.values = new Object[rowValues.length];
                            System.arraycopy(rowValues, 0, loadItem.values, 0, rowValues.length);
                            loadItem.status = DataRow.DataRowStatus.UNCHANGED;
                            dataToLoad.add(loadItem);
                        } else if (tag.equals("insertrow")) {
                            RowLoadItem loadItem = new RowLoadItem();
                            loadItem.values = new Object[rowValues.length];
                            System.arraycopy(rowValues, 0, loadItem.values, 0, rowValues.length);
                            loadItem.status = DataRow.DataRowStatus.INSERTED;
                        } else if (tag.equals("deleterow")) {
                            RowLoadItem loadItem = new RowLoadItem();
                            loadItem.values = new Object[rowValues.length];
                            System.arraycopy(rowValues, 0, loadItem.values, 0, rowValues.length);
                            loadItem.status = DataRow.DataRowStatus.DELETED;
                        } else if (tag.equals("modifyrow")) {
                            RowLoadItem loadItem = new RowLoadItem();
                            loadItem.values = new Object[rowValues.length];
                            System.arraycopy(rowValues, 0, loadItem.values, 0, rowValues.length);
                            loadItem.status = DataRow.DataRowStatus.UPDATED;
                        }  else if (tag.equals("column")) {
                            //in key-columns
                            if (!wasNull) {
                                keyColumnsStack.push(new Integer(data.trim()));
                            }
                        } else if (tag.equals("type")) {
                            mapType = wasNull ? null : data;
                        } else if (tag.equals("class")) {
                            mapClass = wasNull ? null : data;
                            //add the type and class to the typeMap
                            typeMap.put(mapType, mapClass == null ? null : Class.forName(mapClass));
                        } else if (tag.equals("table-name")) {
                            if (inProperties) {
//                                        setTableName(wasNull ? null : data);
                            } else if (inMetaData) {
                                metaData.setTableName(columnIndex, wasNull ? null : data);
                            }
                        } else if (tag.equals("column-count")) {
                            metaData.setColumnCount(wasNull ? 0 : Integer.parseInt(data.trim()));
                        } else if (tag.equals("column-index")) {
                            columnIndex = Integer.parseInt(data.trim());
                        } else if (tag.equals("key-columns")) {
                            int[] kc = new int[keyColumnsStack.size()];
                            int i = 0;
                            for (Integer col : keyColumnsStack) {
                                kc[i++] = col.intValue();
                            }
//                            try {
//                                        setKeyColumns(kc);
//                            } catch (Exception e) {
//                                e.printStackTrace();
//                                        LOG.error("Failed to set the key columns, even after parsing. Columns were " + keyColumnsStack, e);
//                            }
                        } else if (tag.equals("map")) {
                            //if the tag was a map tag, then put the map
                            // elements into the map
//                                    setTypeMap(typeMap);
                        } else if (tag.equals("auto-increment")) {
                            metaData.setAutoIncrement(columnIndex, wasNull ? false : Boolean.parseBoolean(data));
                        } else if (tag.equals("case-sensitive")) {
                            metaData.setCaseSensitive(columnIndex, wasNull ? false : Boolean.parseBoolean(data));
                        } else if (tag.equals("currency")) {
                            metaData.setCurrency(columnIndex, wasNull ? false : Boolean.parseBoolean(data.trim()));
                        } else if (tag.equals("nullable")) {
                            metaData.setNullable(columnIndex, wasNull ? 0 : Integer.parseInt(data.trim()));
                        } else if (tag.equals("signed")) {
                            metaData.setSigned(columnIndex, wasNull ? false : Boolean.parseBoolean(data.trim()));
                        } else if (tag.equals("searchable")) {
                            metaData.setSearchable(columnIndex, wasNull ? false : Boolean.parseBoolean(data.trim()));
                        } else if (tag.equals("column-display-size")) {
                            metaData.setColumnDisplaySize(columnIndex, wasNull ? 255 : Integer.parseInt(data.trim()));
                        } else if (tag.equals("column-label")) {
                            metaData.setColumnLabel(columnIndex, wasNull ? null : data);
                        } else if (tag.equals("column-name")) {
                            metaData.setColumnName(columnIndex, data);
                        } else if (tag.equals("schema-name")) {
                            metaData.setSchemaName(columnIndex, wasNull ? null : data);
                        } else if (tag.equals("column-precision")) {
                            metaData.setPrecision(columnIndex, wasNull ? 0 : Integer.parseInt(data.trim()));
                        } else if (tag.equals("column-scale")) {
                            metaData.setScale(columnIndex, wasNull ? 0 : Integer.parseInt(data.trim()));
                        } else if (tag.equals("catalog-name")) {
                            metaData.setCatalogName(columnIndex, wasNull ? null : data);
                        } else if (tag.equals("column-type")) {
                            metaData.setColumnType(columnIndex, wasNull ? Types.VARCHAR : Integer.parseInt(data.trim()));
                        } else if (tag.equals("column-type-name")) {
                            metaData.setColumnTypeName(columnIndex, wasNull ? null : data);
                        } else if (tag.equals("metadata")) {
                            //drop all of the columns in the data table
                            //and rebuild them based on this meta-data
                            SwingUtilities.invokeAndWait(new Runnable() {
                                public void run() {
                                    table.clear();
                                    DataColumn[] cols = table.getColumns().toArray(new DataColumn[table.getColumns().size()]);
                                    //TODO! broken -- needs to chuck the old dataset entirely
                                    throw new AssertionError("Broken");
//                                    for (DataColumn col : cols) {
//                                        table.dropColumn(col.getName());
//                                    }
//                                    
//                                    //time to rebuild
//                                    try {
//                                        for (int i=0; i<metaData.getColumnCount(); i++) {
//                                            DataColumn col = table.createColumn(metaData.getColumnName(i+1));
//                                            switch (metaData.getColumnType(i+1)) {
//                                                case Types.TINYINT:
//                                                    col.setType(Byte.class);
//                                                    break;
//                                                case Types.SMALLINT:
//                                                    col.setType(Short.class);
//                                                    break;
//                                                case Types.INTEGER:
//                                                    col.setType(Integer.class);
//                                                    break;
//                                                case Types.BIGINT:
//                                                    col.setType(BigInteger.class);
//                                                    break;
//                                                case Types.REAL:
//                                                    col.setType(Float.class);
//                                                    break;
//                                                case Types.FLOAT:
//                                                case Types.DOUBLE:
//                                                    col.setType(Double.class);
//                                                    break;
//                                                case Types.DECIMAL:
//                                                case Types.NUMERIC:
//                                                    col.setType(BigDecimal.class);
//                                                    break;
//                                                case Types.BOOLEAN:
//                                                case Types.BIT:
//                                                    col.setType(Boolean.class);
//                                                    break;
//                                                case Types.CHAR:
//                                                case Types.VARCHAR:
//                                                case Types.LONGVARCHAR:
//                                                    col.setType(String.class);
//                                                    break;
//                                                case Types.VARBINARY:
//                                                case Types.LONGVARBINARY:
//                                                case Types.BINARY:
//                                                    col.setType(Byte[].class);
//                                                    break;

⌨️ 快捷键说明

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