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

📄 testalltypes.java

📁 hsqldb是100%java实现的数据库,是一个开放源代码的JAVA数据库 l 具有标准的SQL语法和JAVA接口 l HSQLDB可以自由使用和分发 l 非常简洁和快速的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    System.out.println("Insert " + (i + 1) + " : "                                       + sw.elapsedTime());                }                // delete and add 4000 rows to introduce fragmentation                if (deleteWhileInsert && i != 0                        && i % deleteWhileInsertInterval == 0) {                    sStatement.execute("CALL IDENTITY();");                    ResultSet rs = sStatement.getResultSet();                    rs.next();                    int lastId = rs.getInt(1);                    sStatement.execute(                        "SELECT * INTO TEMP tempt FROM test WHERE id > "                        + (lastId - 4000) + " ;");                    sStatement.execute("DELETE FROM test WHERE id > "                                       + (lastId - 4000) + " ;");                    sStatement.execute(                        "INSERT INTO test SELECT * FROM tempt;");                    sStatement.execute("DROP TABLE tempt;");                }            }//            sStatement.execute("INSERT INTO test SELECT * FROM temptest;");//            sStatement.execute("DROP TABLE temptest;");//            sStatement.execute(ddl7);            System.out.println("Total insert: " + i);            System.out.println("Insert time: " + sw.elapsedTime() + " rps: "                               + (i * 1000 / sw.elapsedTime()));            sw.zero();            if (!network) {                sStatement.execute("SHUTDOWN");            }            cConnection.close();            System.out.println("Shutdown Time: " + sw.elapsedTime());        } catch (SQLException e) {            System.out.println(e.getMessage());        }    }    protected void tearDown() {}    protected void checkResults() {        try {            StopWatch sw = new StopWatch();            ResultSet rs;            cConnection = DriverManager.getConnection(url + filepath, user,                    password);            System.out.println("Reopened database: " + sw.elapsedTime());            sw.zero();            sStatement = cConnection.createStatement();            sStatement.execute("SET WRITE_DELAY " + writeDelay);            // the tests use different indexes            // use primary index            sStatement.execute("SELECT count(*) from TEST");            rs = sStatement.getResultSet();            rs.next();            System.out.println("Row Count: " + rs.getInt(1));            System.out.println("Time to count: " + sw.elapsedTime());            // use index on zip            sw.zero();            sStatement.execute("SELECT count(*) from TEST where zip > -1");            rs = sStatement.getResultSet();            rs.next();            System.out.println("Row Count: " + rs.getInt(1));            System.out.println("Time to count: " + sw.elapsedTime());            checkSelects();            checkUpdates();            sw.zero();            cConnection.close();            System.out.println("Closed connection: " + sw.elapsedTime());        } catch (SQLException e) {            System.out.println(e.getMessage());        }    }    private void checkSelects() {        StopWatch        sw        = new StopWatch();        int              smallrows = 0xfff;        java.util.Random randomgen = new java.util.Random();        int              i         = 0;        boolean          slow      = false;        try {            for (; i < bigrows; i++) {                PreparedStatement ps = cConnection.prepareStatement(                    "SELECT TOP 1 firstname,lastname,zip,filler FROM test WHERE zip = ?");                ps.setInt(1, nextIntRandom(randomgen, smallrows));                ps.execute();                if ((i + 1) == 100 && sw.elapsedTime() > 5000) {                    slow = true;                }                if (reportProgress && (i + 1) % 10000 == 0                        || (slow && (i + 1) % 100 == 0)) {                    System.out.println("Select " + (i + 1) + " : "                                       + sw.elapsedTime() + " rps: "                                       + (i * 1000 / sw.elapsedTime()));                }            }        } catch (SQLException e) {}        System.out.println("Select random zip " + i + " rows : "                           + sw.elapsedTime() + " rps: "                           + (i * 1000 / sw.elapsedTime()));        sw.zero();        try {            for (i = 0; i < bigrows; i++) {                PreparedStatement ps = cConnection.prepareStatement(                    "SELECT firstname,lastname,zip,filler FROM test WHERE id = ?");                ps.setInt(1, nextIntRandom(randomgen, bigrows - 1));                ps.execute();                if (reportProgress && (i + 1) % 10000 == 0                        || (slow && (i + 1) % 100 == 0)) {                    System.out.println("Select " + (i + 1) + " : "                                       + sw.elapsedTime());                }            }        } catch (SQLException e) {}        System.out.println("Select random id " + i + " rows : "                           + sw.elapsedTime() + " rps: "                           + (i * 1000 / sw.elapsedTime()));    }    private void checkUpdates() {        StopWatch        sw        = new StopWatch();        int              smallrows = 0xfff;        java.util.Random randomgen = new java.util.Random();        int              i         = 0;        boolean          slow      = false;        int              count     = 0;        try {            for (; i < smallrows; i++) {                PreparedStatement ps = cConnection.prepareStatement(                    "UPDATE test SET filler = filler || zip WHERE zip = ?");                int random = nextIntRandom(randomgen, smallrows - 1);                ps.setInt(1, random);                count += ps.executeUpdate();                if (reportProgress && count % 10000 < 20) {                    System.out.println("Update " + count + " : "                                       + sw.elapsedTime());                }            }        } catch (SQLException e) {}        System.out.println("Update with random zip " + i                           + " UPDATE commands, " + count + " rows : "                           + sw.elapsedTime() + " rps: "                           + (count * 1000 / sw.elapsedTime()));        sw.zero();        try {            for (i = 0; i < bigrows; i++) {                PreparedStatement ps = cConnection.prepareStatement(                    "UPDATE test SET zip = zip + 1 WHERE id = ?");                int random = nextIntRandom(randomgen, bigrows - 1);                ps.setInt(1, random);                ps.execute();                if (reportProgress && (i + 1) % 10000 == 0                        || (slow && (i + 1) % 100 == 0)) {                    System.out.println("Update " + (i + 1) + " : "                                       + sw.elapsedTime() + " rps: "                                       + (i * 1000 / sw.elapsedTime()));                }            }        } catch (SQLException e) {}        System.out.println("Update with random id " + i + " rows : "                           + sw.elapsedTime() + " rps: "                           + (i * 1000 / sw.elapsedTime()));    }    int nextIntRandom(Random r, int range) {        int b = Math.abs(r.nextInt());        return b % range;    }    public static void main(String[] argv) {        StopWatch    sw   = new StopWatch();        TestAllTypes test = new TestAllTypes();        test.setUp();        test.testFillUp();        test.tearDown();        test.checkResults();        System.out.println("Total Test Time: " + sw.elapsedTime());    }}

⌨️ 快捷键说明

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