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 String getInstanceId() { return instanceMeta.getInstanceId(); }
@Override public String getPath() { return instanceMeta.getPath(); } }
protected StorageService createStorageServiceInstance(Instance instance, String bagName) throws JasDBStorageException { return (StorageService) applicationContext.getBean("LocalStorageService", instance.getInstanceId(), bagName); }
private File createIndexFile(String bagName, String indexName, boolean multi) throws JasDBStorageException { StringBuilder indexFileNameBuilder = new StringBuilder(); String extension = multi ? INDEX_EXTENSION_MULTI : INDEX_EXTENSION; indexFileNameBuilder.append(bagName).append(BAG_INDEX_NAME_SPLITTER); indexFileNameBuilder.append(indexName).append(extension); String instancePath = metadataStore.getInstance(instanceId).getPath(); return new File(instancePath, indexFileNameBuilder.toString()); } }
@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()); }
@Override public List<Bag> getBags() throws JasDBStorageException { return metadataStore.getBags(instanceMeta.getInstanceId()); }
private File getWriterPath(String instanceId, String bagName) throws JasDBStorageException { String instancePath = metadataStore.getInstance(instanceId).getPath(); return new File(instancePath, bagName + BAG_EXTENSION); }
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; }
@Override public Bag getBag(String bagName) throws JasDBStorageException { return metadataStore.getBag(instanceMeta.getInstanceId(), bagName); }
@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; }