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());
}
}
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();
}
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);
}
}
Aggregations