Search in sources :

Example 6 with ResultInterface

use of com.wplatform.ddal.result.ResultInterface in project jdbc-shards by wplatform.

the class JdbcConnection method getCatalog.

/**
     * Gets the current catalog name.
     *
     * @return the catalog name
     * @throws SQLException if the connection is closed
     */
@Override
public String getCatalog() throws SQLException {
    try {
        debugCodeCall("getCatalog");
        checkClosed();
        if (catalog == null) {
            CommandInterface cat = prepareCommand("CALL DATABASE()", Integer.MAX_VALUE);
            ResultInterface result = cat.executeQuery(0, false);
            result.next();
            catalog = result.currentRow()[0].getString();
            cat.close();
        }
        return catalog;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) CommandInterface(com.wplatform.ddal.command.CommandInterface) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) DbException(com.wplatform.ddal.message.DbException)

Example 7 with ResultInterface

use of com.wplatform.ddal.result.ResultInterface in project jdbc-shards by wplatform.

the class JdbcConnection method getGeneratedKeys.

/**
     * INTERNAL
     */
ResultSet getGeneratedKeys(JdbcStatement stat, int id) {
    getGeneratedKeys = prepareCommand("SELECT SCOPE_IDENTITY() " + "WHERE SCOPE_IDENTITY() IS NOT NULL", getGeneratedKeys);
    ResultInterface result = getGeneratedKeys.executeQuery(0, false);
    ResultSet rs = new JdbcResultSet(this, stat, result, id, false, true, false);
    return rs;
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) ResultSet(java.sql.ResultSet)

Example 8 with ResultInterface

use of com.wplatform.ddal.result.ResultInterface in project jdbc-shards by wplatform.

the class Subquery method getValue.

@Override
public Value getValue(Session session) {
    query.setSession(session);
    ResultInterface result = query.query(2);
    try {
        int rowcount = result.getRowCount();
        if (rowcount > 1) {
            throw DbException.get(ErrorCode.SCALAR_SUBQUERY_CONTAINS_MORE_THAN_ONE_ROW);
        }
        Value v;
        if (rowcount <= 0) {
            v = ValueNull.INSTANCE;
        } else {
            result.next();
            Value[] values = result.currentRow();
            if (result.getVisibleColumnCount() == 1) {
                v = values[0];
            } else {
                v = ValueArray.get(values);
            }
        }
        return v;
    } finally {
        result.close();
    }
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) Value(com.wplatform.ddal.value.Value)

Example 9 with ResultInterface

use of com.wplatform.ddal.result.ResultInterface in project jdbc-shards by wplatform.

the class RoutingHandlerImpl method doRoute.

@Override
public RoutingResult doRoute(TableMate table, Session session, List<IndexCondition> indexConditions) {
    TableRouter tr = table.getTableRouter();
    if (tr == null) {
        return fixedRoutingResult(table.getShards());
    } else {
        Map<String, List<Value>> routingArgs = New.hashMap();
        List<RuleColumn> ruleCols = tr.getRuleColumns();
        SearchRow start = null, end = null;
        for (IndexCondition condition : indexConditions) {
            Column column = condition.getColumn();
            String colName = column.getName();
            RuleColumn matched = null;
            for (RuleColumn ruleColumn : ruleCols) {
                if (colName.equalsIgnoreCase(ruleColumn.getName())) {
                    matched = ruleColumn;
                }
            }
            if (matched == null) {
                continue;
            }
            List<Value> values = routingArgs.get(matched.getName());
            if (values == null) {
                values = New.arrayList();
                routingArgs.put(matched.getName(), values);
            }
            if (condition.getCompareType() == Comparison.IN_LIST) {
                Value[] inList = condition.getCurrentValueList(session);
                for (Value value : inList) {
                    values.add(value);
                }
            } else if (condition.getCompareType() == Comparison.IN_QUERY) {
                ResultInterface result = condition.getCurrentResult();
                while (result.next()) {
                    Value v = result.currentRow()[0];
                    if (v != ValueNull.INSTANCE) {
                        v = column.convert(v);
                        values.add(v);
                    }
                }
            } else {
                int columnId = column.getColumnId();
                Value v = condition.getCurrentValue(session);
                boolean isStart = condition.isStart();
                boolean isEnd = condition.isEnd();
                if (isStart) {
                    start = getSearchRow(table, session, start, columnId, v, true);
                }
                if (isEnd) {
                    end = getSearchRow(table, session, end, columnId, v, false);
                }
            }
        }
        exportRangeArg(table, start, end, routingArgs);
        RoutingResult rr = trc.calculate(tr, routingArgs);
        return rr;
    }
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) Column(com.wplatform.ddal.dbobject.table.Column) Value(com.wplatform.ddal.value.Value) List(java.util.List) IndexCondition(com.wplatform.ddal.dbobject.index.IndexCondition) SearchRow(com.wplatform.ddal.result.SearchRow)

Example 10 with ResultInterface

use of com.wplatform.ddal.result.ResultInterface in project jdbc-shards by wplatform.

the class CommandContainer method query.

@Override
public ResultInterface query(int maxrows) {
    recompileIfRequired();
    start();
    prepared.checkParameters();
    ResultInterface result = prepared.query(maxrows);
    prepared.trace(startTime, result.getRowCount());
    return result;
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface)

Aggregations

ResultInterface (com.wplatform.ddal.result.ResultInterface)15 DbException (com.wplatform.ddal.message.DbException)9 Value (com.wplatform.ddal.value.Value)5 Column (com.wplatform.ddal.dbobject.table.Column)4 SearchRow (com.wplatform.ddal.result.SearchRow)4 CommandInterface (com.wplatform.ddal.command.CommandInterface)3 Query (com.wplatform.ddal.command.dml.Query)3 Expression (com.wplatform.ddal.command.expression.Expression)3 TableMate (com.wplatform.ddal.dbobject.table.TableMate)3 Row (com.wplatform.ddal.result.Row)3 SQLClientInfoException (java.sql.SQLClientInfoException)2 SQLException (java.sql.SQLException)2 IndexCondition (com.wplatform.ddal.dbobject.index.IndexCondition)1 ResultSet (java.sql.ResultSet)1 Savepoint (java.sql.Savepoint)1 List (java.util.List)1