use of com.wplatform.ddal.result.Row 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());
}
use of com.wplatform.ddal.result.Row in project jdbc-shards by wplatform.
the class Update method updateRows.
protected int updateRows() {
tableFilter.startQuery(session);
tableFilter.reset();
RowList rows = new RowList(session);
try {
Table table = tableFilter.getTable();
session.getUser().checkRight(table, Right.UPDATE);
// table.lock(session, true, false);
int columnCount = table.getColumns().length;
// get the old rows, compute the new rows
setCurrentRowNumber(0);
int count = 0;
Column[] columns = table.getColumns();
int limitRows = -1;
if (limitExpr != null) {
Value v = limitExpr.getValue(session);
if (v != ValueNull.INSTANCE) {
limitRows = v.getInt();
}
}
while (tableFilter.next()) {
setCurrentRowNumber(count + 1);
if (limitRows >= 0 && count >= limitRows) {
break;
}
if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
Row oldRow = tableFilter.get();
Row newRow = table.getTemplateRow();
for (int i = 0; i < columnCount; i++) {
Expression newExpr = expressionMap.get(columns[i]);
Value newValue;
if (newExpr == null) {
newValue = oldRow.getValue(i);
} else if (newExpr == ValueExpression.getDefault()) {
Column column = table.getColumn(i);
newValue = table.getDefaultValue(session, column);
} else {
Column column = table.getColumn(i);
newValue = column.convert(newExpr.getValue(session));
}
newRow.setValue(i, newValue);
}
table.validateConvertUpdateSequence(session, newRow);
rows.add(oldRow);
rows.add(newRow);
count++;
}
}
// table.updateRows(this, session, rows);
return count;
} finally {
rows.close();
}
}
Aggregations