use of org.vertexium.Property in project vertexium by visallo.
the class SetClauseExecutor method executeSetVariable.
private void executeSetVariable(VertexiumCypherQueryContext ctx, CypherSetVariable setItem, VertexiumCypherScope.Item item) {
Object left = ctx.getExpressionExecutor().executeExpression(ctx, setItem.getLeft(), item);
VertexiumCypherTypeErrorException.assertType(left, Element.class, null);
if (left == null) {
return;
}
Object values = ctx.getExpressionExecutor().executeExpression(ctx, setItem.getRight(), item);
CypherSetItem.Op op = setItem.getOp();
if (values instanceof Stream) {
values = ((Stream<?>) values).collect(Collectors.toList());
}
if (values instanceof List && ((List) values).size() == 1) {
values = ((List) values).get(0);
}
VertexiumCypherTypeErrorException.assertType(values, Map.class, Element.class);
if (values instanceof Element) {
values = ctx.getElementPropertiesAsMap((Element) values);
}
Element element = (Element) left;
// noinspection unchecked
Map<String, ?> valuesMap = (Map<String, ?>) values;
ExistingElementMutation<Element> m = element.prepareMutation();
if (op == CypherSetItem.Op.EQUAL) {
for (Property property : element.getProperties()) {
if (ctx.isLabelProperty(property)) {
continue;
}
if (!valuesMap.containsKey(property.getName())) {
ctx.removeProperty(m, property.getName());
}
}
}
for (Map.Entry<String, ?> valuesMapEntry : valuesMap.entrySet()) {
String propertyName = valuesMapEntry.getKey();
Object value = valuesMapEntry.getValue();
if (value instanceof CypherLiteral) {
value = ((CypherLiteral) value).getValue();
}
if (value == null) {
ctx.removeProperty(m, propertyName);
} else {
ctx.setProperty(m, propertyName, value);
}
}
ctx.saveElement(m);
}
use of org.vertexium.Property in project vertexium by visallo.
the class CypherResultWriter method elementPropertiesToString.
private String elementPropertiesToString(VertexiumCypherQueryContext ctx, Element element) {
StringBuilder result = new StringBuilder();
boolean first = true;
for (Property property : element.getProperties()) {
if (property.getName().equals(ctx.getLabelPropertyName())) {
continue;
}
if (first) {
result.append("{");
} else {
result.append(", ");
}
result.append(property.getName());
result.append(": ");
result.append(columnValueToString(ctx, property.getValue()));
first = false;
}
if (result.length() > 0) {
result.append("}");
}
return result.toString();
}
use of org.vertexium.Property in project vertexium by visallo.
the class PropertyCollection method removeProperties.
public synchronized Iterable<Property> removeProperties(String name) {
List<Property> removedProperties = new ArrayList<>();
Map<String, ConcurrentSkipListSet<Property>> propertiesByKey = propertiesByNameAndKey.get(name);
if (propertiesByKey != null) {
for (ConcurrentSkipListSet<Property> properties : propertiesByKey.values()) {
for (Property property : properties) {
removedProperties.add(property);
}
}
}
for (Property property : removedProperties) {
removeProperty(property);
}
return removedProperties;
}
use of org.vertexium.Property in project vertexium by visallo.
the class DataInputStreamUtils method decodeProperties.
public static Iterable<Property> decodeProperties(AccumuloGraph graph, DataInputStream in, List<MetadataEntry> metadataEntries, FetchHints fetchHints) throws IOException {
List<Property> results = new ArrayList<>();
while (true) {
int propId = in.read();
if (propId == ElementData.PROP_END) {
break;
} else if (propId != ElementData.PROP_START) {
throw new IOException("Unexpected prop id: " + propId);
}
String propertyKey = graph.getNameSubstitutionStrategy().inflate(decodeString(in));
String propertyName = graph.getNameSubstitutionStrategy().inflate(decodeString(in));
Visibility propertyVisibility = new Visibility(decodeString(in));
long propertyTimestamp = in.readLong();
int propertyValueLength = in.readInt();
byte[] propertyValue = new byte[propertyValueLength];
int read = in.read(propertyValue);
if (read != propertyValueLength) {
throw new IOException("Unexpected data length expected " + propertyValueLength + " found " + read);
}
Set<String> propertyHiddenVisibilitiesStringSet = decodeStringSet(in);
Set<Visibility> propertyHiddenVisibilities = null;
if (propertyHiddenVisibilitiesStringSet != null) {
propertyHiddenVisibilities = propertyHiddenVisibilitiesStringSet.stream().map(Visibility::new).collect(Collectors.toSet());
}
LazyPropertyMetadata metadata = decodePropertyMetadata(in, metadataEntries);
results.add(new LazyMutableProperty(graph, graph.getVertexiumSerializer(), propertyKey, propertyName, propertyValue, metadata, propertyHiddenVisibilities, propertyVisibility, propertyTimestamp, fetchHints));
}
return results;
}
use of org.vertexium.Property in project vertexium by visallo.
the class CypherResultWriter method columnVertexToString.
private String columnVertexToString(VertexiumCypherQueryContext ctx, Vertex vertex) {
StringBuilder result = new StringBuilder();
result.append("(");
int propertyCount = 0;
for (Property property : vertex.getProperties()) {
if (property.getName().equals(ctx.getLabelPropertyName())) {
result.append(":");
result.append(property.getValue());
} else {
propertyCount++;
}
}
if (propertyCount > 0) {
if (result.length() > "(".length()) {
result.append(" ");
}
result.append(elementPropertiesToString(ctx, vertex));
}
result.append(")");
return result.toString();
}
Aggregations