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);
}
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);
}
}
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);
}
}
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;
}
}
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);
}
Aggregations