Search in sources :

Example 26 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class FunctionTable method getValueResultSet.

private ValueResultSet getValueResultSet(Session session) {
    functionExpr = functionExpr.optimize(session);
    Value v = functionExpr.getValue(session);
    if (v == ValueNull.INSTANCE) {
        return null;
    }
    return (ValueResultSet) v;
}
Also used : ValueResultSet(com.wplatform.ddal.value.ValueResultSet) Value(com.wplatform.ddal.value.Value)

Example 27 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class Table method validateConvertUpdateSequence.

/**
     * Validate all values in this row, convert the values if required, and
     * update the sequence values if required. This call will also set the
     * default values if required and set the computed column if there are any.
     *
     * @param session the session
     * @param row the row
     */
public void validateConvertUpdateSequence(Session session, Row row) {
    for (int i = 0; i < columns.length; i++) {
        Value value = row.getValue(i);
        Column column = columns[i];
        Value v2;
        if (column.getComputed()) {
            // force updating the value
            value = null;
            v2 = column.computeValue(session, row);
        }
        v2 = column.validateConvertUpdateSequence(session, value);
        if (v2 != value) {
            row.setValue(i, v2);
        }
    }
}
Also used : SimpleRowValue(com.wplatform.ddal.result.SimpleRowValue) Value(com.wplatform.ddal.value.Value)

Example 28 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class Table method getDefaultValue.

/**
     * Get or generate a default value for the given column.
     *
     * @param session the session
     * @param column the column
     * @return the value
     */
public Value getDefaultValue(Session session, Column column) {
    Expression defaultExpr = column.getDefaultExpression();
    Value v;
    if (defaultExpr == null) {
        v = column.validateConvertUpdateSequence(session, null);
    } else {
        v = defaultExpr.getValue(session);
    }
    return column.convert(v);
}
Also used : Expression(com.wplatform.ddal.command.expression.Expression) SimpleRowValue(com.wplatform.ddal.result.SimpleRowValue) Value(com.wplatform.ddal.value.Value)

Example 29 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class JdbcCallWorker method doWork.

@Override
public Integer doWork() {
    Connection conn = null;
    PreparedStatement stmt = null;
    try {
        DataSource dataSource = getDataSource();
        Optional optional = Optional.build().shardName(shardName).readOnly(false);
        if (trace.isDebugEnabled()) {
            trace.debug("{0} Fetching connection from DataSource.", shardName);
        }
        conn = session.applyConnection(dataSource, optional);
        attach(conn);
        if (trace.isDebugEnabled()) {
            trace.debug("{0} Preparing: {1};", shardName, sql);
        }
        stmt = conn.prepareStatement(sql);
        attach(stmt);
        applyQueryTimeout(stmt);
        if (params != null) {
            for (int i = 0, size = params.size(); i < size; i++) {
                Value v = params.get(i);
                v.set(stmt, i + 1);
                if (trace.isDebugEnabled()) {
                    trace.debug("{0} setParameter: {1} -> {2};", shardName, i + 1, v.getSQL());
                }
            }
        }
        int rows = stmt.executeUpdate();
        if (trace.isDebugEnabled()) {
            trace.debug("{0} executeUpdate: {1} affected.", shardName, rows);
        }
        return rows;
    } catch (SQLException e) {
        StatementBuilder buff = new StatementBuilder();
        buff.append(shardName).append(" executing executeUpdate error:").append(sql);
        if (params != null && params.size() > 0) {
            buff.append("\n{");
            int i = 1;
            for (Value v : params) {
                buff.appendExceptFirst(", ");
                buff.append(i++).append(": ").append(v.getSQL());
            }
            buff.append('}');
        }
        buff.append(';');
        trace.error(e, buff.toString());
        throw wrapException(sql, e);
    }
}
Also used : Optional(com.wplatform.ddal.excutor.Optional) SQLException(java.sql.SQLException) StatementBuilder(com.wplatform.ddal.util.StatementBuilder) Connection(java.sql.Connection) Value(com.wplatform.ddal.value.Value) PreparedStatement(java.sql.PreparedStatement) DataSource(javax.sql.DataSource)

Example 30 with Value

use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.

the class JdbcUpdateWorker method doWork.

@Override
public Integer doWork() {
    Connection conn = null;
    PreparedStatement stmt = null;
    try {
        DataSource dataSource = getDataSource();
        Optional optional = Optional.build().shardName(shardName).readOnly(false);
        if (trace.isDebugEnabled()) {
            trace.debug("{0} Fetching connection from DataSource.", shardName);
        }
        conn = session.applyConnection(dataSource, optional);
        attach(conn);
        if (trace.isDebugEnabled()) {
            trace.debug("{0} Preparing call: {1};", shardName, sql);
        }
        stmt = conn.prepareCall(sql);
        attach(stmt);
        applyQueryTimeout(stmt);
        if (params != null) {
            for (int i = 0, size = params.size(); i < size; i++) {
                Value v = params.get(i);
                v.set(stmt, i + 1);
                if (trace.isDebugEnabled()) {
                    trace.debug("{0} setParameter: {1} -> {2};", shardName, i + 1, v.getSQL());
                }
            }
        }
        int rows = stmt.executeUpdate();
        if (trace.isDebugEnabled()) {
            trace.debug("{0} executeUpdate: {1} affected.", shardName, rows);
        }
        return rows;
    } catch (SQLException e) {
        StatementBuilder buff = new StatementBuilder();
        buff.append(shardName).append(" executing executeUpdate error:").append(sql);
        if (params != null && 0 < params.size()) {
            buff.append("\n{");
            int i = 1;
            for (Value v : params) {
                buff.appendExceptFirst(", ");
                buff.append(i++).append(": ").append(v.getSQL());
            }
            buff.append('}');
        }
        buff.append(';');
        trace.error(e, buff.toString());
        throw wrapException(sql, e);
    }
}
Also used : SQLException(java.sql.SQLException) StatementBuilder(com.wplatform.ddal.util.StatementBuilder) Connection(java.sql.Connection) Value(com.wplatform.ddal.value.Value) PreparedStatement(java.sql.PreparedStatement) DataSource(javax.sql.DataSource)

Aggregations

Value (com.wplatform.ddal.value.Value)84 Expression (com.wplatform.ddal.command.expression.Expression)14 Column (com.wplatform.ddal.dbobject.table.Column)14 StatementBuilder (com.wplatform.ddal.util.StatementBuilder)13 DbException (com.wplatform.ddal.message.DbException)9 SQLException (java.sql.SQLException)8 Row (com.wplatform.ddal.result.Row)7 SearchRow (com.wplatform.ddal.result.SearchRow)7 PreparedStatement (java.sql.PreparedStatement)7 TableMate (com.wplatform.ddal.dbobject.table.TableMate)6 LocalResult (com.wplatform.ddal.result.LocalResult)6 ResultInterface (com.wplatform.ddal.result.ResultInterface)5 Connection (java.sql.Connection)5 Parameter (com.wplatform.ddal.command.expression.Parameter)4 List (java.util.List)4 DataSource (javax.sql.DataSource)4 Query (com.wplatform.ddal.command.dml.Query)3 TableFilter (com.wplatform.ddal.dbobject.table.TableFilter)3 TableNode (com.wplatform.ddal.dispatch.rule.TableNode)3 JdbcWorker (com.wplatform.ddal.excutor.JdbcWorker)3