Search in sources :

Example 51 with Value

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

the class SimpleRow method toString.

@Override
public String toString() {
    StatementBuilder buff = new StatementBuilder("( /* key:");
    buff.append(getKey());
    if (version != 0) {
        buff.append(" v:" + version);
    }
    buff.append(" */ ");
    for (Value v : data) {
        buff.appendExceptFirst(", ");
        buff.append(v == null ? "null" : v.getTraceSQL());
    }
    return buff.append(')').toString();
}
Also used : StatementBuilder(com.wplatform.ddal.util.StatementBuilder) Value(com.wplatform.ddal.value.Value)

Example 52 with Value

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

the class ValueHashMap method rehash.

@Override
protected void rehash(int newLevel) {
    Value[] oldKeys = keys;
    V[] oldValues = values;
    reset(newLevel);
    int len = oldKeys.length;
    for (int i = 0; i < len; i++) {
        Value k = oldKeys[i];
        if (k != null && k != ValueNull.DELETED) {
            // skip the checkSizePut so we don't end up
            // accidentally recursing
            internalPut(k, oldValues[i]);
        }
    }
}
Also used : Value(com.wplatform.ddal.value.Value)

Example 53 with Value

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

the class ValueHashMap method internalPut.

private void internalPut(Value key, V value) {
    int index = getIndex(key);
    int plus = 1;
    int deleted = -1;
    do {
        Value k = keys[index];
        if (k == null) {
            // found an empty record
            if (deleted >= 0) {
                index = deleted;
                deletedCount--;
            }
            size++;
            keys[index] = key;
            values[index] = value;
            return;
        } else if (k == ValueNull.DELETED) {
            // found a deleted record
            if (deleted < 0) {
                deleted = index;
            }
        } else if (k.equals(key)) {
            // update existing
            values[index] = value;
            return;
        }
        index = (index + plus++) & mask;
    } while (plus <= len);
    // no space
    DbException.throwInternalError("hashmap is full");
}
Also used : Value(com.wplatform.ddal.value.Value)

Example 54 with Value

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

the class UpdatableRow method setKey.

private void setKey(PreparedStatement prep, int start, Value[] current) throws SQLException {
    for (int i = 0, size = key.size(); i < size; i++) {
        String col = key.get(i);
        int idx = getColumnIndex(col);
        Value v = current[idx];
        if (v == null || v == ValueNull.INSTANCE) {
            // as multiple such rows could exist
            throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
        }
        v.set(prep, start + i);
    }
}
Also used : Value(com.wplatform.ddal.value.Value)

Example 55 with Value

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

the class JdbcQueryWorker method doWork.

@Override
public ResultSet doWork() {
    Connection conn = null;
    PreparedStatement stmt = null;
    try {
        DataSource dataSource = getDataSource();
        Optional optional = Optional.build().shardName(shardName).readOnly(true);
        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: {};", shardName, sql);
        }
        stmt = conn.prepareStatement(sql);
        attach(stmt);
        applyQueryTimeout(stmt);
        applyMaxRows(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());
                }
            }
        }
        ResultSet result = stmt.executeQuery();
        attach(result);
        return result;
    } catch (SQLException e) {
        StatementBuilder buff = new StatementBuilder();
        buff.append(shardName).append(" executing executeQuery 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 : SQLException(java.sql.SQLException) StatementBuilder(com.wplatform.ddal.util.StatementBuilder) Connection(java.sql.Connection) Value(com.wplatform.ddal.value.Value) ResultSet(java.sql.ResultSet) 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