Search in sources :

Example 1 with GridH2KeyValueRowOnheap

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap in project ignite by apache.

the class H2RowCacheSelfTest method getLinkForKey.

/**
 * @param cacheName Cache name.
 * @param rowCache Row cache.
 * @param key Key to find.
 * @return Row's link.
 */
private long getLinkForKey(String cacheName, H2RowCache rowCache, int key) {
    grid().cache(cacheName).query(new SqlQuery(Value.class, "_key = " + key)).getAll().size();
    ConcurrentHashMap<Long, GridH2KeyValueRowOnheap> rowsMap = GridTestUtils.getFieldValue(rowCache, "rows");
    for (Map.Entry<Long, GridH2KeyValueRowOnheap> e : rowsMap.entrySet()) {
        GridH2KeyValueRowOnheap val = e.getValue();
        if ((Integer) val.key().value(null, false) == key)
            return e.getKey();
    }
    fail("Row cache doesn't contain key [key=" + key + ']');
    return -1;
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) GridH2KeyValueRowOnheap(org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap)

Example 2 with GridH2KeyValueRowOnheap

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap in project ignite by apache.

the class H2RowCache method clearForCache.

/**
 * Clear entries belonging to the given cache.
 *
 * @param cctx Cache context.
 */
private void clearForCache(GridCacheContext cctx) {
    int cacheId = cctx.cacheId();
    Iterator<Map.Entry<Long, GridH2KeyValueRowOnheap>> iter = rows.entrySet().iterator();
    while (iter.hasNext()) {
        GridH2KeyValueRowOnheap row = iter.next().getValue();
        if (F.eq(cacheId, row.cacheId()))
            iter.remove();
    }
}
Also used : GridH2KeyValueRowOnheap(org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap)

Example 3 with GridH2KeyValueRowOnheap

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap in project ignite by apache.

the class H2RowDescriptor method createRow.

/** {@inheritDoc} */
@Override
public GridH2Row createRow(KeyCacheObject key, int partId, @Nullable CacheObject val, GridCacheVersion ver, long expirationTime) throws IgniteCheckedException {
    GridH2Row row;
    try {
        if (// Only can happen for remove operation, can create simple search row.
        val == null)
            row = GridH2RowFactory.create(wrap(key, keyType));
        else
            row = schema.offheap() == null ? new GridH2KeyValueRowOnheap(this, key, keyType, val, valType, ver, expirationTime) : new GridH2KeyValueRowOffheap(this, key, keyType, val, valType, ver, expirationTime);
    } catch (ClassCastException e) {
        throw new IgniteCheckedException("Failed to convert key to SQL type. " + "Please make sure that you always store each value type with the same key type " + "or configure key type as common super class for all actual keys for this value type.", e);
    }
    row.ver = ver;
    row.key = key;
    row.val = val;
    row.partId = partId;
    return row;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridH2KeyValueRowOffheap(org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOffheap) GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row) GridH2KeyValueRowOnheap(org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap)

Example 4 with GridH2KeyValueRowOnheap

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap in project ignite by apache.

the class GridH2Table method update.

/**
 * Updates table for given key. If value is null then row with given key will be removed from table,
 * otherwise value and expiration time will be updated or new row will be added.
 *
 * @param row Row to be updated.
 * @param prevRow Previous row.
 * @param prevRowAvailable Whether previous row is available.
 * @throws IgniteCheckedException If failed.
 */
public void update(CacheDataRow row, @Nullable CacheDataRow prevRow, boolean prevRowAvailable) throws IgniteCheckedException {
    assert desc != null;
    GridH2KeyValueRowOnheap row0 = (GridH2KeyValueRowOnheap) desc.createRow(row);
    GridH2KeyValueRowOnheap prevRow0 = prevRow != null ? (GridH2KeyValueRowOnheap) desc.createRow(prevRow) : null;
    row0.prepareValuesCache();
    if (prevRow0 != null)
        prevRow0.prepareValuesCache();
    try {
        lock(false);
        try {
            ensureNotDestroyed();
            boolean replaced;
            if (prevRowAvailable)
                replaced = pk().putx(row0);
            else {
                prevRow0 = (GridH2KeyValueRowOnheap) pk().put(row0);
                replaced = prevRow0 != null;
            }
            if (!replaced)
                size.increment();
            for (int i = pkIndexPos + 1, len = idxs.size(); i < len; i++) {
                Index idx = idxs.get(i);
                if (idx instanceof GridH2IndexBase)
                    addToIndex((GridH2IndexBase) idx, row0, prevRow0);
            }
            if (!tmpIdxs.isEmpty()) {
                for (GridH2IndexBase idx : tmpIdxs.values()) addToIndex(idx, row0, prevRow0);
            }
        } finally {
            unlock(false);
        }
    } finally {
        row0.clearValuesCache();
        if (prevRow0 != null)
            prevRow0.clearValuesCache();
    }
}
Also used : Index(org.h2.index.Index) SpatialIndex(org.h2.index.SpatialIndex) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)

Aggregations

GridH2KeyValueRowOnheap (org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOnheap)3 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 SqlQuery (org.apache.ignite.cache.query.SqlQuery)1 H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)1 GridH2KeyValueRowOffheap (org.apache.ignite.internal.processors.query.h2.opt.GridH2KeyValueRowOffheap)1 GridH2Row (org.apache.ignite.internal.processors.query.h2.opt.GridH2Row)1 Index (org.h2.index.Index)1 SpatialIndex (org.h2.index.SpatialIndex)1