Search in sources :

Example 61 with Command

use of org.h2.command.Command in project h2database by h2database.

the class JdbcPreparedStatement method executeUpdateInternal.

private int executeUpdateInternal() throws SQLException {
    closeOldResultSet();
    synchronized (session) {
        try {
            setExecutingStatement(command);
            ResultWithGeneratedKeys result = command.executeUpdate(generatedKeysRequest);
            updateCount = result.getUpdateCount();
            ResultInterface gk = result.getGeneratedKeys();
            if (gk != null) {
                int id = getNextId(TraceObject.RESULT_SET);
                generatedKeys = new JdbcResultSet(conn, this, command, gk, id, false, true, false);
            }
        } finally {
            setExecutingStatement(null);
        }
    }
    return updateCount;
}
Also used : ResultInterface(org.h2.result.ResultInterface) ResultWithGeneratedKeys(org.h2.result.ResultWithGeneratedKeys)

Example 62 with Command

use of org.h2.command.Command in project h2database by h2database.

the class JdbcStatement method executeUpdateInternal.

private int executeUpdateInternal(String sql, Object generatedKeysRequest) throws SQLException {
    checkClosedForWrite();
    try {
        closeOldResultSet();
        sql = JdbcConnection.translateSQL(sql, escapeProcessing);
        CommandInterface command = conn.prepareCommand(sql, fetchSize);
        synchronized (session) {
            setExecutingStatement(command);
            try {
                ResultWithGeneratedKeys result = command.executeUpdate(conn.scopeGeneratedKeys() ? false : generatedKeysRequest);
                updateCount = result.getUpdateCount();
                ResultInterface gk = result.getGeneratedKeys();
                if (gk != null) {
                    int id = getNextId(TraceObject.RESULT_SET);
                    generatedKeys = new JdbcResultSet(conn, this, command, gk, id, false, true, false);
                }
            } finally {
                setExecutingStatement(null);
            }
        }
        command.close();
        return updateCount;
    } finally {
        afterWriting();
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) CommandInterface(org.h2.command.CommandInterface) ResultWithGeneratedKeys(org.h2.result.ResultWithGeneratedKeys)

Example 63 with Command

use of org.h2.command.Command in project h2database by h2database.

the class JdbcStatement method executeQuery.

/**
 * Executes a query (select statement) and returns the result set.
 * If another result set exists for this statement, this will be closed
 * (even if this statement fails).
 *
 * @param sql the SQL statement to execute
 * @return the result set
 */
@Override
public ResultSet executeQuery(String sql) throws SQLException {
    try {
        int id = getNextId(TraceObject.RESULT_SET);
        if (isDebugEnabled()) {
            debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id, "executeQuery(" + quote(sql) + ")");
        }
        synchronized (session) {
            checkClosed();
            closeOldResultSet();
            sql = JdbcConnection.translateSQL(sql, escapeProcessing);
            CommandInterface command = conn.prepareCommand(sql, fetchSize);
            ResultInterface result;
            boolean lazy = false;
            boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
            boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
            setExecutingStatement(command);
            try {
                result = command.executeQuery(maxRows, scrollable);
                lazy = result.isLazy();
            } finally {
                if (!lazy) {
                    setExecutingStatement(null);
                }
            }
            if (!lazy) {
                command.close();
            }
            resultSet = new JdbcResultSet(conn, this, command, result, id, closedByResultSet, scrollable, updatable);
        }
        return resultSet;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ResultInterface(org.h2.result.ResultInterface) CommandInterface(org.h2.command.CommandInterface) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 64 with Command

use of org.h2.command.Command in project h2database by h2database.

the class TestView method testViewAlterAndCommandCache.

/**
 * Make sure that when we change a view, that change in reflected in other
 * sessions command cache.
 */
private void testViewAlterAndCommandCache() throws SQLException {
    deleteDb("view");
    Connection conn = getConnection("view");
    Statement stat = conn.createStatement();
    stat.execute("create table t0(id int primary key)");
    stat.execute("create table t1(id int primary key)");
    stat.execute("insert into t0 values(0)");
    stat.execute("insert into t1 values(1)");
    stat.execute("create view v1 as select * from t0");
    ResultSet rs = stat.executeQuery("select * from v1");
    assertTrue(rs.next());
    assertEquals(0, rs.getInt(1));
    stat.execute("create or replace view v1 as select * from t1");
    rs = stat.executeQuery("select * from v1");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    conn.close();
    deleteDb("view");
}
Also used : Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) JdbcConnection(org.h2.jdbc.JdbcConnection) ResultSet(java.sql.ResultSet)

Example 65 with Command

use of org.h2.command.Command in project nzbhydra2 by theotherp.

the class NzbHydra method main.

public static void main(String[] args) throws Exception {
    LoggerFactory.getILoggerFactory();
    String version = NzbHydra.class.getPackage().getImplementationVersion();
    OptionParser parser = new OptionParser();
    parser.accepts("datafolder", "Define path to main data folder. Must start with ./ for relative paths").withRequiredArg().defaultsTo("./data");
    parser.accepts("host", "Run on this host").withOptionalArg();
    parser.accepts("nobrowser", "Don't open browser to Hydra");
    parser.accepts("port", "Run on this port (default: 5076)").withOptionalArg();
    parser.accepts("baseurl", "Set base URL (e.g. /nzbhydra)").withOptionalArg();
    parser.accepts("repairdb", "Repair database. Add database file path as argument").withRequiredArg();
    parser.accepts("help", "Print help");
    parser.accepts("version", "Print version");
    OptionSet options = null;
    try {
        options = parser.parse(args);
    } catch (OptionException e) {
        logger.error("Invalid startup options detected: {}", e.getMessage());
        System.exit(1);
    }
    if (System.getProperty("fromWrapper") == null && Arrays.stream(args).noneMatch(x -> x.equals("directstart"))) {
        logger.info("NZBHydra 2 must be started using the wrapper for restart and updates to work. If for some reason you need to start it from the JAR directly provide the command line argument \"directstart\"");
    } else if (options.has("help")) {
        parser.printHelpOn(System.out);
    } else if (options.has("version")) {
        logger.info("NZBHydra 2 version: " + version);
    } else if (options.has("repairdb")) {
        String databaseFilePath = (String) options.valueOf("repairdb");
        repairDb(databaseFilePath);
    } else {
        startup(args, options);
    }
}
Also used : Arrays(java.util.Arrays) AopAutoConfiguration(org.springframework.boot.autoconfigure.aop.AopAutoConfiguration) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) UrlCalculator(org.nzbhydra.web.UrlCalculator) LoggerFactory(org.slf4j.LoggerFactory) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) SpringApplication(org.springframework.boot.SpringApplication) PreDestroy(javax.annotation.PreDestroy) OptionException(joptsimple.OptionException) ConfigProvider(org.nzbhydra.config.ConfigProvider) CacheManager(org.springframework.cache.CacheManager) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) OptionParser(joptsimple.OptionParser) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) EnableScheduling(org.springframework.scheduling.annotation.EnableScheduling) URI(java.net.URI) OptionSet(joptsimple.OptionSet) EnableCaching(org.springframework.cache.annotation.EnableCaching) DebugInfosProvider(org.nzbhydra.debuginfos.DebugInfosProvider) Logger(org.slf4j.Logger) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) EventListener(org.springframework.context.event.EventListener) IOException(java.io.IOException) GenericStorage(org.nzbhydra.genericstorage.GenericStorage) ApplicationContext(org.springframework.context.ApplicationContext) RestController(org.springframework.web.bind.annotation.RestController) ComponentScan(org.springframework.context.annotation.ComponentScan) File(java.io.File) GuavaCacheManager(org.springframework.cache.guava.GuavaCacheManager) Configuration(org.springframework.context.annotation.Configuration) java.awt(java.awt) BrowserOpener(org.nzbhydra.misc.BrowserOpener) WebSocketAutoConfiguration(org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration) ConnectorStartFailedException(org.springframework.boot.context.embedded.tomcat.ConnectorStartFailedException) PostConstruct(javax.annotation.PostConstruct) Flyway(org.flywaydb.core.Flyway) Bean(org.springframework.context.annotation.Bean) YAMLException(org.yaml.snakeyaml.error.YAMLException) javax.swing(javax.swing) OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Aggregations

ValueString (org.h2.value.ValueString)37 Expression (org.h2.expression.Expression)20 ValueExpression (org.h2.expression.ValueExpression)19 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)17 AlterTableDropConstraint (org.h2.command.ddl.AlterTableDropConstraint)16 AlterTableRenameConstraint (org.h2.command.ddl.AlterTableRenameConstraint)16 Column (org.h2.table.Column)16 IndexColumn (org.h2.table.IndexColumn)13 AlterTableAlterColumn (org.h2.command.ddl.AlterTableAlterColumn)12 ExpressionColumn (org.h2.expression.ExpressionColumn)12 Table (org.h2.table.Table)12 AlterTableRenameColumn (org.h2.command.ddl.AlterTableRenameColumn)11 Connection (java.sql.Connection)10 CreateLinkedTable (org.h2.command.ddl.CreateLinkedTable)10 CreateSchema (org.h2.command.ddl.CreateSchema)10 CreateTable (org.h2.command.ddl.CreateTable)10 DropSchema (org.h2.command.ddl.DropSchema)10 DropTable (org.h2.command.ddl.DropTable)10 Schema (org.h2.schema.Schema)10 TruncateTable (org.h2.command.ddl.TruncateTable)9