use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class InlineIndexHelper method compare.
/**
* @param pageAddr Page address.
* @param off Offset.
* @param maxSize Maximum size to read.
* @param v Value to compare.
* @param comp Comparator.
* @return Compare result (-2 means we can't compare).
*/
public int compare(long pageAddr, int off, int maxSize, Value v, Comparator<Value> comp) {
int c = tryCompareOptimized(pageAddr, off, maxSize, v);
if (c != Integer.MIN_VALUE)
return c;
Value v1 = get(pageAddr, off, maxSize);
if (v1 == null)
return -2;
c = Integer.signum(comp.compare(v1, v));
if (size > 0)
return fixSort(c, sortType());
if (isValueFull(pageAddr, off) || canRelyOnCompare(c, v1, v))
return fixSort(c, sortType());
return -2;
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class GridH2RowDescriptor method wrap.
/**
* Wraps object to respective {@link Value}.
*
* @param obj Object.
* @param type Value type.
* @return Value.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("ConstantConditions")
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:
if (LocalDateTimeUtils.isLocalDate(obj.getClass()))
return LocalDateTimeUtils.localDateToDateValue(obj);
return ValueDate.get((Date) obj);
case Value.TIME:
if (LocalDateTimeUtils.isLocalTime(obj.getClass()))
return LocalDateTimeUtils.localTimeToTimeValue(obj);
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());
if (LocalDateTimeUtils.isLocalDateTime(obj.getClass()))
return LocalDateTimeUtils.localDateTimeToValue(obj);
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 GridH2SpatialIndex method put.
/**
* {@inheritDoc}
*/
@Override
public GridH2Row put(GridH2Row row) {
assert row instanceof GridH2KeyValueRowOnheap : "requires key to be at 0";
Lock l = lock.writeLock();
l.lock();
try {
checkClosed();
Value key = row.getValue(KEY_COL);
assert key != null;
final int seg = segmentForRow(row);
Long rowId = keyToId.get(key);
if (rowId != null) {
Long oldRowId = segments[seg].remove(getEnvelope(idToRow.get(rowId), rowId));
assert rowId.equals(oldRowId);
} else {
rowId = ++rowIds;
keyToId.put(key, rowId);
}
GridH2Row old = idToRow.put(rowId, row);
segments[seg].put(getEnvelope(row, rowId), rowId);
if (old == null)
// No replace.
rowCnt++;
return old;
} finally {
l.unlock();
}
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class GridH2SpatialIndex method remove.
/**
* {@inheritDoc}
*/
@Override
public GridH2Row remove(SearchRow row) {
Lock l = lock.writeLock();
l.lock();
try {
checkClosed();
Value key = row.getValue(KEY_COL);
assert key != null;
Long rowId = keyToId.remove(key);
assert rowId != null;
GridH2Row oldRow = idToRow.remove(rowId);
assert oldRow != null;
final int seg = segmentForRow(row);
if (!segments[seg].remove(getEnvelope(row, rowId), rowId))
throw DbException.throwInternalError("row not found");
rowCnt--;
return oldRow;
} finally {
l.unlock();
}
}
use of org.gridgain.internal.h2.value.Value in project ignite by apache.
the class GridH2SpatialIndex method getEnvelope.
/**
* @param row Row.
* @param rowId Row id.
* @return Envelope.
*/
private SpatialKey getEnvelope(SearchRow row, long rowId) {
Value v = row.getValue(columnIds[0]);
Geometry g = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getGeometry();
Envelope env = g.getEnvelopeInternal();
return new SpatialKey(rowId, (float) env.getMinX(), (float) env.getMaxX(), (float) env.getMinY(), (float) env.getMaxY());
}
Aggregations