Search in sources :

Example 11 with GridH2IndexBase

use of org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase 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 12 with GridH2IndexBase

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

the class H2TableDescriptor method createUserIndex.

/**
 * Create user index.
 *
 * @param idxDesc Index descriptor.
 * @return Index.
 */
public GridH2IndexBase createUserIndex(GridQueryIndexDescriptor idxDesc) {
    IndexColumn keyCol = tbl.indexColumn(KEY_COL, SortOrder.ASCENDING);
    IndexColumn affCol = tbl.getAffinityKeyColumn();
    List<IndexColumn> cols = new ArrayList<>(idxDesc.fields().size() + 2);
    for (String field : idxDesc.fields()) {
        Column col = tbl.getColumn(field);
        cols.add(tbl.indexColumn(col.getColumnId(), idxDesc.descending(field) ? SortOrder.DESCENDING : SortOrder.ASCENDING));
    }
    GridH2RowDescriptor desc = tbl.rowDescriptor();
    if (idxDesc.type() == QueryIndexType.SORTED) {
        cols = H2Utils.treeIndexColumns(desc, cols, keyCol, affCol);
        return idx.createSortedIndex(idxDesc.name(), tbl, false, cols, idxDesc.inlineSize());
    } else if (idxDesc.type() == QueryIndexType.GEOSPATIAL)
        return H2Utils.createSpatialIndex(tbl, idxDesc.name(), cols.toArray(new IndexColumn[cols.size()]));
    throw new IllegalStateException("Index type: " + idxDesc.type());
}
Also used : GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) Column(org.h2.table.Column) IndexColumn(org.h2.table.IndexColumn) ArrayList(java.util.ArrayList) IndexColumn(org.h2.table.IndexColumn)

Example 13 with GridH2IndexBase

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

the class IgniteH2Indexing method addInitialUserIndex.

/**
 * Add initial user index.
 *
 * @param schemaName Schema name.
 * @param desc Table descriptor.
 * @param h2Idx User index.
 * @throws IgniteCheckedException If failed.
 */
private void addInitialUserIndex(String schemaName, H2TableDescriptor desc, GridH2IndexBase h2Idx) throws IgniteCheckedException {
    GridH2Table h2Tbl = desc.table();
    h2Tbl.proposeUserIndex(h2Idx);
    try {
        String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, false);
        executeSql(schemaName, sql);
    } catch (Exception e) {
        // Rollback and re-throw.
        h2Tbl.rollbackUserIndex(h2Idx.getName());
        throw e;
    }
}
Also used : GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 14 with GridH2IndexBase

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

the class IgniteH2Indexing method dynamicIndexCreate.

/**
 * {@inheritDoc}
 */
@Override
public void dynamicIndexCreate(final String schemaName, final String tblName, final QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor) throws IgniteCheckedException {
    // Locate table.
    H2Schema schema = schemas.get(schemaName);
    H2TableDescriptor desc = (schema != null ? schema.tableByName(tblName) : null);
    if (desc == null)
        throw new IgniteCheckedException("Table not found in internal H2 database [schemaName=" + schemaName + ", tblName=" + tblName + ']');
    GridH2Table h2Tbl = desc.table();
    // Create index.
    final GridH2IndexBase h2Idx = desc.createUserIndex(idxDesc);
    h2Tbl.proposeUserIndex(h2Idx);
    try {
        // Populate index with existing cache data.
        final GridH2RowDescriptor rowDesc = h2Tbl.rowDescriptor();
        SchemaIndexCacheVisitorClosure clo = new SchemaIndexCacheVisitorClosure() {

            @Override
            public void apply(CacheDataRow row) throws IgniteCheckedException {
                GridH2Row h2Row = rowDesc.createRow(row);
                h2Idx.putx(h2Row);
            }
        };
        cacheVisitor.visit(clo);
        // At this point index is in consistent state, promote it through H2 SQL statement, so that cached
        // prepared statements are re-built.
        String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, ifNotExists);
        executeSql(schemaName, sql);
    } catch (Exception e) {
        // Rollback and re-throw.
        h2Tbl.rollbackUserIndex(h2Idx.getName());
        throw e;
    }
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) GridH2IndexBase(org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridH2RowDescriptor(org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) GridH2Row(org.apache.ignite.internal.processors.query.h2.opt.GridH2Row) SchemaIndexCacheVisitorClosure(org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorClosure) IgniteSystemProperties.getString(org.apache.ignite.IgniteSystemProperties.getString) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SqlParseException(org.apache.ignite.internal.sql.SqlParseException) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Aggregations

H2TreeIndex (org.apache.ignite.internal.processors.query.h2.database.H2TreeIndex)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 Index (org.h2.index.Index)6 IgniteException (org.apache.ignite.IgniteException)5 SpatialIndex (org.h2.index.SpatialIndex)5 GridH2IndexBase (org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase)4 SQLException (java.sql.SQLException)3 IgniteSystemProperties.getString (org.apache.ignite.IgniteSystemProperties.getString)3 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)3 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)3 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)3 IndexColumn (org.h2.table.IndexColumn)3 ArrayList (java.util.ArrayList)2 CacheException (javax.cache.CacheException)2 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)2 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)2 SqlParseException (org.apache.ignite.internal.sql.SqlParseException)2 Column (org.h2.table.Column)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1