Search in sources :

Example 66 with GridH2Table

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

the class H2Utils method collectCacheIds.

/**
 * Collect cache identifiers from two-step query.
 *
 * @param mainCacheId Id of main cache.
 * @return Result.
 */
public static List<Integer> collectCacheIds(IgniteH2Indexing idx, @Nullable Integer mainCacheId, Collection<QueryTable> tbls) {
    LinkedHashSet<Integer> caches0 = new LinkedHashSet<>();
    if (mainCacheId != null)
        caches0.add(mainCacheId);
    if (!F.isEmpty(tbls)) {
        for (QueryTable tblKey : tbls) {
            GridH2Table tbl = idx.schemaManager().dataTable(tblKey.schema(), tblKey.table());
            if (tbl != null) {
                checkAndStartNotStartedCache(idx.kernalContext(), tbl);
                caches0.add(tbl.cacheId());
            }
        }
    }
    return caches0.isEmpty() ? Collections.emptyList() : new ArrayList<>(caches0);
}
Also used : BigInteger(java.math.BigInteger) LinkedHashSet(java.util.LinkedHashSet) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) QueryTable(org.apache.ignite.internal.processors.cache.query.QueryTable)

Example 67 with GridH2Table

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

the class H2Utils method createSpatialIndex.

/**
 * Create spatial index.
 *
 * @param tbl Table.
 * @param idxName Index name.
 * @param cols Columns.
 */
@SuppressWarnings("ConstantConditions")
public static GridH2IndexBase createSpatialIndex(GridH2Table tbl, String idxName, List<IndexColumn> cols) {
    try {
        Class<?> fctCls = Class.forName(SPATIAL_IDX_FACTORY_CLS);
        Method fctMethod = fctCls.getMethod("createIndex", GridH2Table.class, String.class, List.class);
        return (GridH2IndexBase) fctMethod.invoke(null, tbl, idxName, cols);
    } catch (Exception e) {
        throw new IgniteException("Failed to instantiate: " + SPATIAL_IDX_CLS, e);
    }
}
Also used : GridH2IndexBase(org.apache.ignite.internal.processors.query.h2.opt.GridH2IndexBase) IgniteException(org.apache.ignite.IgniteException) Method(java.lang.reflect.Method) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridH2RetryException(org.apache.ignite.internal.processors.query.h2.opt.GridH2RetryException) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 68 with GridH2Table

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

the class SchemaManager method onCacheDestroyed.

/**
 * Handle cache destroy.
 *
 * @param cacheName Cache name.
 * @param rmvIdx Whether to remove indexes.
 */
public void onCacheDestroyed(String cacheName, boolean rmvIdx) {
    String schemaName = schemaName(cacheName);
    H2Schema schema = schemas.get(schemaName);
    // Remove this mapping only after callback to DML proc - it needs that mapping internally
    cacheName2schema.remove(cacheName);
    // Drop tables.
    Collection<H2TableDescriptor> rmvTbls = new HashSet<>();
    for (H2TableDescriptor tbl : schema.tables()) {
        if (F.eq(tbl.cacheName(), cacheName)) {
            try {
                tbl.table().setRemoveIndexOnDestroy(rmvIdx);
                dropTable(tbl, rmvIdx);
            } catch (Exception e) {
                U.error(log, "Failed to drop table on cache stop (will ignore): " + tbl.fullTableName(), e);
            }
            schema.drop(tbl);
            rmvTbls.add(tbl);
            GridH2Table h2Tbl = tbl.table();
            dataTables.remove(h2Tbl.identifier(), h2Tbl);
        }
    }
    synchronized (schemaMux) {
        if (schema.decrementUsageCount()) {
            schemas.remove(schemaName);
            try {
                dropSchema(schemaName);
            } catch (Exception e) {
                U.error(log, "Failed to drop schema on cache stop (will ignore): " + cacheName, e);
            }
        }
    }
    for (H2TableDescriptor tbl : rmvTbls) {
        for (Index idx : tbl.table().getIndexes()) idx.close(null);
    }
}
Also used : GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) Index(org.h2.index.Index) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet)

Example 69 with GridH2Table

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

the class SchemaManager method createInitialUserIndex.

/**
 * Add initial user index.
 *
 * @param schemaName Schema name.
 * @param desc Table descriptor.
 * @param h2Idx User index.
 * @throws IgniteCheckedException If failed.
 */
private void createInitialUserIndex(String schemaName, H2TableDescriptor desc, GridH2IndexBase h2Idx) throws IgniteCheckedException {
    GridH2Table h2Tbl = desc.table();
    h2Tbl.proposeUserIndex(h2Idx);
    try {
        String sql = H2Utils.indexCreateSql(desc.fullTableName(), h2Idx, false);
        connMgr.executeStatement(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) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException)

Example 70 with GridH2Table

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

the class SchemaManager method dropIndex.

/**
 * Drop index.
 *
 * @param schemaName Schema name.
 * @param idxName Index name.
 * @param ifExists If exists.
 * @throws IgniteCheckedException If failed.
 */
public void dropIndex(final String schemaName, String idxName, boolean ifExists) throws IgniteCheckedException {
    String sql = H2Utils.indexDropSql(schemaName, idxName, ifExists);
    GridH2Table tbl = dataTableForIndex(schemaName, idxName);
    assert tbl != null;
    tbl.setRemoveIndexOnDestroy(true);
    connMgr.executeStatement(schemaName, sql);
}
Also used : GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)

Aggregations

GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)66 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)26 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)26 GridH2RowDescriptor (org.apache.ignite.internal.processors.query.h2.opt.GridH2RowDescriptor)18 GridSqlColumn (org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn)18 Column (org.h2.table.Column)18 ArrayList (java.util.ArrayList)16 IgniteException (org.apache.ignite.IgniteException)15 HashSet (java.util.HashSet)13 GridSqlElement (org.apache.ignite.internal.processors.query.h2.sql.GridSqlElement)12 GridQueryTypeDescriptor (org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor)11 GridSqlTable (org.apache.ignite.internal.processors.query.h2.sql.GridSqlTable)11 SQLException (java.sql.SQLException)10 List (java.util.List)10 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)10 GridSqlSelect (org.apache.ignite.internal.processors.query.h2.sql.GridSqlSelect)8 Map (java.util.Map)7 IgniteEx (org.apache.ignite.internal.IgniteEx)7 GridQueryProperty (org.apache.ignite.internal.processors.query.GridQueryProperty)7 HashMap (java.util.HashMap)5