Search in sources :

Example 1 with RowList

use of com.wplatform.ddal.result.RowList 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();
    }
}
Also used : RowList(com.wplatform.ddal.result.RowList) Table(com.wplatform.ddal.dbobject.table.Table) Column(com.wplatform.ddal.dbobject.table.Column) ValueExpression(com.wplatform.ddal.command.expression.ValueExpression) Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value) Row(com.wplatform.ddal.result.Row)

Aggregations

Expression (com.wplatform.ddal.command.expression.Expression)1 ValueExpression (com.wplatform.ddal.command.expression.ValueExpression)1 Column (com.wplatform.ddal.dbobject.table.Column)1 Table (com.wplatform.ddal.dbobject.table.Table)1 Row (com.wplatform.ddal.result.Row)1 RowList (com.wplatform.ddal.result.RowList)1 Value (com.wplatform.ddal.value.Value)1