use of org.apache.geode.cache.query.IndexExistsException in project geode by apache.
the class PartitionedIndex method verifyAndCreateMissingIndex.
/**
* Verify if the index is available of the buckets. If not create index on the bucket.
*/
public void verifyAndCreateMissingIndex(List buckets) throws QueryInvocationTargetException {
PartitionedRegion pr = (PartitionedRegion) this.getRegion();
PartitionedRegionDataStore prds = pr.getDataStore();
for (Object bId : buckets) {
// create index
BucketRegion bukRegion = (BucketRegion) prds.getLocalBucketById((Integer) bId);
if (bukRegion == null) {
throw new QueryInvocationTargetException("Bucket not found for the id :" + bId);
}
IndexManager im = IndexUtils.getIndexManager(bukRegion, true);
if (im != null && im.getIndex(indexName) == null) {
try {
if (pr.getCache().getLogger().fineEnabled()) {
pr.getCache().getLogger().fine("Verifying index presence on bucket region. " + " Found index " + this.indexName + " not present on the bucket region " + bukRegion.getFullPath() + ", index will be created on this region.");
}
ExecutionContext externalContext = new ExecutionContext(null, bukRegion.getCache());
externalContext.setBucketRegion(pr, bukRegion);
im.createIndex(this.indexName, this.type, this.originalIndexedExpression, this.fromClause, this.imports, externalContext, this, true);
} catch (IndexExistsException iee) {
// Index exists.
} catch (IndexNameConflictException ince) {
// ignore.
}
}
}
}
use of org.apache.geode.cache.query.IndexExistsException in project geode by apache.
the class RegionProvider method doInitializeSortedSet.
private void doInitializeSortedSet(ByteArrayWrapper key, Region<?, ?> r) throws RegionNotFoundException, IndexInvalidException {
String fullpath = r.getFullPath();
try {
queryService.createIndex("scoreIndex", "entry.value.score", r.getFullPath() + ".entrySet entry");
queryService.createIndex("scoreIndex2", "value.score", r.getFullPath() + ".values value");
} catch (IndexNameConflictException | IndexExistsException | UnsupportedOperationException e) {
// ignore, these indexes already exist or unsupported but make sure prepared queries are made
}
HashMap<Enum<?>, Query> queryList = new HashMap<Enum<?>, Query>();
for (SortedSetQuery lq : SortedSetQuery.values()) {
String queryString = lq.getQueryString(fullpath);
Query query = this.queryService.newQuery(queryString);
queryList.put(lq, query);
}
this.preparedQueries.put(key, queryList);
}
use of org.apache.geode.cache.query.IndexExistsException in project geode by apache.
the class CreateIndexFunction method execute.
@Override
public void execute(FunctionContext context) {
final IndexInfo indexInfo = (IndexInfo) context.getArguments();
String memberId = null;
try {
Cache cache = CacheFactory.getAnyInstance();
memberId = cache.getDistributedSystem().getDistributedMember().getId();
QueryService queryService = cache.getQueryService();
String indexName = indexInfo.getIndexName();
String indexedExpression = indexInfo.getIndexedExpression();
String fromClause = indexInfo.getRegionPath();
// Check to see if the region path contains an alias e.g "/region1 r1"
// Then the first string will be the regionPath
String[] regionPathTokens = fromClause.trim().split(" ");
String regionPath = regionPathTokens[0];
switch(indexInfo.getIndexType()) {
case IndexInfo.RANGE_INDEX:
queryService.createIndex(indexName, indexedExpression, fromClause);
break;
case IndexInfo.KEY_INDEX:
queryService.createKeyIndex(indexName, indexedExpression, fromClause);
break;
case IndexInfo.HASH_INDEX:
queryService.createHashIndex(indexName, indexedExpression, fromClause);
break;
default:
queryService.createIndex(indexName, indexedExpression, fromClause);
}
regionPath = getValidRegionName(cache, regionPath);
setResultInSender(context, indexInfo, memberId, cache, regionPath);
} catch (IndexExistsException e) {
String message = CliStrings.format(CliStrings.CREATE_INDEX__INDEX__EXISTS, indexInfo.getIndexName());
context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message));
} catch (IndexNameConflictException e) {
String message = CliStrings.format(CliStrings.CREATE_INDEX__NAME__CONFLICT, indexInfo.getIndexName());
context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message));
} catch (RegionNotFoundException e) {
String message = CliStrings.format(CliStrings.CREATE_INDEX__INVALID__REGIONPATH, indexInfo.getRegionPath());
context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message));
} catch (IndexInvalidException e) {
context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage()));
} catch (Exception e) {
String exceptionMessage = CliStrings.format(CliStrings.EXCEPTION_CLASS_AND_MESSAGE, e.getClass().getName(), e.getMessage());
context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage()));
}
}
use of org.apache.geode.cache.query.IndexExistsException in project geode by apache.
the class OrderByPartitionedDUnitTest method createIndex.
private void createIndex(VM vm, final String indexName, IndexType indexType, final String indexedExpression, final String fromClause) {
int indxTypeCode = -1;
if (indexType.equals(IndexType.FUNCTIONAL)) {
indxTypeCode = 0;
} else if (indexType.equals(IndexType.PRIMARY_KEY)) {
indxTypeCode = 1;
} else if (indexType.equals(IndexType.HASH)) {
indxTypeCode = 2;
}
final int finalIndxTypeCode = indxTypeCode;
vm.invoke(new SerializableRunnable("create index") {
public void run() {
try {
Cache cache = getCache();
IndexType indxType = null;
if (finalIndxTypeCode == 0) {
indxType = IndexType.FUNCTIONAL;
} else if (finalIndxTypeCode == 1) {
indxType = IndexType.PRIMARY_KEY;
} else if (finalIndxTypeCode == 2) {
indxType = IndexType.HASH;
}
cache.getQueryService().createIndex(indexName, indxType, indexedExpression, fromClause);
} catch (RegionNotFoundException e) {
fail(e.toString());
} catch (IndexExistsException e) {
fail(e.toString());
} catch (IndexNameConflictException e) {
fail(e.toString());
}
}
});
}
use of org.apache.geode.cache.query.IndexExistsException in project geode by apache.
the class QueryIndexDUnitTest method createIndex.
private static void createIndex() {
Region region = basicGetCache().getRegion("portfolios");
if (region == null) {
logger.info("The region is not created properly");
} else {
if (!region.isDestroyed()) {
logger.info("Obtained the region with name :" + "portfolios");
QueryService qs = basicGetCache().getQueryService();
if (qs != null) {
try {
qs.createIndex("statusIndex", "status", "/portfolios");
logger.info("Index statusIndex Created successfully");
} catch (IndexNameConflictException e) {
Assert.fail("Caught IndexNameConflictException", e);
} catch (IndexExistsException e) {
Assert.fail("Caught IndexExistsException", e);
} catch (QueryException e) {
Assert.fail("Caught exception while trying to create index", e);
}
} else {
fail("Could not obtain QueryService for the cache ");
}
} else {
fail("Region.isDestroyed() returned true for region : " + "/portfolios");
}
}
}
Aggregations