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();
}
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]);
}
}
}
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");
}
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);
}
}
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);
}
}
Aggregations