@Override public <V> Collection<Attribute<V>> getAttributesByValue(V value) { if (value == null) return Collections.emptySet(); //Make sure you trying to retrieve supported data type if (!AttributeType.DataType.SUPPORTED_TYPES.containsKey(value.getClass().getName())) { throw GraknTxOperationException.unsupportedDataType(value); } HashSet<Attribute<V>> attributes = new HashSet<>(); AttributeType.DataType dataType = AttributeType.DataType.SUPPORTED_TYPES.get(value.getClass().getTypeName()); //noinspection unchecked getConcepts(dataType.getVertexProperty(), dataType.getPersistenceValue(value)).forEach(concept -> { if (concept != null && concept.isAttribute()) { //noinspection unchecked attributes.add(concept.asAttribute()); } }); return attributes; }
@Override public final <S, E> GraphTraversal<S, E> applyPredicate(GraphTraversal<S, E> traversal) { var.ifPresent(theVar -> { // Compare to another variable String thisVar = UUID.randomUUID().toString(); Var otherVar = theVar.var(); String otherValue = UUID.randomUUID().toString(); Traversal[] traversals = Stream.of(VALUE_PROPERTIES) .map(prop -> __.values(prop).as(otherValue).select(thisVar).values(prop).where(gremlinPredicate(otherValue))) .toArray(Traversal[]::new); traversal.as(thisVar).select(otherVar.name()).or(traversals).select(thisVar); }); persistedValue().ifPresent(theValue -> { // Compare to a given value DataType<?> dataType = DataType.SUPPORTED_TYPES.get(value().get().getClass().getTypeName()); Schema.VertexProperty property = dataType.getVertexProperty(); traversal.has(property.name(), gremlinPredicate(theValue)); }); return traversal; }
/** * * @param value The value to store on the resource */ private void setValue(Object value) { Schema.VertexProperty property = dataType().getVertexProperty(); //noinspection unchecked vertex().propertyImmutable(property, value, vertex().property(property)); }
/** * * @return The value casted to the correct type */ @Override public D value(){ return dataType().getValue(vertex().property(dataType().getVertexProperty())); }