Search in sources :

Example 51 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class Server method createWebServer.

/**
 * Create a new web server, but does not start it yet. Example:
 *
 * <pre>
 * Server server = Server.createWebServer("-trace").start();
 * </pre>
 * Supported options are:
 * -webPort, -webSSL, -webAllowOthers, -webDaemon,
 * -trace, -ifExists, -baseDir, -properties.
 * See the main method for details.
 *
 * @param args the argument list
 * @return the server
 */
public static Server createWebServer(String... args) throws SQLException {
    WebServer service = new WebServer();
    Server server = new Server(service, args);
    service.setShutdownHandler(server);
    return server;
}
Also used : TcpServer(org.h2.server.TcpServer) WebServer(org.h2.server.web.WebServer) PgServer(org.h2.server.pg.PgServer) WebServer(org.h2.server.web.WebServer)

Example 52 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class JdbcStatement method checkClosed.

/**
 * INTERNAL.
 * Check if the statement is closed.
 *
 * @param write if the next operation is possibly writing
 * @return true if a reconnect was required
 * @throws DbException if it is closed
 */
protected boolean checkClosed(boolean write) {
    if (conn == null) {
        throw DbException.get(ErrorCode.OBJECT_CLOSED);
    }
    conn.checkClosed(write);
    SessionInterface s = conn.getSession();
    if (s != session) {
        session = s;
        trace = session.getTrace();
        return true;
    }
    return false;
}
Also used : SessionInterface(org.h2.engine.SessionInterface)

Example 53 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestFullText method testMultiThreaded.

private void testMultiThreaded(boolean lucene) throws Exception {
    final String prefix = lucene ? "FTL" : "FT";
    trace("Testing multithreaded " + prefix);
    deleteDb("fullText");
    ArrayList<Connection> connList = new ArrayList<>();
    try {
        int len = 2;
        Task[] task = new Task[len];
        for (int i = 0; i < len; i++) {
            final Connection conn = getConnection("fullText;LOCK_TIMEOUT=60000", connList);
            Statement stat = conn.createStatement();
            initFullText(stat, lucene);
            initFullText(stat, lucene);
            final String tableName = "TEST" + i;
            stat.execute("CREATE TABLE " + tableName + "(ID INT PRIMARY KEY, DATA VARCHAR)");
            stat.execute("CALL " + prefix + "_CREATE_INDEX('PUBLIC', '" + tableName + "', NULL)");
            task[i] = new Task() {

                @Override
                public void call() throws SQLException {
                    trace("starting thread " + Thread.currentThread());
                    PreparedStatement prep = conn.prepareStatement("INSERT INTO " + tableName + " VALUES(?, ?)");
                    Statement stat = conn.createStatement();
                    Random random = new Random();
                    int x = 0;
                    while (!stop) {
                        trace("stop = " + stop + " for " + Thread.currentThread());
                        StringBuilder buff = new StringBuilder();
                        for (int j = 0; j < 1000; j++) {
                            buff.append(" ").append(random.nextInt(10000));
                            buff.append(" x").append(j);
                            buff.append(" ").append(KNOWN_WORDS[j % KNOWN_WORDS.length]);
                        }
                        prep.setInt(1, x);
                        prep.setString(2, buff.toString());
                        prep.execute();
                        x++;
                        for (String knownWord : KNOWN_WORDS) {
                            trace("searching for " + knownWord + " with " + Thread.currentThread());
                            ResultSet rs = stat.executeQuery("SELECT * FROM " + prefix + "_SEARCH('" + knownWord + "', 0, 0)");
                            assertTrue(rs.next());
                        }
                    }
                    trace("closing connection");
                    if (!config.memory) {
                        conn.close();
                    }
                    trace("completed thread " + Thread.currentThread());
                }
            };
        }
        for (Task t : task) {
            t.execute();
        }
        trace("sleeping");
        Thread.sleep(1000);
        trace("setting stop to true");
        for (Task t : task) {
            trace("joining " + t);
            t.get();
            trace("done joining " + t);
        }
    } finally {
        close(connList);
    }
}
Also used : Task(org.h2.util.Task) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Random(java.util.Random) ResultSet(java.sql.ResultSet)

Example 54 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestCsv method testWriteRead.

private void testWriteRead() throws SQLException {
    deleteDb("csv");
    Connection conn = getConnection("csv");
    Statement stat = conn.createStatement();
    stat.execute("CREATE TABLE TEST(ID IDENTITY, NAME VARCHAR)");
    // int len = 100000;
    int len = 100;
    for (int i = 0; i < len; i++) {
        stat.execute("INSERT INTO TEST(NAME) VALUES('Ruebezahl')");
    }
    long time;
    time = System.nanoTime();
    new Csv().write(conn, getBaseDir() + "/testRW.csv", "SELECT X ID, 'Ruebezahl' NAME FROM SYSTEM_RANGE(1, " + len + ")", "UTF8");
    trace("write: " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - time));
    ResultSet rs;
    time = System.nanoTime();
    for (int i = 0; i < 30; i++) {
        rs = new Csv().read(getBaseDir() + "/testRW.csv", null, "UTF8");
        while (rs.next()) {
        // ignore
        }
    }
    trace("read: " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - time));
    rs = new Csv().read(getBaseDir() + "/testRW.csv", null, "UTF8");
    // stat.execute("CREATE ALIAS CSVREAD FOR \"org.h2.tools.Csv.read\"");
    ResultSetMetaData meta = rs.getMetaData();
    assertEquals(2, meta.getColumnCount());
    for (int i = 0; i < len; i++) {
        rs.next();
        assertEquals("" + (i + 1), rs.getString("ID"));
        assertEquals("Ruebezahl", rs.getString("NAME"));
    }
    assertFalse(rs.next());
    rs.close();
    conn.close();
    FileUtils.delete(getBaseDir() + "/testRW.csv");
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Csv(org.h2.tools.Csv) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 55 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestMultiDimension method testPerformance2d.

