Search in sources :

Example 46 with Trace

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

the class WebServer method listen.

@Override
public void listen() {
    this.listenerThread = Thread.currentThread();
    try {
        while (serverSocket != null) {
            Socket s = serverSocket.accept();
            WebThread c = new WebThread(s, this);
            running.add(c);
            c.start();
        }
    } catch (Exception e) {
        trace(e.toString());
    }
}
Also used : Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 47 with Trace

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

the class JdbcConnection method setSavepoint.

/**
 * Creates a new named savepoint.
 *
 * @param name the savepoint name
 * @return the new savepoint
 */
@Override
public Savepoint setSavepoint(String name) throws SQLException {
    try {
        int id = getNextId(TraceObject.SAVEPOINT);
        if (isDebugEnabled()) {
            debugCodeAssign("Savepoint", TraceObject.SAVEPOINT, id, "setSavepoint(" + quote(name) + ")");
        }
        checkClosed();
        CommandInterface set = prepareCommand("SAVEPOINT " + JdbcSavepoint.getName(name, 0), Integer.MAX_VALUE);
        set.executeUpdate(false);
        return new JdbcSavepoint(this, 0, name, trace, id);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : CommandInterface(org.h2.command.CommandInterface) Savepoint(java.sql.Savepoint) DbException(org.h2.message.DbException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException)

Example 48 with Trace

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

the class JdbcConnection method getMetaData.

/**
 * Gets the database meta data for this database.
 *
 * @return the database meta data
 * @throws SQLException if the connection is closed
 */
@Override
public DatabaseMetaData getMetaData() throws SQLException {
    try {
        int id = getNextId(TraceObject.DATABASE_META_DATA);
        if (isDebugEnabled()) {
            debugCodeAssign("DatabaseMetaData", TraceObject.DATABASE_META_DATA, id, "getMetaData()");
        }
        checkClosed();
        return new JdbcDatabaseMetaData(this, trace, id);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : Savepoint(java.sql.Savepoint) DbException(org.h2.message.DbException) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException)

Example 49 with Trace

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

the class Server method createTcpServer.

/**
 * Create a new TCP server, but does not start it yet. Example:
 *
 * <pre>
 * Server server = Server.createTcpServer(
 *     "-tcpPort", "9123", "-tcpAllowOthers").start();
 * </pre>
 * Supported options are:
 * -tcpPort, -tcpSSL, -tcpPassword, -tcpAllowOthers, -tcpDaemon,
 * -trace, -ifExists, -baseDir, -key.
 * See the main method for details.
 * <p>
 * If no port is specified, the default port is used if possible,
 * and if this port is already used, a random port is used.
 * Use getPort() or getURL() after starting to retrieve the port.
 * </p>
 *
 * @param args the argument list
 * @return the server
 */
public static Server createTcpServer(String... args) throws SQLException {
    TcpServer service = new TcpServer();
    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) TcpServer(org.h2.server.TcpServer)

Example 50 with Trace

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

the class Server method runTool.

@Override
public void runTool(String... args) throws SQLException {
    boolean tcpStart = false, pgStart = false, webStart = false;
    boolean browserStart = false;
    boolean tcpShutdown = false, tcpShutdownForce = false;
    String tcpPassword = "";
    String tcpShutdownServer = "";
    boolean startDefaultServers = true;
    for (int i = 0; args != null && i < args.length; i++) {
        String arg = args[i];
        if (arg == null) {
        } else if ("-?".equals(arg) || "-help".equals(arg)) {
            showUsage();
            return;
        } else if (arg.startsWith("-web")) {
            if ("-web".equals(arg)) {
                startDefaultServers = false;
                webStart = true;
            } else if ("-webAllowOthers".equals(arg)) {
            // no parameters
            } else if ("-webDaemon".equals(arg)) {
            // no parameters
            } else if ("-webSSL".equals(arg)) {
            // no parameters
            } else if ("-webPort".equals(arg)) {
                i++;
            } else {
                showUsageAndThrowUnsupportedOption(arg);
            }
        } else if ("-browser".equals(arg)) {
            startDefaultServers = false;
            browserStart = true;
        } else if (arg.startsWith("-tcp")) {
            if ("-tcp".equals(arg)) {
                startDefaultServers = false;
                tcpStart = true;
            } else if ("-tcpAllowOthers".equals(arg)) {
            // no parameters
            } else if ("-tcpDaemon".equals(arg)) {
            // no parameters
            } else if ("-tcpSSL".equals(arg)) {
            // no parameters
            } else if ("-tcpPort".equals(arg)) {
                i++;
            } else if ("-tcpPassword".equals(arg)) {
                tcpPassword = args[++i];
            } else if ("-tcpShutdown".equals(arg)) {
                startDefaultServers = false;
                tcpShutdown = true;
                tcpShutdownServer = args[++i];
            } else if ("-tcpShutdownForce".equals(arg)) {
                tcpShutdownForce = true;
            } else {
                showUsageAndThrowUnsupportedOption(arg);
            }
        } else if (arg.startsWith("-pg")) {
            if ("-pg".equals(arg)) {
                startDefaultServers = false;
                pgStart = true;
            } else if ("-pgAllowOthers".equals(arg)) {
            // no parameters
            } else if ("-pgDaemon".equals(arg)) {
            // no parameters
            } else if ("-pgPort".equals(arg)) {
                i++;
            } else {
                showUsageAndThrowUnsupportedOption(arg);
            }
        } else if ("-properties".equals(arg)) {
            i++;
        } else if ("-trace".equals(arg)) {
        // no parameters
        } else if ("-ifExists".equals(arg)) {
        // no parameters
        } else if ("-baseDir".equals(arg)) {
            i++;
        } else if ("-key".equals(arg)) {
            i += 2;
        } else {
            showUsageAndThrowUnsupportedOption(arg);
        }
    }
    verifyArgs(args);
    if (startDefaultServers) {
        tcpStart = true;
        pgStart = true;
        webStart = true;
        browserStart = true;
    }
    // TODO server: maybe use one single properties file?
    if (tcpShutdown) {
        out.println("Shutting down TCP Server at " + tcpShutdownServer);
        shutdownTcpServer(tcpShutdownServer, tcpPassword, tcpShutdownForce, false);
    }
    try {
        if (tcpStart) {
            tcp = createTcpServer(args);
            tcp.start();
            out.println(tcp.getStatus());
            tcp.setShutdownHandler(this);
        }
        if (pgStart) {
            pg = createPgServer(args);
            pg.start();
            out.println(pg.getStatus());
        }
        if (webStart) {
            web = createWebServer(args);
            web.setShutdownHandler(this);
            SQLException result = null;
            try {
                web.start();
            } catch (Exception e) {
                result = DbException.toSQLException(e);
            }
            out.println(web.getStatus());
            // are wondering why nothing happens
            if (browserStart) {
                try {
                    openBrowser(web.getURL());
                } catch (Exception e) {
                    out.println(e.getMessage());
                }
            }
            if (result != null) {
                throw result;
            }
        } else if (browserStart) {
            out.println("The browser can only start if a web server is started (-web)");
        }
    } catch (SQLException e) {
        stopAll();
        throw e;
    }
}
Also used : SQLException(java.sql.SQLException) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

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