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

📄 databasemanagerswing.java

📁 hsql是很有名的嵌入式数据库
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            }        }        DatabaseManagerSwing m = new DatabaseManagerSwing();        // Added: (weconsultants@users): Need databaseManagerSwing for later Reference        refForFontDialogSwing = m;        m.main();        Connection c = null;        m.setWaiting("Initializing");        try {            if (autoConnect && urlidConnect) {                throw new IllegalArgumentException(                    "You may not specify both (urlid) AND (url/user/password).");            }            if (autoConnect) {                c = ConnectionDialogSwing.createConnection(defDriver, defURL,                        defUser, defPassword);            } else if (urlidConnect) {                if (urlid == null) {                    throw new IllegalArgumentException(                        "You must specify an 'urlid' to use an RC file");                }                autoConnect = true;                String rcfilepath = (rcFile == null) ? DEFAULT_RCFILE                                                     : rcFile;                RCData rcdata     = new RCData(new File(rcfilepath), urlid);                c = rcdata.getConnection(                    null, System.getProperty("sqlfile.charset"),                    System.getProperty("javax.net.ssl.trustStore"));            } else {                c = ConnectionDialogSwing.createConnection(m.fMain,                        "Connect");            }        } catch (Exception e) {            //  Added: (weconsultants@users)            CommonSwing.errorMessage(e);        } finally {            m.setWaiting(null);        }        if (c == null) {            return;        }        // Added: (weconsultants@users): For preloadng FontDialogSwing        FontDialogSwing.CreatFontDialog(refForFontDialogSwing);        m.connect(c);    }    /**     * This stuff is all quick, except for the refreshTree().     * This unit can be kicked off in main Gui thread.  The refreshTree     * will be backgrounded and this method will return.     */    public void connect(Connection c) {        schemaFilter = null;        if (c == null) {            return;        }        if (cConn != null) {            try {                cConn.close();            } catch (SQLException e) {                //  Added: (weconsultants@users)                CommonSwing.errorMessage(e);            }        }        cConn = c;        // Added: (weconsultants@users) Need to barrow to get the table rowcounts        rowConn = c;        try {            dMeta      = cConn.getMetaData();            sStatement = cConn.createStatement();            updateAutoCommitBox();            // Workaround for EXTREME SLOWNESS getting this info from O.            showIndexDetails =                (dMeta.getDatabaseProductName().indexOf("Oracle") < 0);            refreshTree();        } catch (SQLException e) {            //  Added: (weconsultants@users)            CommonSwing.errorMessage(e);        }    }    private static void showUsage() {        System.out.println(            "Usage: java DatabaseManagerSwing [--options]\n"            + "where options include:\n"            + "    --driver <classname>  jdbc driver class\n"            + "    --url <name>          jdbc url\n"            + "    --user <name>         username used for connection\n"            + "    --password <password> password for this user\n"            + "    --urlid <urlid>       use url/user/password/driver in rc file\n"            + "    --rcfile <file>       (defaults to 'dbmanager.rc' in home dir)\n"            + "    --dir <path>          default directory\n"            + "    --script <file>       reads from script file\n"            + "    --noexit              do not call system.exit()\n"            + "(Single-hypen switches like '-driver' are also supported)");    }    private void insertTestData() {        try {            DatabaseManagerCommon.createTestTables(sStatement);            txtCommand.setText(                DatabaseManagerCommon.createTestData(sStatement));            for (int i = 0; i < DatabaseManagerCommon.testDataSql.length;                    i++) {                addToRecent(DatabaseManagerCommon.testDataSql[i]);            }            executeCurrentSQL();        } catch (SQLException e) {            //  Added: (weconsultants@users)            CommonSwing.errorMessage(e);        }    }    // Comment: (weconsultants@users) this boolean does not get referenced..?    public void setMustExit(boolean b) {        this.bMustExit = b;    }    private DBMPrefs prefs = null;    public void main() {        fMain = new JFrame("HSQL Database Manager");        try {            prefs = new DBMPrefs();        } catch (Exception e) {            // Just don't user persisted preferences.            prefs = null;        }        if (prefs == null) {            setLF(CommonSwing.Native);        } else {            autoRefresh      = prefs.autoRefresh;            displayRowCounts = prefs.showRowCounts;            showSys          = prefs.showSysTables;            showSchemas      = prefs.showSchemas;            gridFormat       = prefs.resultGrid;            showTooltips     = prefs.showTooltips;            setLF(prefs.laf);        }        // (ulrivo): An actual icon.  N.b., this adds some tips to the tip map        fMain.getContentPane().add(createToolBar(), "North");        fMain.setIconImage(CommonSwing.getIcon("Frame"));        fMain.addWindowListener(this);        JMenuBar bar = new JMenuBar();        // used shortcuts: CERGTSIUDOLM        String[] fitems = {            "-Connect...", "--", "OOpen Script...", "-Save Script...",            "-Save Result...", "--", "-Exit"        };        addMenu(bar, "File", fitems);        Object[] vitems = {            "RRefresh Tree", boxAutoRefresh, "--", boxRowCounts, boxShowSys,            boxShowSchemas, boxShowGrid        };        addMenu(bar, "View", vitems);        String[] sitems = {            "SSELECT", "IINSERT", "UUPDATE", "DDELETE", "EEXECUTE", "---",            "-CREATE TABLE", "-DROP TABLE", "-CREATE INDEX", "-DROP INDEX",            "--", "-CHECKPOINT", "-SCRIPT", "-SET", "-SHUTDOWN", "--",            "-Test Script"        };        addMenu(bar, "Command", sitems);        mRecent = new JMenu("Recent");        mRecent.setMnemonic(KeyEvent.VK_R);        bar.add(mRecent);        ButtonGroup lfGroup = new ButtonGroup();        lfGroup.add(rbNativeLF);        lfGroup.add(rbJavaLF);        lfGroup.add(rbMotifLF);        boxShowSchemas.setSelected(showSchemas);        boxShowGrid.setSelected(gridFormat);        boxTooltips.setSelected(showTooltips);        boxShowGrid.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G,                Event.CTRL_MASK));        boxAutoRefresh.setSelected(autoRefresh);        boxRowCounts.setSelected(displayRowCounts);        boxShowSys.setSelected(showSys);        rbNativeLF.setActionCommand("LFMODE:" + CommonSwing.Native);        rbJavaLF.setActionCommand("LFMODE:" + CommonSwing.Java);        rbMotifLF.setActionCommand("LFMODE:" + CommonSwing.Motif);        tipMap.put(mitemUpdateSchemas,                   "Refresh the schema list in this menu");        tipMap.put(rbAllSchemas, "Display items in all schemas");        tipMap.put(mitemAbout, "Display product information");        tipMap.put(mitemHelp, "Display advice for obtaining help");        tipMap.put(boxAutoRefresh,                   "Refresh tree (and schema list) automatically"                   + "when YOU modify database objects");        tipMap.put(boxShowSchemas,                   "Display object names in tree like schemaname.basename");        tipMap.put(rbNativeLF,                   "Set Look and Feel to Native for your platform");        tipMap.put(rbJavaLF, "Set Look and Feel to Java");        tipMap.put(rbMotifLF, "Set Look and Feel to Motif");        boxTooltips.setToolTipText(            "Display tooltips (hover text), like this");        tipMap.put(boxAutoCommit,                   "Shows current Auto-commit mode.  Click to change");        tipMap.put(            boxLogging,            "Shows current JDBC DriverManager logging mode.  Click to change");        tipMap.put(boxShowSys,                   "Show system tables in table tree to the left");        tipMap.put(boxShowGrid,                   "Show query results in grid (in text if off)");        tipMap.put(boxRowCounts, "Show row counts with table names in tree");        boxAutoRefresh.setMnemonic(KeyEvent.VK_C);        boxShowSchemas.setMnemonic(KeyEvent.VK_Y);        boxAutoCommit.setMnemonic(KeyEvent.VK_A);        boxShowSys.setMnemonic(KeyEvent.VK_Y);        boxShowGrid.setMnemonic(KeyEvent.VK_G);        boxRowCounts.setMnemonic(KeyEvent.VK_C);        boxLogging.setMnemonic(KeyEvent.VK_L);        rbAllSchemas.setMnemonic(KeyEvent.VK_ASTERISK);        rbNativeLF.setMnemonic(KeyEvent.VK_N);        rbJavaLF.setMnemonic(KeyEvent.VK_J);        rbMotifLF.setMnemonic(KeyEvent.VK_M);        mitemUpdateSchemas.setMnemonic(KeyEvent.VK_U);        Object[] soptions = {            // Added: (weconsultants@users) New menu options            rbNativeLF, rbJavaLF, rbMotifLF, "--", "-Set Fonts", "--",            boxAutoCommit, "CCommit", "LRollback", "--", "-Disable MaxRows",            "-Set MaxRows to 100", "--", boxLogging, "--", "-Insert test data"        };        addMenu(bar, "Options", soptions);        String[] stools = {            "-Dump", "-Restore", "-Transfer"        };        addMenu(bar, "Tools", stools);        mnuSchemas.setMnemonic(KeyEvent.VK_S);        bar.add(mnuSchemas);        JMenu mnuHelp = new JMenu("Help");        mnuHelp.setMnemonic(KeyEvent.VK_H);        mnuHelp.add(mitemAbout);        mnuHelp.add(mitemHelp);        mnuHelp.add(boxTooltips);        rbAllSchemas.addActionListener(schemaListListener);        // May be illegal:        mitemUpdateSchemas.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent actionevent) {                updateSchemaList();            }        });        mitemHelp.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent actionevent) {                JOptionPane.showMessageDialog(                    fMain.getContentPane(), HELP_TEXT, "HELP",                    JOptionPane.INFORMATION_MESSAGE);            }        });        mitemAbout.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent actionevent) {                JOptionPane.showMessageDialog(                    fMain.getContentPane(), ABOUT_TEXT, "About",                    JOptionPane.INFORMATION_MESSAGE);            }        });        boxTooltips.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent actionevent) {                showTooltips = boxTooltips.isSelected();                resetTooltips();            }        });        bar.add(mnuHelp);        fMain.setJMenuBar(bar);        initGUI();        sRecent = new String[iMaxRecent];        // Modified: (weconsultants@users)Mode code to CommonSwing for general use        CommonSwing.setFramePositon(fMain);        // Modified: (weconsultants@users) Changed from deprecated show()        fMain.setVisible(true);        // (ulrivo): load query from command line        if (defScript != null) {            if (defDirectory != null) {                defScript = defDirectory + File.separator + defScript;            }            // if insert stmet is thousands of records...skip showing it            // as text.  Too huge.            StringBuffer buf = new StringBuffer();            ifHuge = DatabaseManagerCommon.readFile(defScript);            if (4096 <= ifHuge.length()) {                buf.append(                    "This huge file cannot be edited. Please execute\n");                txtCommand.setText(buf.toString());            } else {                txtCommand.setText(ifHuge);            }        }        // This must be done AFTER all tip texts are put into the map        resetTooltips();        txtCommand.requestFocus();    }    private void addMenu(JMenuBar b, String name, Object[] items) {        JMenu menu = new JMenu(name);        menu.setMnemonic(name.charAt(0));        addMenuItems(menu, items);        b.add(menu);    }    private void addMenuItems(JMenu f, Object[] m) {        /*         * This method needs to be completely written or just         * obliterated and we'll use the Menu objects directly.         * Problem is, passing in Strings for menu elements makes it         * extremely difficult to use non-text menu items (an important         * part of a good Gui), hot-keys, mnemonic keys, tooltips.         * Note the "trick" required here to set hot-keys.         */        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();        for (int i = 0; i < m.length; i++) {            if (m[i].equals("--")) {                f.addSeparator();            } else if (m[i].equals("---")) {

⌨️ 快捷键说明

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