Search in sources :

Example 1 with DbException

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);
        }
    }
}
Also used : Method(java.lang.reflect.Method) DbException(com.wplatform.ddal.message.DbException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SourceCompiler(com.wplatform.ddal.util.SourceCompiler) DbException(com.wplatform.ddal.message.DbException)

Example 2 with DbException

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());
    }
}
Also used : TableMate(com.wplatform.ddal.dbobject.table.TableMate) DbException(com.wplatform.ddal.message.DbException)

Example 3 with DbException

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);
}
Also used : Column(com.wplatform.ddal.dbobject.table.Column) Value(com.wplatform.ddal.value.Value) TableMate(com.wplatform.ddal.dbobject.table.TableMate) Row(com.wplatform.ddal.result.Row) SearchRow(com.wplatform.ddal.result.SearchRow) DbException(com.wplatform.ddal.message.DbException)

Example 4 with DbException

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;
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) Query(com.wplatform.ddal.command.dml.Query) DbException(com.wplatform.ddal.message.DbException) Column(com.wplatform.ddal.dbobject.table.Column) Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value) TableMate(com.wplatform.ddal.dbobject.table.TableMate) Row(com.wplatform.ddal.result.Row) SearchRow(com.wplatform.ddal.result.SearchRow)

Example 5 with DbException

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());
    }
}
Also used : Column(com.wplatform.ddal.dbobject.table.Column) Prepared(com.wplatform.ddal.command.Prepared) Value(com.wplatform.ddal.value.Value) Parameter(com.wplatform.ddal.command.expression.Parameter) TableMate(com.wplatform.ddal.dbobject.table.TableMate) DbException(com.wplatform.ddal.message.DbException)

Aggregations

DbException (com.wplatform.ddal.message.DbException)14 TableMate (com.wplatform.ddal.dbobject.table.TableMate)8 Column (com.wplatform.ddal.dbobject.table.Column)7 Value (com.wplatform.ddal.value.Value)6 Query (com.wplatform.ddal.command.dml.Query)5 Row (com.wplatform.ddal.result.Row)5 SearchRow (com.wplatform.ddal.result.SearchRow)5 Expression (com.wplatform.ddal.command.expression.Expression)4 ResultInterface (com.wplatform.ddal.result.ResultInterface)3 SQLException (java.sql.SQLException)3 TableNode (com.wplatform.ddal.dispatch.rule.TableNode)2 Database (com.wplatform.ddal.engine.Database)2 Prepared (com.wplatform.ddal.command.Prepared)1 AlterTableAddConstraint (com.wplatform.ddal.command.ddl.AlterTableAddConstraint)1 DefineCommand (com.wplatform.ddal.command.ddl.DefineCommand)1 Insert (com.wplatform.ddal.command.dml.Insert)1 Parameter (com.wplatform.ddal.command.expression.Parameter)1 IndexMate (com.wplatform.ddal.dbobject.index.IndexMate)1 Sequence (com.wplatform.ddal.dbobject.schema.Sequence)1 IndexColumn (com.wplatform.ddal.dbobject.table.IndexColumn)1