@Override public boolean containsIndex(String instanceId, String bagName, IndexDefinition indexDefinition) throws JasDBStorageException { Bag bag = getBag(instanceId, bagName); return bag.getIndexDefinitions().contains(indexDefinition); }
private synchronized void loadIndexes(final String bagName) throws JasDBStorageException { LOG.debug("Loading indexes for bag: {}", bagName); if(!indexes.containsKey(bagName)) { Bag bag = metadataStore.getBag(instanceId, bagName); if(bag != null) { Set<IndexDefinition> indexDefinitions = new HashSet<>(bag.getIndexDefinitions()); LOG.info("Found {} potential indexes for bag: {}", indexDefinitions.size(), bagName); Map<String, Index> bagIndexes = new HashMap<>(); for(IndexDefinition indexDefinition : indexDefinitions) { Index index = loadIndex(bagName, indexDefinition); bagIndexes.put(index.getKeyInfo().getKeyName(), index); } this.indexes.put(bagName, bagIndexes); } } }
@Override public void removeBagIndex(String instanceId, String bagName, IndexDefinition indexDefinition) throws JasDBStorageException { Bag bag = getBag(instanceId, bagName); if(bag != null) { List<IndexDefinition> indexDefinitions = new ArrayList<>(bag.getIndexDefinitions()); if(indexDefinitions.contains(indexDefinition)) { indexDefinitions.remove(indexDefinition); updateBag(instanceId, bagName, new BagMeta(instanceId, bagName, indexDefinitions)); } } else { throw new JasDBStorageException("Unable to remove index for bag: " + bagName + ",could not be found"); } }
@Override public void addBagIndex(String instanceId, String bagName, IndexDefinition indexDefinition) throws JasDBStorageException { Bag bag = getBag(instanceId, bagName); if(bag != null) { List<IndexDefinition> indexDefinitions = new ArrayList<>(bag.getIndexDefinitions()); if(!indexDefinitions.contains(indexDefinition)) { indexDefinitions.add(indexDefinition); updateBag(instanceId, bagName, new BagMeta(instanceId, bagName, indexDefinitions)); } } else { throw new JasDBStorageException("Unable to add index to bag: " + bagName + ",could not be found"); } }
public static SimpleEntity toEntity(Bag bag) throws JasDBStorageException { SimpleEntity entity = new SimpleEntity(); entity.addProperty(Constants.META_TYPE, Constants.BAG_TYPE); entity.addProperty(Constants.INSTANCE, bag.getInstanceId()); entity.addProperty(Constants.NAME, bag.getName()); for(IndexDefinition indexDefinition : bag.getIndexDefinitions()) { entity.addProperty(Constants.INDEXES, indexDefinition.toHeader()); } return entity; }