use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class H2RowDescriptor method wrap.
/** {@inheritDoc} */
@SuppressWarnings("ConstantConditions")
@Override
public Value wrap(Object obj, int type) throws IgniteCheckedException {
assert obj != null;
if (obj instanceof CacheObject) {
// Handle cache object.
CacheObject co = (CacheObject) obj;
if (type == Value.JAVA_OBJECT)
return new GridH2ValueCacheObject(co, idx.objectContext());
obj = co.value(idx.objectContext(), false);
}
switch(type) {
case Value.BOOLEAN:
return ValueBoolean.get((Boolean) obj);
case Value.BYTE:
return ValueByte.get((Byte) obj);
case Value.SHORT:
return ValueShort.get((Short) obj);
case Value.INT:
return ValueInt.get((Integer) obj);
case Value.FLOAT:
return ValueFloat.get((Float) obj);
case Value.LONG:
return ValueLong.get((Long) obj);
case Value.DOUBLE:
return ValueDouble.get((Double) obj);
case Value.UUID:
UUID uuid = (UUID) obj;
return ValueUuid.get(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
case Value.DATE:
return ValueDate.get((Date) obj);
case Value.TIME:
return ValueTime.get((Time) obj);
case Value.TIMESTAMP:
if (obj instanceof java.util.Date && !(obj instanceof Timestamp))
obj = new Timestamp(((java.util.Date) obj).getTime());
return ValueTimestamp.get((Timestamp) obj);
case Value.DECIMAL:
return ValueDecimal.get((BigDecimal) obj);
case Value.STRING:
return ValueString.get(obj.toString());
case Value.BYTES:
return ValueBytes.get((byte[]) obj);
case Value.JAVA_OBJECT:
return ValueJavaObject.getNoCopy(obj, null, null);
case Value.ARRAY:
Object[] arr = (Object[]) obj;
Value[] valArr = new Value[arr.length];
for (int i = 0; i < arr.length; i++) {
Object o = arr[i];
valArr[i] = o == null ? ValueNull.INSTANCE : wrap(o, DataType.getTypeFromClass(o.getClass()));
}
return ValueArray.get(valArr);
case Value.GEOMETRY:
return ValueGeometry.getFromGeometry(obj);
}
throw new IgniteCheckedException("Failed to wrap value[type=" + type + ", value=" + obj + "]");
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class GridH2AbstractKeyValueRow method syncValue.
/**
* @param waitTime Time to await for value unswap.
* @return Synchronized value.
*/
protected synchronized Value syncValue(long waitTime) {
Value v = peekValue(VAL_COL);
while (v == null && waitTime > 0) {
// This call must be quite rare, so performance is not a concern.
long start = System.nanoTime();
try {
// Wait for value arrival to allow other threads to make a progress.
wait(waitTime);
} catch (InterruptedException e) {
throw new IgniteInterruptedException(e);
}
long t = System.nanoTime() - start;
if (t > 0)
waitTime -= TimeUnit.NANOSECONDS.toMillis(t);
v = peekValue(VAL_COL);
}
return v;
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class GridH2AbstractKeyValueRow method updateWeakValue.
/**
* Atomically updates weak value.
*
* @param valObj New value.
* @return New value if old value is empty, old value otherwise.
* @throws IgniteCheckedException If failed.
*/
protected synchronized Value updateWeakValue(Object valObj) throws IgniteCheckedException {
Value res = peekValue(VAL_COL);
if (res != null && !(res instanceof WeakValue))
return res;
Value upd = desc.wrap(valObj, desc.valueType());
setValue(VAL_COL, new WeakValue(upd));
notifyAll();
return upd;
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class GridH2AbstractKeyValueRow method toString.
/** {@inheritDoc} */
@Override
public String toString() {
SB sb = new SB("Row@");
sb.a(Integer.toHexString(System.identityHashCode(this)));
addOffheapRowId(sb);
Value v = peekValue(KEY_COL);
sb.a("[ key: ").a(v == null ? "nil" : v.getString());
v = WeakValue.unwrap(peekValue(VAL_COL));
sb.a(", val: ").a(v == null ? "nil" : v.getString());
v = peekValue(VER_COL);
sb.a(", ver: ").a(v == null ? "nil" : v.getString());
sb.a(" ][ ");
if (v != null) {
for (int i = DEFAULT_COLUMNS_COUNT, cnt = getColumnCount(); i < cnt; i++) {
v = getValue(i);
if (i != DEFAULT_COLUMNS_COUNT)
sb.a(", ");
if (!desc.isKeyValueOrVersionColumn(i))
sb.a(v == null ? "nil" : v.getString());
}
}
sb.a(" ]");
return sb.toString();
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class H2Tree method compareRows.
/**
* Compare two rows.
*
* @param r1 Row 1.
* @param r2 Row 2.
* @return Compare result.
*/
private int compareRows(GridH2Row r1, SearchRow r2) {
if (r1 == r2)
return 0;
for (int i = 0, len = cols.length; i < len; i++) {
int idx = columnIds[i];
Value v1 = r1.getValue(idx);
Value v2 = r2.getValue(idx);
if (v1 == null || v2 == null) {
// can't compare further
return 0;
}
int c = compareValues(v1, v2);
if (c != 0)
return InlineIndexHelper.fixSort(c, cols[i].sortType);
}
return 0;
}
Aggregations