/** * Constructs a by wrapping the provided {@link uk.gov.gchq.gaffer.data.element.Entity} * and using the {@link uk.gov.gchq.gaffer.data.element.ElementValueLoader} to lazily load the element's identifiers and * properties when requested. * * @param entity the entity to wrap. * @param valueLoader the element value loader to use to lazily load the element's identifiers and properties */ public LazyEntity(final Entity entity, final ElementValueLoader valueLoader) { this(entity, valueLoader, new LazyProperties(entity.getProperties(), valueLoader)); }
@Test public void shouldGetLazyProperties() { // Given final Entity entity = new Entity("group"); final ElementValueLoader entityLoader = mock(ElementValueLoader.class); final LazyEntity lazyEntity = new LazyEntity(entity, entityLoader); // When final LazyProperties result = lazyEntity.getProperties(); // Then assertNotNull(result); assertNotSame(entity.getProperties(), result); }
@Test public void shouldLoadIdentifierWhenNotLoaded() { // Given final Entity entity = mock(Entity.class); given(entity.getProperties()).willReturn(mock(Properties.class)); final ElementValueLoader entityLoader = mock(ElementValueLoader.class); final LazyEntity lazyEntity = new LazyEntity(entity, entityLoader); final IdentifierType identifierType = IdentifierType.VERTEX; final String exceptedIdentifierValue = "identifier value"; given(entity.getVertex()).willReturn(exceptedIdentifierValue); // When Object identifierValue = lazyEntity.getIdentifier(identifierType); // Then assertEquals(exceptedIdentifierValue, identifierValue); assertEquals(identifierValue, entity.getVertex()); verify(entityLoader).loadIdentifiers(entity); }
/** * Constructs a by wrapping the provided {@link uk.gov.gchq.gaffer.data.element.Entity} * and using the {@link uk.gov.gchq.gaffer.data.element.ElementValueLoader} to lazily load the element's identifiers and * properties when requested. * * @param entity the entity to wrap. * @param valueLoader the element value loader to use to lazily load the element's identifiers and properties */ public LazyEntity(final Entity entity, final ElementValueLoader valueLoader) { this(entity, valueLoader, new LazyProperties(entity.getProperties(), valueLoader)); }
@Override public Key getKeyFromEntity(final Entity entity) { // Row key is formed from vertex final byte[] rowKey = getRowKeyFromEntity(entity); final byte[] columnFamily = buildColumnFamily(entity.getGroup()); final byte[] columnQualifier = buildColumnQualifier(entity.getGroup(), entity.getProperties()); // Column visibility is formed from the visibility final byte[] columnVisibility = buildColumnVisibility(entity.getGroup(), entity.getProperties()); final long timeStamp = buildTimestamp(entity.getGroup(), entity.getProperties()); // Create and return key return new Key(rowKey, columnFamily, columnQualifier, columnVisibility, timeStamp); }
public void write(final Entity entity) throws SerialisationException { recordConsumer.startMessage(); final int indexPos = writeEntity(entity, schema); writeProperties(entity.getProperties(), schema, indexPos); recordConsumer.endMessage(); }
@Override public void write(final Kryo kryo, final Output output, final Entity entity) { output.writeString(entity.getGroup()); kryo.writeClass(output, entity.getVertex().getClass()); kryo.writeObject(output, entity.getVertex()); kryo.writeObjectOrNull(output, entity.getProperties(), Properties.class); }