use of com.wplatform.ddal.command.expression.Parameter in project jdbc-shards by wplatform.
the class ExecuteProcedure method setParameters.
private void setParameters() {
Prepared prepared = procedure.getPrepared();
ArrayList<Parameter> params = prepared.getParameters();
for (int i = 0; params != null && i < params.size() && i < expressions.size(); i++) {
Expression expr = expressions.get(i);
Parameter p = params.get(i);
p.setValue(expr.getValue(session));
}
}
use of com.wplatform.ddal.command.expression.Parameter in project jdbc-shards by wplatform.
the class Insert method prepare.
@Override
public void prepare() {
if (columns == null) {
if (list.size() > 0 && list.get(0).length == 0) {
// special case where table is used as a sequence
columns = new Column[0];
} else {
columns = table.getColumns();
}
}
if (list.size() > 0) {
for (Expression[] expr : list) {
if (expr.length != columns.length) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
}
for (int i = 0, len = expr.length; i < len; i++) {
Expression e = expr[i];
if (e != null) {
e = e.optimize(session);
if (e instanceof Parameter) {
Parameter p = (Parameter) e;
p.setColumn(columns[i]);
}
expr[i] = e;
}
}
}
} else {
query.prepare();
if (query.getColumnCount() != columns.length) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
}
}
}
use of com.wplatform.ddal.command.expression.Parameter in project jdbc-shards by wplatform.
the class CommandContainer method recompileIfRequired.
private void recompileIfRequired() {
if (prepared.needRecompile()) {
// TODO test with 'always recompile'
String sql = prepared.getSQL();
ArrayList<Parameter> oldParams = prepared.getParameters();
Parser parser = new Parser(session);
prepared = parser.parse(sql);
ArrayList<Parameter> newParams = prepared.getParameters();
for (int i = 0, size = newParams.size(); i < size; i++) {
Parameter old = oldParams.get(i);
if (old.isValueSet()) {
Value v = old.getValue(session);
Parameter p = newParams.get(i);
p.setValue(v);
}
}
prepared.prepare();
}
}
use of com.wplatform.ddal.command.expression.Parameter in project jdbc-shards by wplatform.
the class MergeExecutor method merge.
private void merge(Row row) {
TableMate table = castTableMate(prepared.getTable());
Prepared update = prepared.getUpdate();
Column[] columns = prepared.getColumns();
Column[] keys = prepared.getKeys();
ArrayList<Parameter> k = update.getParameters();
for (int i = 0; i < columns.length; i++) {
Column col = columns[i];
Value v = row.getValue(col.getColumnId());
Parameter p = k.get(i);
p.setValue(v);
}
for (int i = 0; i < keys.length; i++) {
Column col = keys[i];
Value v = row.getValue(col.getColumnId());
if (v == null) {
throw DbException.get(ErrorCode.COLUMN_CONTAINS_NULL_VALUES_1, col.getSQL());
}
Parameter p = k.get(columns.length + i);
p.setValue(v);
}
int count = update.update();
if (count == 0) {
try {
table.validateConvertUpdateSequence(session, row);
updateRow(table, row);
} catch (DbException e) {
throw e;
}
} else if (count != 1) {
throw DbException.get(ErrorCode.DUPLICATE_KEY_1, table.getSQL());
}
}
use of com.wplatform.ddal.command.expression.Parameter 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();
}
}
}
Aggregations