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

📄 databasemanagerswing.java

📁 hsql是很有名的嵌入式数据库
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        b.append(NL + height + " row(s) in " + lTime + " ms");        txtResult.setText(b.toString());    }    private void addToRecent(String s) {        for (int i = 0; i < iMaxRecent; i++) {            if (s.equals(sRecent[i])) {                return;            }        }        if (sRecent[iRecent] != null) {            mRecent.remove(iRecent);        }        sRecent[iRecent] = s;        if (s.length() > 43) {            s = s.substring(0, 40) + "...";        }        JMenuItem item = new JMenuItem(s);        item.setActionCommand("#" + iRecent);        item.addActionListener(this);        mRecent.insert(item, iRecent);        iRecent = (iRecent + 1) % iMaxRecent;    }    private void initGUI() {        JPanel pCommand = new JPanel();        pResult = new JPanel();        nsSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pCommand,                                     pResult);        // Added: (weconsultants@users)        nsSplitPane.setOneTouchExpandable(true);        pCommand.setLayout(new BorderLayout());        pResult.setLayout(new BorderLayout());        Font fFont = new Font("Dialog", Font.PLAIN, 12);        txtCommand = new JTextArea(5, 40);        txtCommand.setMargin(new Insets(5, 5, 5, 5));        txtCommand.addKeyListener(this);        txtCommandScroll = new JScrollPane(txtCommand);        txtResult        = new JTextArea(20, 40);        txtResult.setMargin(new Insets(5, 5, 5, 5));        txtResultScroll = new JScrollPane(txtResult);        txtCommand.setFont(fFont);        txtResult.setFont(new Font("Courier", Font.PLAIN, 12));/*// button replaced by toolbar        butExecute = new JButton("Execute");        butExecute.addActionListener(this);        pCommand.add(butExecute, BorderLayout.EAST);*/        pCommand.add(txtCommandScroll, BorderLayout.CENTER);        gResult = new GridSwing();        TableSorter sorter = new TableSorter(gResult);        tableModel   = sorter;        gResultTable = new JTable(sorter);        sorter.setTableHeader(gResultTable.getTableHeader());        gScrollPane = new JScrollPane(gResultTable);        gResultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);        gResult.setJTable(gResultTable);        //getContentPane().setLayout(new BorderLayout());        pResult.add(gScrollPane, BorderLayout.CENTER);        // Set up the tree        rootNode    = new DefaultMutableTreeNode("Connection");        treeModel   = new DefaultTreeModel(rootNode);        tTree       = new JTree(treeModel);        tScrollPane = new JScrollPane(tTree);        tScrollPane.setPreferredSize(new Dimension(120, 400));        tScrollPane.setMinimumSize(new Dimension(70, 100));        txtCommandScroll.setPreferredSize(new Dimension(360, 100));        txtCommandScroll.setMinimumSize(new Dimension(180, 100));        gScrollPane.setPreferredSize(new Dimension(460, 300));        ewSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,                                     tScrollPane, nsSplitPane);        // Added: (weconsultants@users)        ewSplitPane.setOneTouchExpandable(true);        fMain.getContentPane().add(ewSplitPane, BorderLayout.CENTER);        // Added: (weconsultants@users)        jStatusLine = new JLabel();        iReadyStatus =            new JButton(new ImageIcon(CommonSwing.getIcon("StatusReady")));        iReadyStatus.setSelectedIcon(            new ImageIcon(CommonSwing.getIcon("StatusRunning")));        pStatus = new JPanel();        pStatus.setLayout(new BorderLayout());        pStatus.add(iReadyStatus, BorderLayout.WEST);        pStatus.add(jStatusLine, BorderLayout.CENTER);        fMain.getContentPane().add(pStatus, "South");        doLayout();        fMain.pack();    }    /* Simple tree node factory method - set's parent and user object.     */    private DefaultMutableTreeNode makeNode(Object userObject,            MutableTreeNode parent) {        DefaultMutableTreeNode node = new DefaultMutableTreeNode(userObject);        if (parent != null) {            treeModel.insertNodeInto(node, parent, parent.getChildCount());        }        return node;    }    private static final String[] usertables       = {        "TABLE", "GLOBAL TEMPORARY", "VIEW", "SYSTEM TABLE"    };    private static final String[] nonSystables     = {        "TABLE", "GLOBAL TEMPORARY", "VIEW"    };    private static final HashSet  oracleSysUsers   = new HashSet();    private static final String[] oracleSysSchemas = {        "SYS", "SYSTEM", "OUTLN", "DBSNMP", "OUTLN", "MDSYS", "ORDSYS",        "ORDPLUGINS", "CTXSYS", "DSSYS", "PERFSTAT", "WKPROXY", "WKSYS",        "WMSYS", "XDB", "ANONYMOUS", "ODM", "ODM_MTR", "OLAPSYS", "TRACESVR",        "REPADMIN"    };    static {        for (int i = 0; i < oracleSysSchemas.length; i++) {            oracleSysUsers.add(oracleSysSchemas[i]);        }    }    /**     * Schedules to run in a Gui-safe thread     */    protected void refreshTree() {        backgroundIt(treeRefreshRunnable, "Refreshing object tree");    }    /**     * Clear all existing nodes from the tree model and rebuild from scratch.     *     * This method executes in current thread     */    protected void directRefreshTree() {        int[]                  rowCounts;        DefaultMutableTreeNode propertiesNode;        // Added: (weconsultants@users) Moved tableNode here for visibiity nd new DECFM        DefaultMutableTreeNode tableNode;        DecimalFormat DECFMT = new DecimalFormat(" ( ####,###,####,##0 )");        // First clear the existing tree by simply enumerating        // over the root node's children and removing them one by one.        while (treeModel.getChildCount(rootNode) > 0) {            DefaultMutableTreeNode child =                (DefaultMutableTreeNode) treeModel.getChild(rootNode, 0);            treeModel.removeNodeFromParent(child);            child.removeAllChildren();            child.removeFromParent();        }        treeModel.nodeStructureChanged(rootNode);        treeModel.reload();        tScrollPane.repaint();        // Now rebuild the tree below its root        try {            // Start by naming the root node from its URL:            rootNode.setUserObject(dMeta.getURL());            // get metadata about user tables by building a vector of table names            ResultSet result = dMeta.getTables(null, null, null,                                               (showSys ? usertables                                                        : nonSystables));            Vector tables  = new Vector();            Vector schemas = new Vector();            // sqlbob@users Added remarks.            Vector remarks = new Vector();            String schema;            while (result.next()) {                schema = result.getString(2);                if ((!showSys)                        && dMeta.getDatabaseProductName().indexOf("Oracle")                           > -1 && oracleSysUsers.contains(schema)) {                    continue;                }                if (schemaFilter == null || schema.equals(schemaFilter)) {                    schemas.addElement(schema);                    tables.addElement(result.getString(3));                    remarks.addElement(result.getString(5));                    continue;                }            }            result.close();            // Added: (weconsultants@users)            // Sort not to go into production. Have to sync with 'remarks Vector' for DBMS that has it            //   Collections.sort(tables);            // Added: (weconsultants@users) - Add rowCounts if needed.            rowCounts = new int[tables.size()];            try {                rowCounts = getRowCounts(tables, schemas);            } catch (Exception e) {                //  Added: (weconsultants@users)                CommonSwing.errorMessage(e);            }            // For each table, build a tree node with interesting info            for (int i = 0; i < tables.size(); i++) {                String name = (String) tables.elementAt(i);                schema = (String) schemas.elementAt(i);                String schemaname = "";                if (schema != null && showSchemas) {                    schemaname = schema + '.';                }                String rowcount = displayRowCounts                                  ? (", " + DECFMT.format(rowCounts[i]))                                  : "";                String displayedName = schemaname + name + rowcount;                // weconsul@ptd.net Add rowCounts if needed.                tableNode = makeNode(displayedName, rootNode);                ResultSet col = dMeta.getColumns(null, schema, name, null);                if ((schema != null) &&!schema.trim().equals("")) {                    makeNode(schema, tableNode);                }                // sqlbob@users Added remarks.                String remark = (String) remarks.elementAt(i);                if ((remark != null) &&!remark.trim().equals("")) {                    makeNode(remark, tableNode);                }                // This block is very slow for some Oracle tables.                // With a child for each column containing pertinent attributes                while (col.next()) {                    String c = col.getString(4);                    DefaultMutableTreeNode columnNode = makeNode(c,                        tableNode);                    String type = col.getString(6);                    makeNode("Type: " + type, columnNode);                    boolean nullable = col.getInt(11)                                       != DatabaseMetaData.columnNoNulls;                    makeNode("Nullable: " + nullable, columnNode);                }                col.close();                DefaultMutableTreeNode indexesNode = makeNode("Indices",                    tableNode);                ResultSet ind = null;                if (showIndexDetails) {                    try {                        ind = dMeta.getIndexInfo(null, schema, name, false,                                                 false);                        String                 oldiname  = null;                        DefaultMutableTreeNode indexNode = null;                        // A child node to contain each index - and its attributes                        while (ind.next()) {                            boolean nonunique = ind.getBoolean(4);                            String  iname     = ind.getString(6);                            if ((oldiname == null                                    ||!oldiname.equals(iname))) {                                indexNode = makeNode(iname, indexesNode);                                makeNode("Unique: " + !nonunique, indexNode);                                oldiname = iname;                            }                            // And the ordered column list for index components                            makeNode(ind.getString(9), indexNode);                        }                    } catch (SQLException se) {                        // Workaround for Oracle                        if (se.getMessage() == null || ((!se.getMessage()                                .startsWith("ORA-25191:")) && (!se                                .getMessage().startsWith("ORA-01702:")) &&!se                                    .getMessage().startsWith("ORA-01031:"))) {                            throw se;                        }                    } finally {                        if (ind != null) {                            ind.close();                            ind = null;                        }                    }                }            }            // Finally - a little additional metadata on this connection            propertiesNode = makeNode("Properties", rootNode);            makeNode("User: " + dMeta.getUserName(), propertiesNode);            makeNode("ReadOnly: " + cConn.isReadOnly(), propertiesNode);            makeNode("AutoCommit: " + cConn.getAutoCommit(), propertiesNode);            makeNode("Driver: " + dMeta.getDriverName(), propertiesNode);            makeNode("Product: " + dMeta.getDatabaseProductName(),                     propertiesNode);            makeNode("Version: " + dMeta.getDatabaseProductVersion(),                     propertiesNode);        } catch (SQLException se) {            propertiesNode = makeNode("Error getting metadata:", rootNode);            makeNode(se.getMessage(), propertiesNode);            makeNode(se.getSQLState(), propertiesNode);            CommonSwing.errorMessage(se);        }        treeModel.nodeStructureChanged(rootNode);        treeModel.reload();        tScrollPane.repaint();        // We want the Schema List to always be in sync with the displayed tree        updateSchemaList();    }    // Added: (weconsultants@users) Sets up\changes the running status icon    void setStatusLine(String busyBaseString) {        iReadyStatus.setSelected(busyBaseString != null);        if (busyBaseString == null) {            String additionalMsg = "";            if (schemaFilter != null) {                additionalMsg = " /  Tree showing objects in schema '"                                + schemaFilter + "'";            }            jStatusLine.setText("  " + READY_STATUS + additionalMsg);        } else {            jStatusLine.setText("  " + busyBaseString + ".

⌨️ 快捷键说明

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