Search in sources :

Example 6 with Row

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();
    }
}
Also used : Row(org.h2.result.Row) SearchRow(org.h2.result.SearchRow) GridUnsafeMemory(org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory)

Example 7 with Row

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));
}
Also used : Value(org.h2.value.Value) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject)

Example 8 with Row

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);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridH2ValueMessage(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessage) Value(org.h2.value.Value)

Example 9 with Row

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);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException) GridKernalContext(org.apache.ignite.internal.GridKernalContext) Value(org.h2.value.Value) GridH2ValueMessage(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessage)

Example 10 with Row

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;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException) GridH2ValueMessage(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessage) ArrayList(java.util.ArrayList) Value(org.h2.value.Value) GridH2RowMessage(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2RowMessage) IndexColumn(org.h2.table.IndexColumn)

Aggregations

Value (org.h2.value.Value)16 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)10 Column (org.h2.table.Column)8 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)7 ArrayList (java.util.ArrayList)6 Index (org.h2.index.Index)6 BinaryObject (org.apache.ignite.binary.BinaryObject)5 GridQueryProperty (org.apache.ignite.internal.processors.query.GridQueryProperty)5 SimpleResultSet (org.h2.tools.SimpleResultSet)5 ResultSet (java.sql.ResultSet)4 LinkedHashMap (java.util.LinkedHashMap)4 H2PkHashIndex (org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex)4 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)4 SQLException (java.sql.SQLException)3 Statement (java.sql.Statement)3 HashMap (java.util.HashMap)3 CacheException (javax.cache.CacheException)3 GridKernalContext (org.apache.ignite.internal.GridKernalContext)3 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)3