Search in sources :

Example 1 with Prepared

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

the class ExecuteProcedure method setParameters.

private void setParameters() {
    Prepared prepared = procedure.getPrepared();
    ArrayList<Parameter> params = prepared.getParameters();
    for (int i = 0; params != null && i < params.size() && i < expressions.size(); i++) {
        Expression expr = expressions.get(i);
        Parameter p = params.get(i);
        p.setValue(expr.getValue(session));
    }
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression) Prepared(com.wplatform.ddal.command.Prepared) Parameter(com.wplatform.ddal.command.expression.Parameter)

Example 2 with Prepared

use of com.wplatform.ddal.command.Prepared 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 3 with Prepared

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

the class ExecuteProcedure method query.

@Override
public ResultInterface query(int limit) {
    setParameters();
    Prepared prepared = procedure.getPrepared();
    return prepared.query(limit);
}
Also used : Prepared(com.wplatform.ddal.command.Prepared)

Example 4 with Prepared

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

the class ExecuteProcedure method update.

@Override
public int update() {
    setParameters();
    Prepared prepared = procedure.getPrepared();
    return prepared.update();
}
Also used : Prepared(com.wplatform.ddal.command.Prepared)

Example 5 with Prepared

use of com.wplatform.ddal.command.Prepared 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)

Aggregations

Prepared (com.wplatform.ddal.command.Prepared)5 Parameter (com.wplatform.ddal.command.expression.Parameter)3 Column (com.wplatform.ddal.dbobject.table.Column)2 Value (com.wplatform.ddal.value.Value)2 Expression (com.wplatform.ddal.command.expression.Expression)1 TableMate (com.wplatform.ddal.dbobject.table.TableMate)1 DbException (com.wplatform.ddal.message.DbException)1