use of com.wplatform.ddal.dbobject.table.Column 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.dbobject.table.Column 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.dbobject.table.Column in project jdbc-shards by wplatform.
the class MergeExecutor method doTranslate.
@Override
protected List<Value> doTranslate(TableNode node, SearchRow row, StatementBuilder buff) {
String forTable = node.getCompositeObjectName();
TableMate table = castTableMate(prepared.getTable());
Column[] columns = table.getColumns();
return buildInsert(forTable, columns, row, buff);
}
Aggregations