public RecordId convertAvroRecordId(ByteBuffer recordId, LRepository repository) { byte[] bytes = new byte[recordId.remaining()]; recordId.get(bytes); return repository.getIdGenerator().fromBytes(bytes); }
public RecordId getRecordId() { if (recordId == null) { recordId = idGenerator.fromBytes(getRow()); } return recordId; }
public static AbsoluteRecordId fromBytes(byte[] bytes, IdGenerator idGenerator) { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); DataInput dataInput = new DataInputStream(byteArrayInputStream); byte[] tableBytes; byte[] recordIdBytes; try { tableBytes = new byte[dataInput.readInt()]; dataInput.readFully(tableBytes, 0, tableBytes.length); recordIdBytes = new byte[dataInput.readInt()]; dataInput.readFully(recordIdBytes, 0, recordIdBytes.length); } catch (IOException ioe) { throw new RuntimeException("Error while deserializing AbsoluteRecordId", ioe); } return new AbsoluteRecordIdImpl(new String(tableBytes), idGenerator.fromBytes(recordIdBytes)); }
/** * Version of #decodeRecord() which returns an {@link IdRecord} instance rather than a {@link Record} instance. */ public IdRecord decodeRecordWithIds(Result result) throws InterruptedException, RepositoryException { Long latestVersion = getLatestVersion(result); RecordId recordId = idGenerator.fromBytes(result.getRow()); return decodeRecordWithIds(recordId, latestVersion, result, typeManager.getFieldTypesSnapshot()); }
/** * Decode the given HBase result into a Lily Record assuming it contains the state of the latest version of * the record (if the record has any versions, otherwise it only contains non-versioned fields). */ public Record decodeRecord(Result result) throws InterruptedException, RepositoryException { Long latestVersion = getLatestVersion(result); RecordId recordId = idGenerator.fromBytes(result.getRow()); return decodeRecord(recordId, latestVersion, null, result, typeManager.getFieldTypesSnapshot()); }
Set<DependencyEntry> deserializeDependenciesForward(byte[] serialized) throws IOException { final DataInputImpl dataInput = new DataInputImpl(serialized); final int nDependencies = dataInput.readInt(); final Set<DependencyEntry> result = new HashSet<DependencyEntry>(nDependencies); while (result.size() < nDependencies) { final int tableLength = dataInput.readInt(); final String table = Bytes.toString(dataInput.readBytes(tableLength)); final int masterBytesLength = dataInput.readInt(); final byte[] masterBytes = dataInput.readBytes(masterBytesLength); final DerefMapVariantPropertiesPattern variantPropertiesPattern = deserializeVariantPropertiesPattern(dataInput); result.add(new DependencyEntry(new AbsoluteRecordIdImpl(table, idGenerator.newRecordId(idGenerator.fromBytes(masterBytes), variantPropertiesPattern.getConcreteProperties())), variantPropertiesPattern.getPatternProperties())); } return result; }
@Override public Set<RecordId> getVariants(RecordId recordId) throws RepositoryException { byte[] masterRecordIdBytes = recordId.getMaster().toBytes(); FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); filterList.addFilter(new PrefixFilter(masterRecordIdBytes)); filterList.addFilter(REAL_RECORDS_FILTER); Scan scan = new Scan(masterRecordIdBytes, filterList); scan.addColumn(RecordCf.DATA.bytes, RecordColumn.DELETED.bytes); Set<RecordId> recordIds = new HashSet<RecordId>(); try { ResultScanner scanner = recordTable.getScanner(scan); Result result; while ((result = scanner.next()) != null) { RecordId id = idGenerator.fromBytes(result.getRow()); recordIds.add(id); } Closer.close( scanner); // Not closed in finally block: avoid HBase contact when there could be connection problems. } catch (IOException e) { throw new RepositoryException("Error getting list of variants of record " + recordId.getMaster(), e); } return recordIds; }
/** * Decodes links from Lily 2.0 and earlier (before table name was added to Link serialization). */ public static Link decode(DataInput dataInput, IdGenerator idGenerator) { // The bytes format is as follows: // [byte representation of master record id, if not null][args: bytes of the string representation] int recordIdLength = dataInput.readInt(); byte[] recordIdBytes = null; if (recordIdLength > 0) { recordIdBytes = dataInput.readBytes(recordIdLength); } String args = dataInput.readUTF(); if (recordIdLength == 0 && args == null) { return new Link(); } LinkBuilder builder = Link.newBuilder(); if (recordIdLength > 0) { RecordId id = idGenerator.fromBytes(recordIdBytes); builder.recordId(id); } if (args != null && args.length() > 0) { argsFromString(args, builder, args /* does not matter, should never be invalid */); } return builder.create(); }
public static Link read(DataInput dataInput, IdGenerator idGenerator) { // Format: see write(DataOutput). int tableLength = dataInput.readInt(); byte[] tableBytes = dataInput.readBytes(tableLength); int recordIdLength = dataInput.readInt(); byte[] recordIdBytes = null; if (recordIdLength > 0) { recordIdBytes = dataInput.readBytes(recordIdLength); } String args = dataInput.readUTF(); if (recordIdLength == 0 && args == null) { return new Link(); } LinkBuilder builder = Link.newBuilder(); if (tableLength > 0) { builder.table(new String(tableBytes)); } if (recordIdLength > 0) { RecordId id = idGenerator.fromBytes(recordIdBytes); builder.recordId(id); } if (args != null && args.length() > 0) { argsFromString(args, builder, args /* does not matter, should never be invalid */); } return builder.create(); }
record.setId(repository.getIdGenerator().fromBytes(idBytes));