public static BagMeta fromEntity(Entity entity) throws JasDBStorageException { String instance = entity.getValue(Constants.INSTANCE).toString(); String name = entity.getValue(Constants.NAME).toString(); List<IndexDefinition> indexDefinitionList = new ArrayList<>(); if(entity.hasProperty(Constants.INDEXES)) { for(Object indexDefinition : entity.getValues(Constants.INDEXES)) { indexDefinitionList.add(IndexDefinition.fromHeader(indexDefinition.toString())); } } return new BagMeta(instance, name, indexDefinitionList); }
@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"); } }
private synchronized StorageService createStorageService(String instanceId, String bagName, String key) throws JasDBStorageException { //now we have a lock let's check again if(storageServices.containsKey(key)) { return storageServices.get(key); } else { if(metadataStore.containsInstance(instanceId)) { if(!metadataStore.containsBag(instanceId, bagName)) { metadataStore.addBag(new BagMeta(instanceId, bagName, new ArrayList<IndexDefinition>())); } Instance instance = metadataStore.getInstance(instanceId); StorageService serviceInstance = createStorageServiceInstance(instance, bagName); serviceInstance.openService(configurationLoader.getConfiguration()); storageServices.put(key, serviceInstance); //wrappedInstance); return serviceInstance; } else { throw new JasDBStorageException("Unable to create bag storage service, instance: " + instanceId + " does not exist"); } } }
@Override public EntityBag createOrGetBag(String instanceId, String bagName) throws JasDBStorageException { BagConnector connector = RemoteConnectorFactory.createConnector(nodeInformation, BagConnector.class); Bag meta = connector.getBag(getContext(), instanceId, bagName); if(meta == null) { meta = connector.createBag(getContext(), instanceId, new BagMeta(instanceId, bagName, new ArrayList<IndexDefinition>())); } return new RemoteEntityBag(instanceId, getContext(), nodeInformation, meta); }