Search in sources :

Example 1 with SearchRow

use of org.h2.result.SearchRow in project ignite by apache.

the class GridH2SpatialIndex method getEnvelope.

/**
     * @param row Row.
     * @param rowId Row id.
     * @return Envelope.
     */
private SpatialKey getEnvelope(SearchRow row, long rowId) {
    Value v = row.getValue(columnIds[0]);
    Geometry g = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getGeometry();
    Envelope env = g.getEnvelopeInternal();
    return new SpatialKey(rowId, (float) env.getMinX(), (float) env.getMaxX(), (float) env.getMinY(), (float) env.getMaxY());
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) ValueGeometry(org.h2.value.ValueGeometry) SpatialKey(org.h2.mvstore.rtree.SpatialKey) ValueGeometry(org.h2.value.ValueGeometry) Value(org.h2.value.Value) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 2 with SearchRow

use of org.h2.result.SearchRow in project ignite by apache.

the class GridH2SpatialIndex method remove.

/** {@inheritDoc} */
@Override
public GridH2Row remove(SearchRow row) {
    Lock l = lock.writeLock();
    l.lock();
    try {
        checkClosed();
        Value key = row.getValue(KEY_COL);
        assert key != null;
        Long rowId = keyToId.remove(key);
        assert rowId != null;
        GridH2Row oldRow = idToRow.remove(rowId);
        assert oldRow != null;
        final int seg = segmentForRow(row);
        if (!segments[seg].remove(getEnvelope(row, rowId), rowId))
            throw DbException.throwInternalError("row not found");
        rowCnt--;
        return oldRow;
    } finally {
        l.unlock();
    }
}
Also used : Value(org.h2.value.Value) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 3 with SearchRow

use of org.h2.result.SearchRow 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;
    CacheObject key;
    if (ctx != null) {
        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));
    }
    assert segmentsCount() == 1;
    return 0;
}
Also used : Value(org.h2.value.Value) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject)

Example 4 with SearchRow

use of org.h2.result.SearchRow 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) Value(org.h2.value.Value) GridH2RowMessage(org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2RowMessage) IndexColumn(org.h2.table.IndexColumn)

Example 5 with SearchRow

use of org.h2.result.SearchRow 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)

Aggregations

Value (org.h2.value.Value)7 CacheException (javax.cache.CacheException)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 GridH2ValueMessage (org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessage)2 SearchRow (org.h2.result.SearchRow)2 IndexColumn (org.h2.table.IndexColumn)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Timestamp (java.sql.Timestamp)1 Random (java.util.Random)1 UUID (java.util.UUID)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1 H2PkHashIndex (org.apache.ignite.internal.processors.query.h2.database.H2PkHashIndex)1