private void checkClosed() { if(closed) { throw new RuntimeJasDBException("Query cursor is closed"); } }
@Override public void removeGrant(String userName) { throw new RuntimeJasDBException("Grant not allowed to be modified"); } }
@Override public List<?> mapToRawType(Object value) { if(value instanceof List) { return (List<?>) value; } else { throw new RuntimeJasDBException("Invalid type, cannot cast object: " + value + " to a list"); } }
@Override public Map<String, ?> mapToRawType(Object value) { if(value instanceof Map) { return (Map<String, ?>) value; } else { throw new RuntimeJasDBException("Invalid type, cannot cast object: " + value + " to a map"); } }
@Override public Long mapToRawType(Object value) { if(value instanceof Long) { return (Long)value; } else if(value instanceof Integer) { int v = (Integer) value; return (long) v; } else { throw new RuntimeJasDBException("Unable to map value: " + value); } }
@Override public Object getValue() { throw new RuntimeJasDBException("Not implemented"); }
@Override public void addGrant(Grant grant) { throw new RuntimeJasDBException("Grant not allowed to be modified"); }
@Override public Key cloneKey() { throw new RuntimeJasDBException("Not implemented"); }
@Override public Key cloneKey(boolean includeChildren) { throw new RuntimeJasDBException("Not implemented"); }
@Override public int compareTo(Key o) { throw new RuntimeJasDBException("Cannot use data key for compare or sorting"); }
public void close() { if(inputStream != null) { try { inputStream.close(); } catch(IOException e) { throw new RuntimeJasDBException("Unable to cleanly close connection", e); } } }
public static byte[] getUnicodeBytes(String data) { try { return data.getBytes(DEFAULT_ENCODING); } catch(UnsupportedEncodingException e) { throw new RuntimeJasDBException("Unable to retrieve unicode key, character set invalid", e); } }
public static String getUnicodeString(byte[] data) { try { return new String(data, DEFAULT_ENCODING).trim(); } catch(UnsupportedEncodingException e) { throw new RuntimeJasDBException("Unable to load unicode key, character set invalid", e); } } }
public String getEntityAsString() { if(inputStream != null) { try { BufferedReader read = new BufferedReader(new InputStreamReader(inputStream)); String r = read.readLine(); read.close(); return r; } catch(IOException e) { throw new RuntimeJasDBException("Unable to load entity as string", e); } } else { return null; } }
private void setValue(Object instance, Object value, PropertyMetadata v) { try { v.getWriteMethod().invoke(instance, value); } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeJasDBException("Unable to set field value on entity: " + instance.getClass(), e); } }
public static Key recordToKey(RecordResult recordResult) { try { Entity entity = toEntity(recordResult.getStream()); return entityToKey(entity); } catch (JasDBStorageException e) { throw new RuntimeJasDBException("Unable to read record Document Id", e); } }
@Override public Property mapToProperty(String propertyName, Object value) { Property property = new MultivalueProperty(propertyName, true); List<?> values = mapToRawType(value); values.forEach(v -> { try { TypeMapper typeMapper = getTypeMapper(v.getClass()); property.addValue(typeMapper.mapToValue(v)); } catch (JasDBStorageException e) { throw new RuntimeJasDBException("Unable to map list", e); } }); return property; }
throw new RuntimeJasDBException("The remote client url is invalid", e); } catch(UnsupportedEncodingException e) { throw new RemoteException("Unsupported encoding", e);
private void handleIndexScanAndRebuild() throws JasDBStorageException { Collection<Index> indexes = getIndexManager().getIndexes(bagName).values(); List<Future<?>> indexRebuilds = new ArrayList<>(indexes.size()); LOG.info("Doing index scan for: {} items", getSize()); RecordWriter recordWriter = recordWriterFactoryLoader.loadRecordWriter(instanceId, bagName); if(recordWriter instanceof TransactionalRecordWriter) { TransactionalRecordWriter transactionalRecordWriter = (TransactionalRecordWriter) recordWriter; LOG.info("Forcing primary key rebuild first, we need to ensure integrity"); transactionalRecordWriter.verify(recordResult -> { try { return new UUIDKey(BagOperationUtil.toEntity(recordResult.getStream()).getInternalId()); } catch (JasDBStorageException e) { throw new RuntimeJasDBException("Unable to read jasdb entitiy", e); } }); } for(final Index index : indexes) { LOG.info("Scheduling index rebuild of index: {} for bag: {}", index, bagName); indexRebuilds.add(indexRebuilder.submit(new IndexScanAndRecovery(index, getRecordWriter().readAllRecords()))); } for(Future<?> indexRebuild : indexRebuilds) { try { indexRebuild.get(); } catch(ExecutionException | InterruptedException e) { throw new JasDBStorageException("Unable to initialize bag, index rebuild failed", e); } } }
entity.addProperty(property); } else if(!v.isNullable()) { throw new RuntimeJasDBException("Unable to map property: " + v + " value is null"); throw new RuntimeJasDBException("Unable to map property: " + v, e);