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);
}
}
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;
}
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();
}
}
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;
}
}
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;
}
Aggregations