Search in sources :

Example 71 with Command

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

the class Session method prepareLocal.

/**
 * Parse and prepare the given SQL statement.
 * This method also checks if the connection has been closed.
 *
 * @param sql the SQL statement
 * @return the prepared statement
 */
public Command prepareLocal(String sql) {
    if (closed) {
        throw DbException.get(ErrorCode.CONNECTION_BROKEN_1, "session closed");
    }
    Command command;
    if (queryCacheSize > 0) {
        if (queryCache == null) {
            queryCache = SmallLRUCache.newInstance(queryCacheSize);
            modificationMetaID = database.getModificationMetaId();
        } else {
            long newModificationMetaID = database.getModificationMetaId();
            if (newModificationMetaID != modificationMetaID) {
                queryCache.clear();
                modificationMetaID = newModificationMetaID;
            }
            command = queryCache.get(sql);
            if (command != null && command.canReuse()) {
                command.reuse();
                return command;
            }
        }
    }
    Parser parser = new Parser(this);
    try {
        command = parser.prepareCommand(sql);
    } finally {
        // we can't reuse sub-query indexes, so just drop the whole cache
        subQueryIndexCache = null;
    }
    command.prepareJoinBatch();
    if (queryCache != null) {
        if (command.isCacheable()) {
            queryCache.put(sql, command);
        }
    }
    return command;
}
Also used : Command(org.h2.command.Command) Parser(org.h2.command.Parser)

Example 72 with Command

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

the class MetaRecord method execute.

/**
 * Execute the meta data statement.
 *
 * @param db the database
 * @param systemSession the system session
 * @param listener the database event listener
 */
void execute(Database db, Session systemSession, DatabaseEventListener listener) {
    try {
        Prepared command = systemSession.prepare(sql);
        command.setObjectId(id);
        command.update();
    } catch (DbException e) {
        e = e.addSQL(sql);
        SQLException s = e.getSQLException();
        db.getTrace(Trace.DATABASE).error(s, sql);
        if (listener != null) {
            listener.exceptionThrown(s, sql);
        // continue startup in this case
        } else {
            throw e;
        }
    }
}
Also used : SQLException(java.sql.SQLException) Prepared(org.h2.command.Prepared) DbException(org.h2.message.DbException)

Example 73 with Command

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

the class TcpServerThread method closeSession.

private void closeSession() {
    if (session != null) {
        RuntimeException closeError = null;
        try {
            Command rollback = session.prepareLocal("ROLLBACK");
            rollback.executeUpdate(false);
        } catch (RuntimeException e) {
            closeError = e;
            server.traceError(e);
        } catch (Exception e) {
            server.traceError(e);
        }
        try {
            session.close();
            server.removeConnection(threadId);
        } catch (RuntimeException e) {
            if (closeError == null) {
                closeError = e;
                server.traceError(e);
            }
        } catch (Exception e) {
            server.traceError(e);
        } finally {
            session = null;
        }
        if (closeError != null) {
            throw closeError;
        }
    }
}
Also used : Command(org.h2.command.Command) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException) IOException(java.io.IOException) JdbcSQLException(org.h2.jdbc.JdbcSQLException)

Example 74 with Command

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

the class TcpServerThread method setParameters.

private void setParameters(Command command) throws IOException {
    int len = transfer.readInt();
    ArrayList<? extends ParameterInterface> params = command.getParameters();
    for (int i = 0; i < len; i++) {
        Parameter p = (Parameter) params.get(i);
        p.setValue(transfer.readValue());
    }
}
Also used : Parameter(org.h2.expression.Parameter)

Example 75 with Command

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

the class Parser method parseUpdate.

private Update parseUpdate() {
    Update command = new Update(session);
    currentPrepared = command;
    int start = lastParseIndex;
    TableFilter filter = readSimpleTableFilter(0, null);
    command.setTableFilter(filter);
    parseUpdateSetClause(command, filter, start);
    return command;
}
Also used : TableFilter(org.h2.table.TableFilter) Update(org.h2.command.dml.Update) AlterTableRenameConstraint(org.h2.command.ddl.AlterTableRenameConstraint) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint)

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