use of com.wplatform.ddal.message.DbException in project jdbc-shards by wplatform.
the class FunctionAlias method loadFromSource.
private void loadFromSource() {
SourceCompiler compiler = database.getCompiler();
synchronized (compiler) {
String fullClassName = Constants.USER_PACKAGE + "." + getName();
compiler.setSource(fullClassName, source);
try {
Method m = compiler.getMethod(fullClassName);
JavaMethod method = new JavaMethod(m, 0);
javaMethods = new JavaMethod[] { method };
} catch (DbException e) {
throw e;
} catch (Exception e) {
throw DbException.get(ErrorCode.SYNTAX_ERROR_1, e, source);
}
}
}
use of com.wplatform.ddal.message.DbException in project jdbc-shards by wplatform.
the class ReplaceExecutor method replace.
private void replace(Row row) {
TableMate table = castTableMate(prepared.getTable());
int count = update(row);
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.message.DbException 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);
}
use of com.wplatform.ddal.message.DbException in project jdbc-shards by wplatform.
the class InsertExecutor method executeUpdate.
@Override
public int executeUpdate() {
TableMate table = castTableMate(prepared.getTable());
table.check();
session.getUser().checkRight(table, Right.INSERT);
prepared.setCurrentRowNumber(0);
rowNumber = 0;
affectRows = 0;
ArrayList<Expression[]> list = prepared.getList();
Column[] columns = prepared.getColumns();
int listSize = list.size();
if (listSize > 0) {
int columnLen = columns.length;
for (int x = 0; x < listSize; x++) {
Row newRow = table.getTemplateRow();
Expression[] expr = list.get(x);
prepared.setCurrentRowNumber(x + 1);
for (int i = 0; i < columnLen; i++) {
Column c = columns[i];
int index = c.getColumnId();
Expression e = expr[i];
if (e != null) {
// e can be null (DEFAULT)
e = e.optimize(session);
try {
Value v = c.convert(e.getValue(session));
newRow.setValue(index, v);
} catch (DbException ex) {
throw prepared.setRow(ex, x, Prepared.getSQL(expr));
}
}
}
rowNumber++;
table.validateConvertUpdateSequence(session, newRow);
addNewRow(newRow);
}
} else {
Query query = prepared.getQuery();
if (prepared.isInsertFromSelect()) {
query.query(0, this);
} else {
ResultInterface rows = query.query(0);
while (rows.next()) {
Value[] r = rows.currentRow();
addRow(r);
}
rows.close();
}
}
flushNewRows();
return affectRows;
}
use of com.wplatform.ddal.message.DbException 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());
}
}
Aggregations