Search in sources :

Example 36 with Row

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

the class H2TreeIndex method find.

/**
 * {@inheritDoc}
 */
@Override
public Cursor find(Session ses, SearchRow lower, SearchRow upper) {
    try {
        IndexingQueryCacheFilter filter = partitionFilter(threadLocalFilter());
        int seg = threadLocalSegment();
        H2Tree tree = treeForRead(seg);
        if (indexType.isPrimaryKey() && lower != null && upper != null && tree.compareRows(lower, upper) == 0) {
            GridH2Row row = tree.findOne(lower, filter);
            return (row == null) ? EMPTY_CURSOR : new SingleRowCursor(row);
        } else {
            GridCursor<GridH2Row> cursor = tree.find(lower, upper, filter);
            return new H2Cursor(cursor);
        }
    } catch (IgniteCheckedException e) {
        throw DbException.convert(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) H2Cursor(org.apache.ignite.internal.processors.query.h2.H2Cursor) GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row) IndexingQueryCacheFilter(org.apache.ignite.spi.indexing.IndexingQueryCacheFilter) SingleRowCursor(org.h2.index.SingleRowCursor)

Example 37 with Row

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

Example 38 with Row

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

the class GridMergeIndexIterator method advance.

/**
 * Advance iterator.
 */
private void advance() {
    next = null;
    try {
        boolean hasNext = false;
        while (cursor == null || !(hasNext = cursor.next())) {
            if (idxIter.hasNext())
                cursor = idxIter.next().findInStream(null, null);
            else {
                releaseIfNeeded();
                break;
            }
        }
        if (hasNext) {
            Row row = cursor.get();
            int cols = row.getColumnCount();
            List<Object> res = new ArrayList<>(cols);
            for (int c = 0; c < cols; c++) res.add(row.getValue(c).getObject());
            next = res;
        }
    } catch (Exception e) {
        releaseIfNeeded();
        throw e;
    }
}
Also used : ArrayList(java.util.ArrayList) Row(org.h2.result.Row) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) NoSuchElementException(java.util.NoSuchElementException)

Example 39 with Row

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

the class GridH2Table method remove.

/**
 * Remove row.
 *
 * @param row Row.
 * @return {@code True} if was removed.
 * @throws IgniteCheckedException If failed.
 */
public boolean remove(CacheDataRow row) throws IgniteCheckedException {
    GridH2Row row0 = desc.createRow(row);
    lock(false);
    try {
        ensureNotDestroyed();
        boolean rmv = pk().removex(row0);
        if (rmv) {
            for (int i = pkIndexPos + 1, len = idxs.size(); i < len; i++) {
                Index idx = idxs.get(i);
                if (idx instanceof GridH2IndexBase)
                    ((GridH2IndexBase) idx).removex(row0);
            }
            if (!tmpIdxs.isEmpty()) {
                for (GridH2IndexBase idx : tmpIdxs.values()) idx.removex(row0);
            }
            size.decrement();
        }
        return rmv;
    } finally {
        unlock(false);
    }
}
Also used : Index(org.h2.index.Index) SpatialIndex(org.h2.index.SpatialIndex) H2TreeIndex(org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)

Example 40 with Row

use of org.h2.result.Row in project elastic-core-maven by OrdinaryDude.

the class FullTextTrigger method reindexTable.

/**
 * Reindex the table
 *
 * @param   conn                SQL connection
 * @throws  SQLException        Unable to reindex table
 */
private void reindexTable(Connection conn) throws SQLException {
    if (indexColumns.isEmpty()) {
        return;
    }
    // 
    // Build the SELECT statement for just the indexed columns
    // 
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT DB_ID");
    for (int index : indexColumns) {
        sb.append(", ").append(columnNames.get(index));
    }
    sb.append(" FROM ").append(tableName);
    Object[] row = new Object[columnNames.size()];
    // 
    try (Statement qstmt = conn.createStatement();
        ResultSet rs = qstmt.executeQuery(sb.toString())) {
        while (rs.next()) {
            row[dbColumn] = rs.getObject(1);
            int i = 2;
            for (int index : indexColumns) {
                row[index] = rs.getObject(i++);
            }
            indexRow(row);
        }
    }
    // 
    // Commit the index updates
    // 
    commitIndex();
}
Also used : Statement(java.sql.Statement) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet)

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