Search in sources :

Example 16 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class SelectExecutor method queryGroupSorted.

private void queryGroupSorted(int columnCount, ResultTarget result) {
    int rowNumber = 0;
    prepared.setCurrentRowNumber(0);
    prepared.setCurrentGroup(null);
    Value[] previousKeyValues = null;
    while (topTableFilter.next()) {
        //for rownum expression
        prepared.setCurrentRowNumber(rowNumber + 1);
        if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
            rowNumber++;
            Value[] keyValues = new Value[groupIndex.length];
            // update group
            for (int i = 0; i < groupIndex.length; i++) {
                int idx = groupIndex[i];
                Expression expr = expressions.get(idx);
                keyValues[i] = expr.getValue(session);
            }
            if (previousKeyValues == null) {
                previousKeyValues = keyValues;
                prepared.setCurrentGroup(New.<Expression, Object>hashMap());
            } else if (!Arrays.equals(previousKeyValues, keyValues)) {
                addGroupSortedRow(previousKeyValues, columnCount, result);
                previousKeyValues = keyValues;
                prepared.setCurrentGroup(New.<Expression, Object>hashMap());
            }
            prepared.increaseCurrentGroupRowId();
            for (int i = 0; i < columnCount; i++) {
                if (groupByExpression == null || !groupByExpression[i]) {
                    Expression expr = expressions.get(i);
                    expr.updateAggregate(session);
                }
            }
        }
    }
    if (previousKeyValues != null) {
        addGroupSortedRow(previousKeyValues, columnCount, result);
    }
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value)

Example 17 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class SelectExecutor method queryFlat.

private void queryFlat(int columnCount, ResultTarget result, long limitRows) {
    // limitRows is never 0 here
    if (limitRows > 0 && offsetExpr != null) {
        int offset = offsetExpr.getValue(session).getInt();
        if (offset > 0) {
            limitRows += offset;
        }
    }
    int rowNumber = 0;
    prepared.setCurrentRowNumber(0);
    int sampleSize = getSampleSizeValue(session);
    while (topTableFilter.next()) {
        prepared.setCurrentRowNumber(rowNumber + 1);
        if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
            Value[] row = new Value[columnCount];
            for (int i = 0; i < columnCount; i++) {
                Expression expr = expressions.get(i);
                row[i] = expr.getValue(session);
            }
            result.addRow(row);
            rowNumber++;
            if ((sort == null) && limitRows > 0 && result.getRowCount() >= limitRows) {
                break;
            }
            if (sampleSize > 0 && rowNumber >= sampleSize) {
                break;
            }
        }
    }
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value)

Example 18 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class SelectExecutor method queryGroupAccordant.

private void queryGroupAccordant(int columnCount, ResultTarget result) {
    Value[] row = new Value[columnCount];
    for (int i = 0; i < columnCount; i++) {
        Expression expr = expressions.get(i);
        row[i] = expr.getValue(session);
    }
    result.addRow(row);
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value)

Example 19 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class DefineCommandExecutor method execute.

/**
     * execute DDL use default sql translator
     * 
     * @param nodes
     */
public void execute(TableNode[] nodes) {
    session.checkCanceled();
    List<JdbcWorker<Integer>> workers = New.arrayList(nodes.length);
    for (TableNode node : nodes) {
        String sql = doTranslate(node);
        List<Parameter> items = getPrepared().getParameters();
        List<Value> params = New.arrayList(items.size());
        for (Parameter parameter : items) {
            params.add(parameter.getParamValue());
        }
        workers.add(createUpdateWorker(node.getShardName(), sql, params));
    }
    addRuningJdbcWorkers(workers);
    try {
        // DDL statement returns nothing.
        if (workers.size() > 1) {
            //MILLISECONDS
            int queryTimeout = getQueryTimeout();
            if (queryTimeout > 0) {
                jdbcExecutor.invokeAll(workers, queryTimeout, TimeUnit.MILLISECONDS);
            } else {
                jdbcExecutor.invokeAll(workers);
            }
        } else if (workers.size() == 1) {
            workers.get(0).doWork();
        }
    } catch (InterruptedException e) {
        throw DbException.convert(e);
    } finally {
        removeRuningJdbcWorkers(workers);
        for (JdbcWorker<Integer> jdbcWorker : workers) {
            jdbcWorker.closeResource();
        }
    }
}
Also used : JdbcWorker(com.wplatform.ddal.excutor.JdbcWorker) TableNode(com.wplatform.ddal.dispatch.rule.TableNode) Value(com.wplatform.ddal.value.Value) Parameter(com.wplatform.ddal.command.expression.Parameter)

Example 20 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class InsertExecutor method addRow.

@Override
public void addRow(Value[] values) {
    TableMate table = castTableMate(prepared.getTable());
    Row newRow = table.getTemplateRow();
    Column[] columns = prepared.getColumns();
    prepared.setCurrentRowNumber(++rowNumber);
    for (int j = 0, len = columns.length; j < len; j++) {
        Column c = columns[j];
        int index = c.getColumnId();
        try {
            Value v = c.convert(values[j]);
            newRow.setValue(index, v);
        } catch (DbException ex) {
            throw prepared.setRow(ex, rowNumber, Prepared.getSQL(values));
        }
    }
    table.validateConvertUpdateSequence(session, newRow);
    addNewRow(newRow);
}
Also used : Column(com.wplatform.ddal.dbobject.table.Column) Value(com.wplatform.ddal.value.Value) TableMate(com.wplatform.ddal.dbobject.table.TableMate) Row(com.wplatform.ddal.result.Row) SearchRow(com.wplatform.ddal.result.SearchRow) DbException(com.wplatform.ddal.message.DbException)

Aggregations

Value (com.wplatform.ddal.value.Value)84 Expression (com.wplatform.ddal.command.expression.Expression)14 Column (com.wplatform.ddal.dbobject.table.Column)14 StatementBuilder (com.wplatform.ddal.util.StatementBuilder)13 DbException (com.wplatform.ddal.message.DbException)9 SQLException (java.sql.SQLException)8 Row (com.wplatform.ddal.result.Row)7 SearchRow (com.wplatform.ddal.result.SearchRow)7 PreparedStatement (java.sql.PreparedStatement)7 TableMate (com.wplatform.ddal.dbobject.table.TableMate)6 LocalResult (com.wplatform.ddal.result.LocalResult)6 ResultInterface (com.wplatform.ddal.result.ResultInterface)5 Connection (java.sql.Connection)5 Parameter (com.wplatform.ddal.command.expression.Parameter)4 List (java.util.List)4 DataSource (javax.sql.DataSource)4 Query (com.wplatform.ddal.command.dml.Query)3 TableFilter (com.wplatform.ddal.dbobject.table.TableFilter)3 TableNode (com.wplatform.ddal.dispatch.rule.TableNode)3 JdbcWorker (com.wplatform.ddal.excutor.JdbcWorker)3