use of org.h2.result.Row in project ignite by apache.
the class GridH2Table method doUpdate.
/**
* For testing only.
*
* @param row Row.
* @param del If given row should be deleted from table.
* @return {@code True} if operation succeeded.
* @throws IgniteCheckedException If failed.
*/
@SuppressWarnings("LockAcquiredButNotSafelyReleased")
boolean doUpdate(final GridH2Row row, boolean del) throws IgniteCheckedException {
// Here we assume that each key can't be updated concurrently and case when different indexes
// getting updated from different threads with different rows with the same key is impossible.
GridUnsafeMemory mem = desc == null ? null : desc.memory();
lock(false);
if (mem != null)
desc.guard().begin();
try {
ensureNotDestroyed();
GridH2IndexBase pk = pk();
if (!del) {
assert rowFactory == null || row.link != 0 : row;
// Put to PK.
GridH2Row old = pk.put(row);
if (old == null)
size.increment();
int len = idxs.size();
int i = pkIndexPos;
// Start from 3 because 0 - Scan (don't need to update), 1 - PK hash (already updated), 2 - PK (already updated).
while (++i < len) {
if (!(idxs.get(i) instanceof GridH2IndexBase))
continue;
GridH2IndexBase idx = index(i);
addToIndex(idx, pk, row, old, false);
}
for (GridH2IndexBase idx : tmpIdxs.values()) addToIndex(idx, pk, row, old, true);
} else {
// index(1) is PK, get full row from there (search row here contains only key but no other columns).
GridH2Row old = pk.remove(row);
if (old != null) {
// Start from 3 because 0 - Scan (don't need to update), 1 - PK hash (already updated), 2 - PK (already updated).
for (int i = pkIndexPos + 1, len = idxs.size(); i < len; i++) {
if (!(idxs.get(i) instanceof GridH2IndexBase))
continue;
Row res = index(i).remove(old);
assert eq(pk, res, old) : "\n" + old + "\n" + res + "\n" + i + " -> " + index(i).getName();
}
for (GridH2IndexBase idx : tmpIdxs.values()) idx.remove(old);
size.decrement();
} else
return false;
}
// The snapshot is not actual after update.
if (actualSnapshot != null)
actualSnapshot.set(pk.segmentForRow(row), null);
return true;
} finally {
unlock(false);
if (mem != null)
desc.guard().end();
}
}
use of org.h2.result.Row in project ignite by apache.
the class GridH2IndexBase method segmentForRow.
/**
* @param row Table row.
* @return Segment ID for given row.
*/
protected int segmentForRow(SearchRow row) {
assert row != null;
if (segmentsCount() == 1 || ctx == null)
return 0;
CacheObject key;
final Value keyColValue = row.getValue(KEY_COL);
assert keyColValue != null;
final Object o = keyColValue.getObject();
if (o instanceof CacheObject)
key = (CacheObject) o;
else
key = ctx.toCacheKeyObject(o);
return segmentForPartition(ctx.affinity().partition(key));
}
use of org.h2.result.Row in project ignite by apache.
the class GridH2IndexBase method toRow.
/**
* @param msg Message.
* @return Row.
*/
private Row toRow(GridH2RowMessage msg) {
if (msg == null)
return null;
GridKernalContext ctx = kernalContext();
List<GridH2ValueMessage> vals = msg.values();
assert !F.isEmpty(vals) : vals;
Value[] vals0 = new Value[vals.size()];
for (int i = 0; i < vals0.length; i++) {
try {
vals0[i] = vals.get(i).value(ctx);
} catch (IgniteCheckedException e) {
throw new CacheException(e);
}
}
return database.createRow(vals0, MEMORY_CALCULATE);
}
use of org.h2.result.Row in project ignite by apache.
the class GridH2IndexBase method toSearchRow.
/**
* @param msg Row message.
* @return Search row.
*/
private SearchRow toSearchRow(GridH2RowMessage msg) {
if (msg == null)
return null;
GridKernalContext ctx = kernalContext();
Value[] vals = new Value[getTable().getColumns().length];
assert vals.length > 0;
List<GridH2ValueMessage> msgVals = msg.values();
for (int i = 0; i < indexColumns.length; i++) {
if (i >= msgVals.size())
continue;
try {
vals[indexColumns[i].column.getColumnId()] = msgVals.get(i).value(ctx);
} catch (IgniteCheckedException e) {
throw new CacheException(e);
}
}
return database.createRow(vals, MEMORY_CALCULATE);
}
use of org.h2.result.Row in project ignite by apache.
the class GridH2IndexBase method toSearchRowMessage.
/**
* @param row Search row.
* @return Row message.
*/
private GridH2RowMessage toSearchRowMessage(SearchRow row) {
if (row == null)
return null;
List<GridH2ValueMessage> vals = new ArrayList<>(indexColumns.length);
for (IndexColumn idxCol : indexColumns) {
Value val = row.getValue(idxCol.column.getColumnId());
if (val == null)
break;
try {
vals.add(GridH2ValueMessageFactory.toMessage(val));
} catch (IgniteCheckedException e) {
throw new CacheException(e);
}
}
GridH2RowMessage res = new GridH2RowMessage();
res.values(vals);
return res;
}
Aggregations