use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.
the class SelectExecutor method addGroupSortedRow.
private void addGroupSortedRow(Value[] keyValues, int columnCount, ResultTarget result) {
Value[] row = new Value[columnCount];
for (int j = 0; groupIndex != null && j < groupIndex.length; j++) {
row[groupIndex[j]] = keyValues[j];
}
for (int j = 0; j < columnCount; j++) {
if (groupByExpression != null && groupByExpression[j]) {
continue;
}
Expression expr = expressions.get(j);
row[j] = expr.getValue(session);
}
if (isHavingNullOrFalse(row)) {
return;
}
row = keepOnlyDistinct(row, columnCount);
result.addRow(row);
}
use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.
the class TransactionExecutor method executeUpdate.
@Override
public int executeUpdate() {
int type = prepared.getType();
switch(type) {
case CommandInterface.SET_AUTOCOMMIT_TRUE:
session.setAutoCommit(true);
break;
case CommandInterface.SET_AUTOCOMMIT_FALSE:
session.setAutoCommit(false);
break;
case CommandInterface.BEGIN:
session.begin();
break;
case CommandInterface.COMMIT:
session.commit(false);
break;
case CommandInterface.ROLLBACK:
session.rollback();
break;
case CommandInterface.SAVEPOINT:
session.addSavepoint(prepared.getSavepointName());
break;
case CommandInterface.ROLLBACK_TO_SAVEPOINT:
session.rollbackToSavepoint(prepared.getSavepointName());
break;
case CommandInterface.PREPARE_COMMIT:
session.prepareCommit(prepared.getTransactionName());
break;
case CommandInterface.COMMIT_TRANSACTION:
session.getUser().checkAdmin();
session.setPreparedTransaction(prepared.getTransactionName(), true);
break;
case CommandInterface.ROLLBACK_TRANSACTION:
session.getUser().checkAdmin();
session.setPreparedTransaction(prepared.getTransactionName(), false);
break;
case CommandInterface.TRANSACTION_ISOLATION:
session.getUser().checkAdmin();
Expression expr = prepared.getExpression();
expr = expr.optimize(session);
session.setTransactionIsolation(expr.getValue(session).getInt());
break;
case CommandInterface.TRANSACTION_READONLY_FALSE:
session.getUser().checkAdmin();
session.setReadOnly(false);
break;
case CommandInterface.TRANSACTION_READONLY_TRUE:
session.getUser().checkAdmin();
session.setReadOnly(true);
break;
default:
DbException.throwInternalError("type=" + type);
}
return 0;
}
use of com.wplatform.ddal.command.expression.Expression 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.command.expression.Expression in project jdbc-shards by wplatform.
the class TableFilter method setEvaluatable.
private void setEvaluatable(TableFilter join) {
if (session.getDatabase().getSettings().nestedJoins) {
setEvaluatable(true);
return;
}
// this table filter is now evaluatable - in all sub-joins
do {
Expression e = join.getJoinCondition();
if (e != null) {
e.setEvaluatable(this, true);
}
TableFilter n = join.getNestedJoin();
if (n != null) {
setEvaluatable(n);
}
join = join.getJoin();
} while (join != null);
}
use of com.wplatform.ddal.command.expression.Expression in project jdbc-shards by wplatform.
the class DeleteExecutor method doTranslate.
@Override
protected List<Value> doTranslate(TableNode node, SearchRow row, StatementBuilder buff) {
ArrayList<Value> params = New.arrayList();
TableFilter tableFilter = prepared.getTableFilter();
String forTable = node.getCompositeObjectName();
Expression condition = prepared.getCondition();
Expression limitExpr = prepared.getLimitExpr();
buff.append("DELETE FROM ");
buff.append(identifier(forTable));
if (condition != null) {
condition.exportParameters(tableFilter, params);
buff.append(" WHERE ").append(StringUtils.unEnclose(condition.getSQL()));
}
if (limitExpr != null) {
limitExpr.exportParameters(tableFilter, params);
buff.append(" LIMIT ").append(StringUtils.unEnclose(limitExpr.getSQL()));
}
return params;
}
Aggregations