use of org.vertexium.property.PropertyValue in project vertexium by visallo.
the class AccumuloElement method addPropertyInternal.
protected void addPropertyInternal(Property property) {
if (property.getKey() == null) {
throw new IllegalArgumentException("key is required for property");
}
Object propertyValue = property.getValue();
if (propertyValue instanceof PropertyValue && !((PropertyValue) propertyValue).isStore()) {
return;
}
Property existingProperty = getProperty(property.getKey(), property.getName(), property.getVisibility());
if (existingProperty == null) {
this.properties.addProperty(property);
} else {
if (existingProperty instanceof MutableProperty) {
((MutableProperty) existingProperty).update(property);
} else {
throw new VertexiumException("Could not update property of type: " + existingProperty.getClass().getName());
}
}
}
use of org.vertexium.property.PropertyValue in project vertexium by visallo.
the class GraphTestBase method testStreamingPropertyValueMarkResetLargeReads.
@Test
public void testStreamingPropertyValueMarkResetLargeReads() throws IOException {
assumeTrue("InputStream mark/reset is not supported", isInputStreamMarkResetSupported());
String expectedLargeValue = IOUtils.toString(new LargeStringInputStream(LARGE_PROPERTY_VALUE_SIZE));
byte[] expectedLargeValueBytes = expectedLargeValue.getBytes();
PropertyValue propLarge = StreamingPropertyValue.create(new ByteArrayInputStream(expectedLargeValue.getBytes()), String.class);
graph.prepareVertex("v1", VISIBILITY_A).setProperty("propLarge", propLarge, VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
graph.flush();
Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
StreamingPropertyValue prop = (StreamingPropertyValue) v1.getPropertyValue("propLarge");
InputStream in = prop.getInputStream();
int amountToRead = expectedLargeValueBytes.length - 8;
byte[] buffer = null;
while (amountToRead > 0) {
buffer = new byte[amountToRead];
amountToRead -= in.read(buffer);
}
assertEquals(expectedLargeValue.charAt(expectedLargeValue.length() - 9), (char) buffer[buffer.length - 1]);
in.mark(32);
buffer = new byte[2];
int sizeRead = in.read(buffer);
assertEquals(2, sizeRead);
assertEquals(expectedLargeValue.charAt(expectedLargeValue.length() - 8), (char) buffer[0]);
assertEquals(expectedLargeValue.charAt(expectedLargeValue.length() - 7), (char) buffer[1]);
assertEquals(expectedLargeValue.charAt(expectedLargeValue.length() - 6), (char) in.read());
in.reset();
sizeRead = in.read(buffer);
assertEquals(2, sizeRead);
assertEquals(expectedLargeValue.charAt(expectedLargeValue.length() - 8), (char) buffer[0]);
}
use of org.vertexium.property.PropertyValue in project vertexium by visallo.
the class GraphTestBase method testAddStreamingPropertyValue.
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
@Test
public void testAddStreamingPropertyValue() throws IOException, InterruptedException {
String expectedLargeValue = IOUtils.toString(new LargeStringInputStream(LARGE_PROPERTY_VALUE_SIZE));
PropertyValue propSmall = StreamingPropertyValue.create(new ByteArrayInputStream("value1".getBytes()), String.class, 6L);
PropertyValue propLarge = StreamingPropertyValue.create(new ByteArrayInputStream(expectedLargeValue.getBytes()), String.class, null);
String largePropertyName = "propLarge/\\*!@#$%^&*()[]{}|";
Vertex v1 = graph.prepareVertex("v1", VISIBILITY_A).setProperty("propSmall", propSmall, VISIBILITY_A).setProperty(largePropertyName, propLarge, VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
graph.flush();
Iterable<Object> propSmallValues = v1.getPropertyValues("propSmall");
Assert.assertEquals(1, count(propSmallValues));
Object propSmallValue = propSmallValues.iterator().next();
assertTrue("propSmallValue was " + propSmallValue.getClass().getName(), propSmallValue instanceof StreamingPropertyValue);
StreamingPropertyValue value = (StreamingPropertyValue) propSmallValue;
assertEquals(String.class, value.getValueType());
assertEquals("value1".getBytes().length, (long) value.getLength());
assertEquals("value1", IOUtils.toString(value.getInputStream()));
assertEquals("value1", IOUtils.toString(value.getInputStream()));
Iterable<Object> propLargeValues = v1.getPropertyValues(largePropertyName);
Assert.assertEquals(1, count(propLargeValues));
Object propLargeValue = propLargeValues.iterator().next();
assertTrue(largePropertyName + " was " + propLargeValue.getClass().getName(), propLargeValue instanceof StreamingPropertyValue);
value = (StreamingPropertyValue) propLargeValue;
assertEquals(String.class, value.getValueType());
assertEquals(expectedLargeValue.getBytes().length, (long) value.getLength());
assertEquals(expectedLargeValue, IOUtils.toString(value.getInputStream()));
assertEquals(expectedLargeValue, IOUtils.toString(value.getInputStream()));
graph.flush();
v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
propSmallValues = v1.getPropertyValues("propSmall");
Assert.assertEquals(1, count(propSmallValues));
propSmallValue = propSmallValues.iterator().next();
assertTrue("propSmallValue was " + propSmallValue.getClass().getName(), propSmallValue instanceof StreamingPropertyValue);
value = (StreamingPropertyValue) propSmallValue;
assertEquals(String.class, value.getValueType());
assertEquals("value1".getBytes().length, (long) value.getLength());
assertEquals("value1", IOUtils.toString(value.getInputStream()));
assertEquals("value1", IOUtils.toString(value.getInputStream()));
propLargeValues = v1.getPropertyValues(largePropertyName);
Assert.assertEquals(1, count(propLargeValues));
propLargeValue = propLargeValues.iterator().next();
assertTrue(largePropertyName + " was " + propLargeValue.getClass().getName(), propLargeValue instanceof StreamingPropertyValue);
value = (StreamingPropertyValue) propLargeValue;
assertEquals(String.class, value.getValueType());
assertEquals(expectedLargeValue.getBytes().length, (long) value.getLength());
assertEquals(expectedLargeValue, IOUtils.toString(value.getInputStream()));
assertEquals(expectedLargeValue, IOUtils.toString(value.getInputStream()));
}
use of org.vertexium.property.PropertyValue in project vertexium by visallo.
the class GraphTestBase method testChangeVisibilityOnStreamingProperty.
@Test
public void testChangeVisibilityOnStreamingProperty() throws IOException {
String expectedLargeValue = IOUtils.toString(new LargeStringInputStream(LARGE_PROPERTY_VALUE_SIZE));
PropertyValue propSmall = StreamingPropertyValue.create(new ByteArrayInputStream("value1".getBytes()), String.class);
PropertyValue propLarge = StreamingPropertyValue.create(new ByteArrayInputStream(expectedLargeValue.getBytes()), String.class);
String largePropertyName = "propLarge/\\*!@#$%^&*()[]{}|";
graph.prepareVertex("v1", VISIBILITY_A).setProperty("propSmall", propSmall, VISIBILITY_A).setProperty(largePropertyName, propLarge, VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
graph.flush();
Assert.assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties()));
graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A).prepareMutation().alterPropertyVisibility("propSmall", VISIBILITY_B).save(AUTHORIZATIONS_A_AND_B);
graph.flush();
Assert.assertEquals(1, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties()));
graph.getVertex("v1", FetchHints.ALL, AUTHORIZATIONS_A).prepareMutation().alterPropertyVisibility(largePropertyName, VISIBILITY_B).save(AUTHORIZATIONS_A_AND_B);
graph.flush();
Assert.assertEquals(0, count(graph.getVertex("v1", AUTHORIZATIONS_A).getProperties()));
Assert.assertEquals(2, count(graph.getVertex("v1", AUTHORIZATIONS_A_AND_B).getProperties()));
}
use of org.vertexium.property.PropertyValue in project vertexium by visallo.
the class GraphTestBase method testStreamingPropertyValueLargeReads.
@Test
public void testStreamingPropertyValueLargeReads() throws IOException {
String expectedLargeValue = IOUtils.toString(new LargeStringInputStream(LARGE_PROPERTY_VALUE_SIZE));
byte[] expectedLargeValueBytes = expectedLargeValue.getBytes();
PropertyValue propLarge = StreamingPropertyValue.create(new ByteArrayInputStream(expectedLargeValue.getBytes()), String.class);
graph.prepareVertex("v1", VISIBILITY_A).setProperty("propLarge", propLarge, VISIBILITY_A).save(AUTHORIZATIONS_A_AND_B);
graph.flush();
Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A);
StreamingPropertyValue prop = (StreamingPropertyValue) v1.getPropertyValue("propLarge");
byte[] buffer = new byte[LARGE_PROPERTY_VALUE_SIZE * 2];
int leftToRead = expectedLargeValueBytes.length;
InputStream in = prop.getInputStream();
for (int expectedOffset = 0; expectedOffset < expectedLargeValueBytes.length; ) {
int sizeRead = in.read(buffer);
for (int j = 0; j < sizeRead; j++, expectedOffset++, leftToRead--) {
assertEquals("invalid data at offset " + expectedOffset, expectedLargeValueBytes[expectedOffset], buffer[j]);
}
}
assertEquals(0, leftToRead);
assertEquals(-1, in.read(buffer));
}
Aggregations