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; }
@Override public CompareResult compare(Key o, CompareMethod method) { if(o != null) { if(o instanceof CompositeKey) { CompositeKey localKey = new CompositeKey(); localKey.setKeys(new Key[] {this}); localKey.setValueMarker(1); return localKey.compare(o, method); } else { return evaluateKey(o); } } else { throw new RuntimeJasDBException("Cannot compare null Key"); } }
public SecureUserSession(UserSession userSession) { this.sessionId = userSession.getSessionId(); this.user = userSession.getUser(); this.encryptedContentKey = userSession.getEncryptedContentKey(); try { CryptoEngine cryptoEngine = CryptoFactory.getEngine(); accessTokenHash = cryptoEngine.hash(sessionId, userSession.getAccessToken()); } catch(JasDBSecurityException e) { throw new RuntimeJasDBException("Unable to hash token", e); } }
@Override public void writeRecord(UUIDKey documentId, ClonableDataStream dataStream) throws JasDBStorageException { String recordContents = RecordStreamUtil.toString(dataStream); writer.writeRecord(recordContents, p -> { try { index.insertIntoIndex(documentId.cloneKey(false).addKey(keyInfo.getKeyNameMapper(), "RECORD_POINTER", new LongKey(p))); } catch(JasDBStorageException e) { try { removeRecord(documentId); } catch (JasDBStorageException e1) { LOG.error("", e); } throw new RuntimeJasDBException("Unable to write record already exists", e); } }); }