private void testPerformance2d() throws SQLException {
    deleteDb("multiDimension");
    Connection conn;
    conn = getConnection("multiDimension");
    Statement stat = conn.createStatement();
    stat.execute("CREATE ALIAS MAP FOR \"" + getClass().getName() + ".interleave\"");
    stat.execute("CREATE TABLE TEST(X INT NOT NULL, Y INT NOT NULL, " + "XY BIGINT AS MAP(X, Y), DATA VARCHAR)");
    stat.execute("CREATE INDEX IDX_X ON TEST(X, Y)");
    stat.execute("CREATE INDEX IDX_XY ON TEST(XY)");
    PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST(X, Y, DATA) VALUES(?, ?, ?)");
    // the MultiDimension tool is faster for 4225 (65^2) points
    // the more the bigger the difference
    int max = getSize(30, 65);
    long time = System.nanoTime();
    for (int x = 0; x < max; x++) {
        for (int y = 0; y < max; y++) {
            long t2 = System.nanoTime();
            if (t2 - time > TimeUnit.SECONDS.toNanos(1)) {
                int percent = (int) (100.0 * ((double) x * max + y) / ((double) max * max));
                trace(percent + "%");
                time = t2;
            }
            prep.setInt(1, x);
            prep.setInt(2, y);
            prep.setString(3, "Test data");
            prep.execute();
        }
    }
    stat.execute("ANALYZE SAMPLE_SIZE 10000");
    PreparedStatement prepRegular = conn.prepareStatement("SELECT * FROM TEST WHERE X BETWEEN ? AND ? " + "AND Y BETWEEN ? AND ? ORDER BY X, Y");
    MultiDimension multi = MultiDimension.getInstance();
    String sql = multi.generatePreparedQuery("TEST", "XY", new String[] { "X", "Y" });
    sql += " ORDER BY X, Y";
    PreparedStatement prepMulti = conn.prepareStatement(sql);
    long timeMulti = 0, timeRegular = 0;
    int timeMax = getSize(500, 2000);
    Random rand = new Random(1);
    while (timeMulti < timeMax) {
        int size = rand.nextInt(max / 10);
        int minX = rand.nextInt(max - size);
        int minY = rand.nextInt(max - size);
        int maxX = minX + size, maxY = minY + size;
        time = System.nanoTime();
        ResultSet rs1 = multi.getResult(prepMulti, new int[] { minX, minY }, new int[] { maxX, maxY });
        timeMulti += System.nanoTime() - time;
        time = System.nanoTime();
        prepRegular.setInt(1, minX);
        prepRegular.setInt(2, maxX);
        prepRegular.setInt(3, minY);
        prepRegular.setInt(4, maxY);
        ResultSet rs2 = prepRegular.executeQuery();
        timeRegular += System.nanoTime() - time;
        while (rs1.next()) {
            assertTrue(rs2.next());
            assertEquals(rs1.getInt(1), rs2.getInt(1));
            assertEquals(rs1.getInt(2), rs2.getInt(2));
        }
        assertFalse(rs2.next());
    }
    conn.close();
    deleteDb("multiDimension");
    trace("2d: regular: " + TimeUnit.NANOSECONDS.toMillis(timeRegular) + " MultiDimension: " + TimeUnit.NANOSECONDS.toMillis(timeMulti));
}
Also used : Random(java.util.Random) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MultiDimension(org.h2.tools.MultiDimension)

Aggregations

SQLException (java.sql.SQLException)16 DbException (org.h2.message.DbException)14 Connection (java.sql.Connection)11 ResultSet (java.sql.ResultSet)10 PreparedStatement (java.sql.PreparedStatement)9 Statement (java.sql.Statement)8 IOException (java.io.IOException)7 Savepoint (java.sql.Savepoint)7 Random (java.util.Random)7 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 TraceSystem (org.h2.message.TraceSystem)5 Server (org.h2.tools.Server)5 ValueString (org.h2.value.ValueString)5 SQLClientInfoException (java.sql.SQLClientInfoException)4 SysProperties (org.h2.engine.SysProperties)4 JdbcConnection (org.h2.jdbc.JdbcConnection)4 SortedProperties (org.h2.util.SortedProperties)4 Value (org.h2.value.Value)4 Socket (java.net.Socket)3