Search in sources :

Example 6 with Parameter

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

the class MergeExecutor method merge.

private void merge(Row row) {
    TableMate table = castTableMate(prepared.getTable());
    Prepared update = prepared.getUpdate();
    Column[] columns = prepared.getColumns();
    Column[] keys = prepared.getKeys();
    ArrayList<Parameter> k = update.getParameters();
    for (int i = 0; i < columns.length; i++) {
        Column col = columns[i];
        Value v = row.getValue(col.getColumnId());
        Parameter p = k.get(i);
        p.setValue(v);
    }
    for (int i = 0; i < keys.length; i++) {
        Column col = keys[i];
        Value v = row.getValue(col.getColumnId());
        if (v == null) {
            throw DbException.get(ErrorCode.COLUMN_CONTAINS_NULL_VALUES_1, col.getSQL());
        }
        Parameter p = k.get(columns.length + i);
        p.setValue(v);
    }
    int count = update.update();
    if (count == 0) {
        try {
            table.validateConvertUpdateSequence(session, row);
            updateRow(table, row);
        } catch (DbException e) {
            throw e;
        }
    } else if (count != 1) {
        throw DbException.get(ErrorCode.DUPLICATE_KEY_1, table.getSQL());
    }
}
Also used : Column(com.wplatform.ddal.dbobject.table.Column) Prepared(com.wplatform.ddal.command.Prepared) Value(com.wplatform.ddal.value.Value) Parameter(com.wplatform.ddal.command.expression.Parameter) TableMate(com.wplatform.ddal.dbobject.table.TableMate) DbException(com.wplatform.ddal.message.DbException)

Example 7 with Parameter

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

the class ReplaceExecutor method update.

private int update(Row row) {
    Prepared update = prepared.getUpdate();
    Column[] columns = prepared.getColumns();
    Column[] keys = prepared.getKeys();
    // the statement degenerates to an INSERT
    if (update == null) {
        return 0;
    }
    ArrayList<Parameter> k = update.getParameters();
    for (int i = 0; i < columns.length; i++) {
        Column col = columns[i];
        Value v = row.getValue(col.getColumnId());
        Parameter p = k.get(i);
        p.setValue(v);
    }
    for (int i = 0; i < keys.length; i++) {
        Column col = keys[i];
        Value v = row.getValue(col.getColumnId());
        if (v == null) {
            throw DbException.get(ErrorCode.COLUMN_CONTAINS_NULL_VALUES_1, col.getSQL());
        }
        Parameter p = k.get(columns.length + i);
        p.setValue(v);
    }
    return update.update();
}
Also used : Column(com.wplatform.ddal.dbobject.table.Column) Prepared(com.wplatform.ddal.command.Prepared) Value(com.wplatform.ddal.value.Value) Parameter(com.wplatform.ddal.command.expression.Parameter)

Example 8 with Parameter

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

the class Update method setAssignment.

/**
 * Add an assignment of the form column = expression.
 *
 * @param column     the column
 * @param expression the expression
 */
public void setAssignment(Column column, Expression expression) {
    if (expressionMap.containsKey(column)) {
        throw DbException.get(ErrorCode.DUPLICATE_COLUMN_NAME_1, column.getName());
    }
    columns.add(column);
    expressionMap.put(column, expression);
    if (expression instanceof Parameter) {
        Parameter p = (Parameter) expression;
        p.setColumn(column);
    }
}
Also used : Parameter(com.wplatform.ddal.command.expression.Parameter)

Aggregations

Parameter (com.wplatform.ddal.command.expression.Parameter)8 Value (com.wplatform.ddal.value.Value)4 Prepared (com.wplatform.ddal.command.Prepared)3 Expression (com.wplatform.ddal.command.expression.Expression)2 Column (com.wplatform.ddal.dbobject.table.Column)2 TableMate (com.wplatform.ddal.dbobject.table.TableMate)1 TableNode (com.wplatform.ddal.dispatch.rule.TableNode)1 JdbcWorker (com.wplatform.ddal.excutor.JdbcWorker)1 DbException (com.wplatform.ddal.message.DbException)1