@Override public DBInstance getInstance(String instanceId) throws JasDBStorageException { try { return instanceFactory.getInstance(instanceId); } catch(ConfigurationException e) { throw new JasDBStorageException("Unable to retrieve instance: " + instanceId, e); } }
public ClonableDataStream getStream() throws JasDBStorageException { try { return stream.clone(); } catch(CloneNotSupportedException e) { throw new JasDBStorageException("Unable to clone datastream", e); } }
public static Object getValue(Object mappableObject, PropertyMetadata propertyMetadata) throws JasDBStorageException { Method readMethod = propertyMetadata.getReadMethod(); try { return readMethod.invoke(mappableObject); } catch(InvocationTargetException | IllegalAccessException e) { throw new JasDBStorageException("Unable to read property: " + propertyMetadata, e); } }
@Override public DataBlock writeKey(Key key, DataBlock dataBlock) throws JasDBStorageException { if(key instanceof CompositeKey) { return multiKeyloader.writeKeys(key, dataBlock); } else { throw new JasDBStorageException("Unable to write key not a composite key"); } }
public static <T> TypeMapper<T> getTypeMapper(Class<T> type) throws JasDBStorageException { Optional<TypeMapper> typeMapperOptional = typeMappers.stream().filter(t -> t.isSupportedType(type)).findAny(); if(typeMapperOptional.isPresent()) { return typeMapperOptional.get(); } else { throw new JasDBStorageException("Unable to find type mapper for return type: " + type); } } }
@Override public void writeKey(Key key, int curPosition, ByteBuffer byteBuffer) throws JasDBStorageException { if(key instanceof LongKey) { LongKey longKey = (LongKey) key; byteBuffer.putLong(curPosition, longKey.getKey()); } else { throw new JasDBStorageException("The key is of an unexpected type: " + key.getClass().toString()); } }
public static <T extends Annotation> T getAnnotation(AnnotatedElement type, Class<T> annotationType) throws JasDBStorageException { Optional<T> annotation = getOptionalAnnotation(type, annotationType); if(annotation.isPresent()) { return annotation.get(); } else { throw new JasDBStorageException("Unable to get annotation: " + annotationType); } }
@Override public IndexManager getIndexManager(String instanceId) throws JasDBStorageException { if(!indexManagers.containsKey(instanceId)) { if(metadataStore.containsInstance(instanceId)) { IndexManager indexManager = (IndexManager) applicationContext.getBean("IndexManager", instanceId); indexManagers.putIfAbsent(instanceId, indexManager); } else { throw new JasDBStorageException("Unable to get index manager, instance does not exist"); } } return indexManagers.get(instanceId); }
@Override public void writeKey(Key key, int curPosition, ByteBuffer byteBuffer) throws JasDBStorageException { if(key instanceof CompositeKey) { multiKeyloader.writeKeys(key, curPosition, byteBuffer); } else { throw new JasDBStorageException("Unable to write key not a composite key"); } }
@Override public void removeStorageService(String instanceId, String bagName) throws JasDBStorageException { String storageServiceKey = instanceId + "_" + bagName; StorageService storageService = storageServices.get(storageServiceKey); if(storageService != null) { storageService.remove(); storageServices.remove(storageServiceKey); metadataStore.removeBag(instanceId, bagName); } else { throw new JasDBStorageException("Unable to remove bag, bag does not exist"); } }
private void validateInstance(String instance) throws JasDBStorageException { try { InstanceConnector instanceConnector = RemoteConnectorFactory.createConnector(nodeInformation, InstanceConnector.class); if(instanceConnector.getInstance(getContext(), instance) != null) { this.instance = instance; } else { throw new JasDBStorageException("Instance with id: " + instance + " does not exist"); } } catch(RemoteException e) { throw new JasDBStorageException("Unable to load instance", e); } }
private static Key mapToKey(Value value) throws JasDBStorageException { if(value instanceof StringValue) { return new StringKey(value.toString()); } else if(value instanceof LongValue) { return new LongKey(((LongValue)value).toLong()); } else if(value instanceof IntegerValue) { throw new JasDBStorageException("Not yet implemented"); } else { throw new JasDBStorageException("Unsupported key type: " + value.getClass().getName()); } } }
@Override public void removeBag(String instanceId, String name) throws JasDBStorageException { String bagId = getBagKey(instanceId, name); if(bagMetaMap.containsKey(bagId)) { MetaWrapper<Bag> bagMetaWrapper = bagMetaMap.get(bagId); writer.removeRecord(() -> of(bagMetaWrapper.getRecordPointer()), null); bagMetaMap.remove(bagId); } else { throw new JasDBStorageException("Unable to delete bag: " + name + " does not exist"); } }
@Override public void openWriter() throws JasDBStorageException { try { bucket = cacheManager.getBucket("RecordBucket_" + storeName); wrappedWriter.openWriter(); } catch(CoreConfigException e) { throw new JasDBStorageException("", e); } }
private void doLeaveBlockUpdate(LeaveBlock leaveBlock, Key key) throws JasDBStorageException { if(leaveBlock.contains(key)) { leaveBlock.updateKey(key); } else { throw new JasDBStorageException("Unable to update key: " + key + " cannot be found in the index"); } }
@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 void addInstance(String instanceId) throws JasDBStorageException { if(!metadataStore.containsInstance(instanceId)) { Instance instanceData = metadataStore.addInstance(instanceId); this.instances.put(instanceId, new DBInstanceImpl(storageServiceFactory, metadataStore, instanceData)); } else { throw new JasDBStorageException("Instance with id: " + instanceId + " was already configured, can't override"); } }
private Instance addInstance(String instanceId, String path) throws JasDBStorageException { if(!instanceMetaMap.containsKey(instanceId)) { InstanceMeta instance = new InstanceMeta(instanceId, path); SimpleEntity entity = InstanceMeta.toEntity(instance); String jsonData = SimpleEntity.toJson(entity); long recordPointer = writer.writeRecord(jsonData, null); instanceMetaMap.put(instanceId, new MetaWrapper<>(instance, recordPointer)); return instance; } else { throw new JasDBStorageException("Unable to create instance, already exists"); } }
@Override public DataBlock writeKey(Key key, DataBlock dataBlock) throws JasDBStorageException { if(key instanceof UUIDKey) { UUIDKey uuidKey = (UUIDKey) key; dataBlock = dataBlock.writeLong(uuidKey.getMostSignificant()).getDataBlock(); dataBlock = dataBlock.writeLong(uuidKey.getLeastSignificant()).getDataBlock(); return dataBlock; } else { throw new JasDBStorageException("The key is of an unexpected type: " + key.getClass().toString()); } }
@Override public void updateKey(Key key) throws JasDBStorageException { if(isLeave) { Key foundKey = treeNodes.get(key).getKey(); foundKey.setKeys(key.getKeys()); modified = true; } else { throw new JasDBStorageException("Unable to update key, root is not a leave"); } }