Search in sources :

Example 31 with Expression

use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.

the class SelectExecutor method addGroupSortedRow.

private void addGroupSortedRow(Value[] keyValues, int columnCount, ResultTarget result) {
    Value[] row = new Value[columnCount];
    for (int j = 0; groupIndex != null && j < groupIndex.length; j++) {
        row[groupIndex[j]] = keyValues[j];
    }
    for (int j = 0; j < columnCount; j++) {
        if (groupByExpression != null && groupByExpression[j]) {
            continue;
        }
        Expression expr = expressions.get(j);
        row[j] = expr.getValue(session);
    }
    if (isHavingNullOrFalse(row)) {
        return;
    }
    row = keepOnlyDistinct(row, columnCount);
    result.addRow(row);
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value)

Example 32 with Expression

use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.

the class TransactionExecutor method executeUpdate.

@Override
public int executeUpdate() {
    int type = prepared.getType();
    switch(type) {
        case CommandInterface.SET_AUTOCOMMIT_TRUE:
            session.setAutoCommit(true);
            break;
        case CommandInterface.SET_AUTOCOMMIT_FALSE:
            session.setAutoCommit(false);
            break;
        case CommandInterface.BEGIN:
            session.begin();
            break;
        case CommandInterface.COMMIT:
            session.commit(false);
            break;
        case CommandInterface.ROLLBACK:
            session.rollback();
            break;
        case CommandInterface.SAVEPOINT:
            session.addSavepoint(prepared.getSavepointName());
            break;
        case CommandInterface.ROLLBACK_TO_SAVEPOINT:
            session.rollbackToSavepoint(prepared.getSavepointName());
            break;
        case CommandInterface.PREPARE_COMMIT:
            session.prepareCommit(prepared.getTransactionName());
            break;
        case CommandInterface.COMMIT_TRANSACTION:
            session.getUser().checkAdmin();
            session.setPreparedTransaction(prepared.getTransactionName(), true);
            break;
        case CommandInterface.ROLLBACK_TRANSACTION:
            session.getUser().checkAdmin();
            session.setPreparedTransaction(prepared.getTransactionName(), false);
            break;
        case CommandInterface.TRANSACTION_ISOLATION:
            session.getUser().checkAdmin();
            Expression expr = prepared.getExpression();
            expr = expr.optimize(session);
            session.setTransactionIsolation(expr.getValue(session).getInt());
            break;
        case CommandInterface.TRANSACTION_READONLY_FALSE:
            session.getUser().checkAdmin();
            session.setReadOnly(false);
            break;
        case CommandInterface.TRANSACTION_READONLY_TRUE:
            session.getUser().checkAdmin();
            session.setReadOnly(true);
            break;
        default:
            DbException.throwInternalError("type=" + type);
    }
    return 0;
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression)

Example 33 with Expression

use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.

the class UpdateExecutor method executeUpdate.

@Override
public int executeUpdate() {
    TableFilter tableFilter = prepared.getTableFilter();
    TableMate table = castTableMate(tableFilter.getTable());
    List<Column> columns = prepared.getColumns();
    Map<Column, Expression> valueMap = prepared.getExpressionMap();
    table.check();
    session.getUser().checkRight(table, Right.UPDATE);
    Row updateRow = table.getTemplateRow();
    for (int i = 0, size = columns.size(); i < size; i++) {
        Column c = columns.get(i);
        Expression e = valueMap.get(c);
        int index = c.getColumnId();
        if (e != null) {
            // e can be null (DEFAULT)
            e = e.optimize(session);
            try {
                Value v = c.convert(e.getValue(session));
                updateRow.setValue(index, v);
            } catch (DbException ex) {
                ex.addSQL("evaluate expression " + e.getSQL());
                throw ex;
            }
        }
    }
    return updateRow(table, updateRow, tableFilter.getIndexConditions());
}
Also used : TableFilter(com.wplatform.ddal.dbobject.table.TableFilter) Column(com.wplatform.ddal.dbobject.table.Column) Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value) TableMate(com.wplatform.ddal.dbobject.table.TableMate) Row(com.wplatform.ddal.result.Row) SearchRow(com.wplatform.ddal.result.SearchRow) DbException(com.wplatform.ddal.message.DbException)

Example 34 with Expression

use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.

the class TableFilter method setEvaluatable.

private void setEvaluatable(TableFilter join) {
    if (session.getDatabase().getSettings().nestedJoins) {
        setEvaluatable(true);
        return;
    }
    // this table filter is now evaluatable - in all sub-joins
    do {
        Expression e = join.getJoinCondition();
        if (e != null) {
            e.setEvaluatable(this, true);
        }
        TableFilter n = join.getNestedJoin();
        if (n != null) {
            setEvaluatable(n);
        }
        join = join.getJoin();
    } while (join != null);
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression)

Example 35 with Expression

use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.

the class DeleteExecutor method doTranslate.

@Override
protected List<Value> doTranslate(TableNode node, SearchRow row, StatementBuilder buff) {
    ArrayList<Value> params = New.arrayList();
    TableFilter tableFilter = prepared.getTableFilter();
    String forTable = node.getCompositeObjectName();
    Expression condition = prepared.getCondition();
    Expression limitExpr = prepared.getLimitExpr();
    buff.append("DELETE FROM ");
    buff.append(identifier(forTable));
    if (condition != null) {
        condition.exportParameters(tableFilter, params);
        buff.append(" WHERE ").append(StringUtils.unEnclose(condition.getSQL()));
    }
    if (limitExpr != null) {
        limitExpr.exportParameters(tableFilter, params);
        buff.append(" LIMIT ").append(StringUtils.unEnclose(limitExpr.getSQL()));
    }
    return params;
}
Also used : TableFilter(com.wplatform.ddal.dbobject.table.TableFilter) Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value)

Aggregations

Expression (com.wplatform.ddal.command.expression.Expression)40 Column (com.wplatform.ddal.dbobject.table.Column)15 Value (com.wplatform.ddal.value.Value)14 StatementBuilder (com.wplatform.ddal.util.StatementBuilder)9 Row (com.wplatform.ddal.result.Row)5 TableFilter (com.wplatform.ddal.dbobject.table.TableFilter)4 TableMate (com.wplatform.ddal.dbobject.table.TableMate)4 DbException (com.wplatform.ddal.message.DbException)4 SearchRow (com.wplatform.ddal.result.SearchRow)4 Query (com.wplatform.ddal.command.dml.Query)3 ExpressionColumn (com.wplatform.ddal.command.expression.ExpressionColumn)3 ValueExpression (com.wplatform.ddal.command.expression.ValueExpression)3 Database (com.wplatform.ddal.engine.Database)3 ResultInterface (com.wplatform.ddal.result.ResultInterface)3 Parameter (com.wplatform.ddal.command.expression.Parameter)2 Index (com.wplatform.ddal.dbobject.index.Index)2 LocalResult (com.wplatform.ddal.result.LocalResult)2 Prepared (com.wplatform.ddal.command.Prepared)1 AlterTableAddConstraint (com.wplatform.ddal.command.ddl.AlterTableAddConstraint)1 SelectOrderBy (com.wplatform.ddal.command.dml.SelectOrderBy)1