@Override public String getInstanceId() { return instanceMeta.getInstanceId(); }
protected StorageService createStorageServiceInstance(Instance instance, String bagName) throws JasDBStorageException { return (StorageService) applicationContext.getBean("LocalStorageService", instance.getInstanceId(), bagName); }
@Override public List<Bag> getBags() throws JasDBStorageException { return metadataStore.getBags(instanceMeta.getInstanceId()); }
@Override public Bag getBag(String bagName) throws JasDBStorageException { return metadataStore.getBag(instanceMeta.getInstanceId(), bagName); }
private void initializeServices() throws JasDBStorageException { for(Instance instanceMeta : metadataStore.getInstances()) { LOG.info("Loading instance: {} on path: {}", instanceMeta.getInstanceId(), instanceMeta.getPath()); instances.put(instanceMeta.getInstanceId(), new DBInstanceImpl(storageServiceFactory, metadataStore, instanceMeta)); } }
@Override public void updateInstance(Instance instance) throws JasDBStorageException { if(instanceMetaMap.containsKey(instance.getInstanceId())) { SimpleEntity entity = InstanceMeta.toEntity(instance); String jsonData = SimpleEntity.toJson(entity); removeInstance(instance.getInstanceId()); long recordPointer = writer.writeRecord(jsonData, null); instanceMetaMap.put(instance.getInstanceId(), new MetaWrapper<>(instance, recordPointer)); } else { throw new JasDBStorageException("Unable to update instance, does not exists"); } }
@Override public void removeBag(String bagName) throws JasDBStorageException { try { storageServiceFactory.removeStorageService(instanceMeta.getInstanceId(), bagName); } catch(ConfigurationException e) { throw new JasDBStorageException("Unable to remove bag", e); } }
@Override public Instance deleteInstance(String instanceId) throws JasDBStorageException { Instance deleteInstance = getInstance(instanceId); //in case we are deleting the current connected instance let's switch to default context if(this.instance != null && deleteInstance.getInstanceId().equals(this.instance.getInstanceId())) { this.instance = instanceFactory.getInstance(); } instanceFactory.deleteInstance(instanceId); return this.instance; }
@Test public void testGetInstances() throws JasDBException { DBSession session = sessionFactory.createSession(); List<Instance> instanceList = session.getInstances(); assertEquals(1, instanceList.size()); Instance instance = instanceList.get(0); assertEquals("default", instance.getInstanceId()); assertEquals(jasdbHome, new File(instance.getPath()).toString()); }
public static SimpleEntity toEntity(Instance instance) { SimpleEntity entity = new SimpleEntity(); entity.addProperty(Constants.META_TYPE, Constants.INSTANCE_TYPE); entity.addProperty(Constants.INSTANCE, instance.getInstanceId()); entity.addProperty(Constants.INSTANCE_PATH, instance.getPath()); return entity; }