protected LazyEntity(final Entity entity, final ElementValueLoader valueLoader, final LazyProperties lazyProperties) { super(entity.getGroup(), null); this.entity = entity; this.valueLoader = valueLoader; this.lazyProperties = lazyProperties; }
@Override public String getGroup() { return entity.getGroup(); }
@Override public Object getIdentifier(final IdentifierType identifierType) { switch (identifierType) { case GROUP: return getGroup(); case VERTEX: return getVertex(); default: return null; } }
@Override public Entity emptyClone() { return new Entity(this.getGroup(), this.getVertex()); }
private Entity cloneCoreFields(final Entity entity) { final Entity newEntity = new Entity(entity.getGroup()); newEntity.setVertex(entity.getVertex()); return newEntity; } }
@Override @Test public void shouldSetAndGetFields() { // Given final Entity entity = new Entity.Builder() .group("group") .vertex("identifier") .build(); // Then assertEquals("group", entity.getGroup()); assertEquals("identifier", entity.getVertex()); }
@Test public void shouldConstructEntity() { // Given final String vertex = "vertex1"; final String propValue = "propValue"; // When final Entity entity = new Entity(TestGroups.ENTITY, vertex); entity.putProperty(TestPropertyNames.STRING, propValue); // Then assertEquals(TestGroups.ENTITY, entity.getGroup()); assertEquals(vertex, entity.getVertex()); assertEquals(propValue, entity.getProperty(TestPropertyNames.STRING)); }
@Test public void shouldBuildEntity() { // Given final String vertex = "vertex1"; final String propValue = "propValue"; // When final Entity entity = new Entity.Builder() .group(TestGroups.ENTITY) .vertex(vertex) .property(TestPropertyNames.STRING, propValue) .build(); // Then assertEquals(TestGroups.ENTITY, entity.getGroup()); assertEquals(vertex, entity.getVertex()); assertEquals(propValue, entity.getProperty(TestPropertyNames.STRING)); }
@Override public String getGroup() { return entity.getGroup(); }
protected LazyEntity(final Entity entity, final ElementValueLoader valueLoader, final LazyProperties lazyProperties) { super(entity.getGroup(), null); this.entity = entity; this.valueLoader = valueLoader; this.lazyProperties = lazyProperties; }
@Override public Object getIdentifier(final IdentifierType identifierType) { switch (identifierType) { case GROUP: return getGroup(); case VERTEX: return getVertex(); default: return null; } }
@Override public Entity emptyClone() { return new Entity(this.getGroup(), this.getVertex()); }
@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); }
@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); }