Search in sources :

Example 1 with RTreeCursor

use of org.h2.mvstore.rtree.MVRTreeMap.RTreeCursor in project h2database by h2database.

the class MVSpatialIndex method add.

@Override
public void add(Session session, Row row) {
    TransactionMap<SpatialKey, Value> map = getMap(session);
    SpatialKey key = getKey(row);
    if (key.isNull()) {
        return;
    }
    if (indexType.isUnique()) {
        // this will detect committed entries only
        RTreeCursor cursor = spatialMap.findContainedKeys(key);
        Iterator<SpatialKey> it = map.wrapIterator(cursor, false);
        while (it.hasNext()) {
            SpatialKey k = it.next();
            if (k.equalsIgnoringId(key)) {
                throw getDuplicateKeyException(key.toString());
            }
        }
    }
    try {
        map.put(key, ValueLong.get(0));
    } catch (IllegalStateException e) {
        throw mvTable.convertException(e);
    }
    if (indexType.isUnique()) {
        // check if there is another (uncommitted) entry
        RTreeCursor cursor = spatialMap.findContainedKeys(key);
        Iterator<SpatialKey> it = map.wrapIterator(cursor, true);
        while (it.hasNext()) {
            SpatialKey k = it.next();
            if (k.equalsIgnoringId(key)) {
                if (map.isSameTransaction(k)) {
                    continue;
                }
                map.remove(key);
                if (map.get(k) != null) {
                    // committed
                    throw getDuplicateKeyException(k.toString());
                }
                throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, table.getName());
            }
        }
    }
}
Also used : SpatialKey(org.h2.mvstore.rtree.SpatialKey) Value(org.h2.value.Value) VersionedValue(org.h2.mvstore.db.TransactionStore.VersionedValue) RTreeCursor(org.h2.mvstore.rtree.MVRTreeMap.RTreeCursor)

Aggregations

VersionedValue (org.h2.mvstore.db.TransactionStore.VersionedValue)1 RTreeCursor (org.h2.mvstore.rtree.MVRTreeMap.RTreeCursor)1 SpatialKey (org.h2.mvstore.rtree.SpatialKey)1 Value (org.h2.value.Value)1