public static IndexDefinition map(IndexEntry entry) { return new IndexDefinition(entry.getName(), entry.getKeyHeader(), entry.getValueHeader(), entry.getIndexType()); } }
@RequestMapping(value = "/Instances({instanceId})/Bags({bagName})/Indexes", method = POST, consumes = "application/json", produces = "application/json") public RestEntity writeEntry(@PathVariable String instanceId, @PathVariable String bagName, @RequestBody IndexEntry indexEntry) throws RestException { if(StringUtils.hasText(instanceId) && StringUtils.hasText(bagName)) { try { StorageService storageService = storageServiceFactory.getStorageService(instanceId, bagName); KeyInfo keyInfo = new KeyInfoImpl(indexEntry.getKeyHeader(), indexEntry.getValueHeader()); List<IndexField> indexFields = keyInfo.getIndexKeyFields(); List<IndexField> indexFieldValues = keyInfo.getIndexValueFields(); IndexField[] indexFieldValueArray = indexFieldValues.toArray(new IndexField[indexFieldValues.size()]); if (indexFields.size() > SINGLE_KEY_FIELD) { CompositeIndexField compositeIndexField = new SimpleCompositeIndexField(indexFields.toArray(new IndexField[indexFields.size()])); storageService.ensureIndex(compositeIndexField, indexEntry.isUniqueConstraint(), indexFieldValueArray); } else if (indexFields.size() == SINGLE_KEY_FIELD) { storageService.ensureIndex(indexFields.get(0), indexEntry.isUniqueConstraint(), indexFieldValueArray); } else { throw new RestException("Unable to create index, no key fields specified"); } return indexEntry; } catch (JasDBStorageException e) { throw new RestException("Unable to write index data: " + e.getMessage()); } } else { throw new RestException("No InstanceId or Bag Name where specified when creating index"); } }
private RestEntity loadIndexes(String instanceId, String bagName) throws JasDBException { IndexManager indexManager = getIndexManager(instanceId); StatRecord getIndexCounter = StatisticsMonitor.createRecord("getIndexes"); Map<String, Index> indexes = indexManager.getIndexes(bagName); getIndexCounter.stop(); List<IndexEntry> indexEntries = new ArrayList<>(indexes.size()); for(Index index : indexes.values()) { KeyInfo keyInfo = index.getKeyInfo(); IndexEntry entry = new IndexEntry(keyInfo.getKeyName(), keyInfo.keyAsHeader(), keyInfo.valueAsHeader(), index.hasUniqueConstraint(), index.getIndexType()); entry.setMemorySize(index.getMemoryManager().getTotalMemoryUsage()); indexEntries.add(entry); } return new IndexCollection(indexEntries); }
public static IndexEntry map(IndexDefinition definition, boolean isUnique) { return new IndexEntry(definition.getIndexName(), definition.getHeaderDescriptor(), definition.getValueDescriptor(), isUnique, definition.getIndexType()); }