@Test public void indexType() { String xml = cacheXml + regionXml + "<index name=\"indexName\" expression=\"expression\" key-index=\"true\"/>" + "</region></cache>"; cacheConfig = service.unMarshall(xml); RegionConfig.Index index = cacheConfig.getRegions().get(0).getIndexes().get(0); assertThat(index.isKeyIndex()).isTrue(); assertThat(index.getName()).isEqualTo("indexName"); assertThat(index.getExpression()).isEqualTo("expression"); assertThat(index.getType()).isEqualTo("range"); }
/** * Sets the value of the type property. Also sets the keyIndex property to true if the type * being set is "key". * * allowed object is * {@link String } * * @deprecated Index should only be a "key" or "range" type which is set using * {@link #setKeyIndex(Boolean)} */ public void setType(String value) { if ("range".equalsIgnoreCase(value) || "hash".equalsIgnoreCase(value) || "key".equalsIgnoreCase(value)) { this.type = value.toLowerCase(); } else { throw new IllegalArgumentException("Invalid index type " + value); } setKeyIndex("key".equalsIgnoreCase(value)); }
@Override public boolean updateConfigForGroup(String group, CacheConfig config, Object configObject) { Set<RegionConfig.Index> updatedIndexes = (Set<RegionConfig.Index>) configObject; if (updatedIndexes == null) { return false; } for (RegionConfig.Index index : updatedIndexes) { RegionConfig regionConfig = getValidRegionConfig(index.getFromClause(), config); if (regionConfig == null) { throw new IllegalStateException("RegionConfig is null"); } regionConfig.getIndexes().add(index); } return true; }
memberId = cache.getDistributedSystem().getDistributedMember().getId(); QueryService queryService = cache.getQueryService(); String indexName = indexInfo.getName(); String regionPath = indexInfo.getFromClause();
String indexName = indexDefinition.getName(); String regionPath = indexDefinition.getFromClause(); String indexedExpression = indexDefinition.getExpression(); IndexType indexType = IndexType.valueOfSynonym(indexDefinition.getType()); new ArrayList<>(multiIndexCreationException.getFailedIndexNames()); List<String> createdIndexes = indexDefinitions.stream().filter(i -> !failedIndexes.contains(i.getName())) .map(RegionConfig.Index::getName).collect(Collectors.toList());
RegionConfig.Index index = new RegionConfig.Index(); index.setName(indexName); index.setExpression(indexedExpression); index.setFromClause(regionPath); if (indexType == IndexType.PRIMARY_KEY) { index.setKeyIndex(true); } else { index.setKeyIndex(false); index.setType(indexType.getName());
RegionConfig.Index indexInfo = new RegionConfig.Index(); indexInfo.setName(indexName); indexInfo.setFromClause(regionName);
RegionConfig.Index indexInfo = new RegionConfig.Index(); indexInfo.setName(indexName); indexInfo.setExpression(indexedExpression); indexInfo.setFromClause(regionPath); indexInfo.setType(indexType.getName());
memberId = cache.getDistributedSystem().getDistributedMember().getId(); QueryService queryService = cache.getQueryService(); String indexName = indexInfo.getName(); String indexedExpression = indexInfo.getExpression(); String fromClause = indexInfo.getFromClause(); if (indexInfo.isKeyIndex()) { queryService.createKeyIndex(indexName, indexedExpression, fromClause); } else if ("hash".equals(indexInfo.getType())) { queryService.createHashIndex(indexName, indexedExpression, fromClause); } else { CliStrings.format(CliStrings.CREATE_INDEX__INDEX__EXISTS, indexInfo.getName()); context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message)); } catch (IndexNameConflictException e) { String message = CliStrings.format(CliStrings.CREATE_INDEX__NAME__CONFLICT, indexInfo.getName()); context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message)); } catch (RegionNotFoundException e) { String message = CliStrings.format(CliStrings.CREATE_INDEX__INVALID__REGIONPATH, indexInfo.getFromClause()); context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message)); } catch (IndexInvalidException e) {
@Override public boolean updateConfigForGroup(String group, CacheConfig config, Object element) { RegionConfig.Index indexFromCommand = (RegionConfig.Index) element; String indexName = indexFromCommand.getName(); String regionName = indexFromCommand.getFromClause(); if (regionName != null) { RegionConfig regionConfig = config.findRegionConfiguration(regionName); if (regionConfig == null) { String errorMessage = "Region " + regionName + " not found"; if (!ConfigurationPersistenceService.CLUSTER_CONFIG.equals(group)) { errorMessage += " in group " + group; } throw new EntityNotFoundException(errorMessage); } if (indexName.isEmpty()) { regionConfig.getIndexes().clear(); } else { CacheElement.removeElement(regionConfig.getIndexes(), indexName); } } else { // Need to search for the index name as region was not specified for (RegionConfig r : config.getRegions()) { CacheElement.removeElement(r.getIndexes(), indexName); } } return true; }
@Override public boolean updateConfigForGroup(String group, CacheConfig config, Object element) { RegionConfig.Index index = (RegionConfig.Index) element; String regionPath = getValidRegionName(index.getFromClause(), config); RegionConfig regionConfig = config.findRegionConfiguration(regionPath); if (regionConfig == null) { throw new EntityNotFoundException("Region " + index.getFromClause() + " not found."); } regionConfig.getIndexes().add(index); return true; } }
@Test public void defaultInexType() throws Exception { DistributedMember member = mock(DistributedMember.class); doReturn(Collections.singleton(member)).when(command).findMembers(any(), any()); ArgumentCaptor<RegionConfig.Index> indexTypeCaptor = ArgumentCaptor.forClass(RegionConfig.Index.class); gfshParser.executeAndAssertThat(command, "create index --name=abc --expression=abc --region=abc"); verify(command).executeAndGetFunctionResult(any(), indexTypeCaptor.capture(), eq(Collections.singleton(member))); assertThat(indexTypeCaptor.getValue().getType()).isEqualTo("range"); }
static void addIndex(String name, String expression, String fromClause, IndexType type) { RegionConfig.Index index = new RegionConfig.Index(); index.setName(name); index.setFromClause(fromClause); index.setType(type.getName()); index.setExpression(expression); indexDefinitions.add(index); } }
@Override public String getId() { return getName(); } }