Search in sources :

Example 16 with TransactionMap

use of org.h2.mvstore.db.TransactionStore.TransactionMap in project h2database by h2database.

the class MVPrimaryIndex method find.

@Override
public Cursor find(Session session, SearchRow first, SearchRow last) {
    ValueLong min, max;
    if (first == null) {
        min = ValueLong.MIN;
    } else if (mainIndexColumn < 0) {
        min = ValueLong.get(first.getKey());
    } else {
        ValueLong v = (ValueLong) first.getValue(mainIndexColumn);
        if (v == null) {
            min = ValueLong.get(first.getKey());
        } else {
            min = v;
        }
    }
    if (last == null) {
        max = ValueLong.MAX;
    } else if (mainIndexColumn < 0) {
        max = ValueLong.get(last.getKey());
    } else {
        ValueLong v = (ValueLong) last.getValue(mainIndexColumn);
        if (v == null) {
            max = ValueLong.get(last.getKey());
        } else {
            max = v;
        }
    }
    TransactionMap<Value, Value> map = getMap(session);
    return new MVStoreCursor(session, map.entryIterator(min, max));
}
Also used : ValueLong(org.h2.value.ValueLong) Value(org.h2.value.Value)

Example 17 with TransactionMap

use of org.h2.mvstore.db.TransactionStore.TransactionMap in project h2database by h2database.

the class MVPrimaryIndex method remove.

@Override
public void remove(Session session) {
    TransactionMap<Value, Value> map = getMap(session);
    if (!map.isClosed()) {
        Transaction t = session.getTransaction();
        t.removeMap(map);
    }
}
Also used : Transaction(org.h2.mvstore.db.TransactionStore.Transaction) Value(org.h2.value.Value)

Example 18 with TransactionMap

use of org.h2.mvstore.db.TransactionStore.TransactionMap in project h2database by h2database.

the class MVPrimaryIndex method getRow.

@Override
public Row getRow(Session session, long key) {
    TransactionMap<Value, Value> map = getMap(session);
    Value v = map.get(ValueLong.get(key));
    if (v == null) {
        throw DbException.get(ErrorCode.ROW_NOT_FOUND_IN_PRIMARY_INDEX, getSQL() + ": " + key);
    }
    ValueArray array = (ValueArray) v;
    Row row = session.createRow(array.getList(), 0);
    row.setKey(key);
    return row;
}
Also used : Value(org.h2.value.Value) Row(org.h2.result.Row) SearchRow(org.h2.result.SearchRow) ValueArray(org.h2.value.ValueArray)

Example 19 with TransactionMap

use of org.h2.mvstore.db.TransactionStore.TransactionMap 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)

Example 20 with TransactionMap

use of org.h2.mvstore.db.TransactionStore.TransactionMap in project h2database by h2database.

the class MVSpatialIndex method remove.

@Override
public void remove(Session session) {
    TransactionMap<SpatialKey, Value> map = getMap(session);
    if (!map.isClosed()) {
        Transaction t = session.getTransaction();
        t.removeMap(map);
    }
}
Also used : SpatialKey(org.h2.mvstore.rtree.SpatialKey) Transaction(org.h2.mvstore.db.TransactionStore.Transaction) Value(org.h2.value.Value) VersionedValue(org.h2.mvstore.db.TransactionStore.VersionedValue)

Aggregations

Transaction (org.h2.mvstore.db.TransactionStore.Transaction)19 MVStore (org.h2.mvstore.MVStore)17 TransactionStore (org.h2.mvstore.db.TransactionStore)17 Value (org.h2.value.Value)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 ValueArray (org.h2.value.ValueArray)6 Random (java.util.Random)5 VersionedValue (org.h2.mvstore.db.TransactionStore.VersionedValue)4 SpatialKey (org.h2.mvstore.rtree.SpatialKey)4 Task (org.h2.util.Task)4 ValueLong (org.h2.value.ValueLong)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Entry (java.util.Map.Entry)1 MetaRecord (org.h2.engine.MetaRecord)1 Session (org.h2.engine.Session)1 DbException (org.h2.message.DbException)1 Change (org.h2.mvstore.db.TransactionStore.Change)1