public static UUIDKey getDocumentKey(KeyNameMapper keyNameMapper, Key key) throws JasDBStorageException { Key documentKey = key.getKey(keyNameMapper, "__ID"); if(documentKey != null) { return (UUIDKey) documentKey; } else { throw new JasDBStorageException("No DocumentId present in key value"); } }
@Override public void writeKeys(Key sourceKey, int offset, ByteBuffer keyBuffer) throws JasDBStorageException { int curPosition = offset; for(KeyFactory keyFactory : keyFactories) { Key value = sourceKey.getKey(keyNameMapper, keyFactory.getFieldName()); if(value != null) { keyFactory.writeKey(value, curPosition, keyBuffer); } curPosition += keyFactory.getKeySize(); } }
private void loadNextRecord() { if(indexIterator.hasNext()) { Key key = indexIterator.next(); DataKey dataKey = (DataKey) key.getKey(keyNameMapper, "data"); nextLoadedRecord = new BtreeRecordResult(dataKey); foundRecords++; } else { nextLoadedRecord = null; } }
private Optional<Long> getRecordPointer(UUIDKey documentId) { try { IndexSearchResultIterator resultIterator = index.searchIndex(new EqualsCondition(documentId), Index.NO_SEARCH_LIMIT); if (!resultIterator.isEmpty()) { Key key = resultIterator.next(); LongKey longKey = (LongKey) key.getKey(keyInfo.getKeyNameMapper(), "RECORD_POINTER"); return Optional.of(longKey.getKey()); } else { throw new RecordNotFoundException("Unable to read record: " + documentId + ", could not be found"); } } catch(JasDBStorageException e) { LOG.error("Unable lookup data record for document: {}", documentId); } return Optional.empty(); }
@Override public DataBlock writeKeys(Key sourceKey, DataBlock dataBlock) throws JasDBStorageException { DataBlock currentBlock = dataBlock; for(KeyFactory keyFactory : keyFactories) { Key value = sourceKey.getKey(keyNameMapper, keyFactory.getFieldName()); if(value != null) { currentBlock = keyFactory.writeKey(value, currentBlock); } else { throw new JasDBStorageException("Cannot insert key into index, field: " + keyFactory.getFieldName() + " missing in key: " + sourceKey); } } return currentBlock; }
@Override public RecordResult readRecord(UUIDKey documentId) throws JasDBStorageException { IndexSearchResultIterator resultIterator = index.searchIndex(new EqualsCondition(documentId), Index.NO_SEARCH_LIMIT); if(!resultIterator.isEmpty()) { Key key = resultIterator.next(); DataKey dataKey = (DataKey) key.getKey(keyInfo.getKeyNameMapper(), "data"); return new BtreeRecordResult(dataKey); } else { return new BtreeRecordResult(); } }