/** * * @return The data type of this {@link Attribute}'s {@link AttributeType}. */ @Override public AttributeType.DataType<D> dataType() { return type().dataType(); }
@Override public final AttributeType.DataType<D> dataType() { return type().dataType(); }
/** * Add a datatype to a resource type var * @param var var to be modified * @param type type from which metadata extracted * @return var with appropriate datatype */ private static VarPattern datatype(VarPattern var, AttributeType type) { AttributeType.DataType dataType = type.dataType(); if (dataType != null) { return var.datatype(dataType); } else { return var; } } }
@SuppressWarnings("unchecked") @Override public <V> AttributeType<V> putAttributeType(Label label, AttributeType.DataType<V> dataType) { @SuppressWarnings("unchecked") AttributeType<V> attributeType = putSchemaConcept(label, Schema.BaseType.ATTRIBUTE_TYPE, false, v -> factory().buildAttributeType(v, getMetaAttributeType(), dataType)); //These checks is needed here because caching will return a type by label without checking the datatype if (Schema.MetaSchema.isMetaLabel(label)) { throw GraknTxOperationException.metaTypeImmutable(label); } else if (!dataType.equals(attributeType.dataType())) { throw GraknTxOperationException.immutableProperty(attributeType.dataType(), dataType, Schema.VertexProperty.DATA_TYPE); } return attributeType; }
/** * Helper method to validate that the target types are of one data type, and get that data type * * @return the DataType of the target types */ @Nullable private AttributeType.DataType<?> validateAndGetTargetDataType() { AttributeType.DataType<?> dataType = null; for (Type type : targetTypes()) { // check if the selected type is a attribute type if (!type.isAttributeType()) throw GraqlQueryException.mustBeAttributeType(type.label()); AttributeType<?> attributeType = type.asAttributeType(); if (dataType == null) { // check if the attribute type has data-type LONG or DOUBLE dataType = attributeType.dataType(); if (!dataType.equals(AttributeType.DataType.LONG) && !dataType.equals(AttributeType.DataType.DOUBLE)) { throw GraqlQueryException.attributeMustBeANumber(dataType, attributeType.label()); } } else { // check if all the attribute types have the same data-type if (!dataType.equals(attributeType.dataType())) { throw GraqlQueryException.attributesWithDifferentDataTypes(query.of().get()); } } } return dataType; }
protected Attribute newResource(AttributeType type) { AttributeType.DataType<?> dataType = type.dataType(); Object value = gen().make(ResourceValues.class).dataType(dataType).generate(random, status); return type.create(value); }
public static <D> AttributeImpl<D> create(VertexElement vertexElement, AttributeType<D> type, Object value) { Object persistenceValue = castValue(type.dataType(), value); AttributeImpl<D> attribute = new AttributeImpl<>(vertexElement, type, persistenceValue); //Generate the index again. Faster than reading String index = Schema.generateAttributeIndex(type.label(), value.toString()); vertexElement.property(Schema.VertexProperty.INDEX, index); //Track the attribute by index vertexElement.tx().txCache().addNewAttribute(index, attribute.id()); return attribute; }
private SchemaConcept putSchemaConcept() { SchemaConcept superConcept = use(SUPER_CONCEPT); Label label = use(LABEL); SchemaConcept concept; if (superConcept.isEntityType()) { concept = executor.tx().putEntityType(label); } else if (superConcept.isRelationshipType()) { concept = executor.tx().putRelationshipType(label); } else if (superConcept.isRole()) { concept = executor.tx().putRole(label); } else if (superConcept.isAttributeType()) { AttributeType attributeType = superConcept.asAttributeType(); AttributeType.DataType<?> dataType = useOrDefault(DATA_TYPE, attributeType.dataType()); concept = executor.tx().putAttributeType(label, dataType); } else if (superConcept.isRule()) { concept = executor.tx().putRule(label, use(WHEN), use(THEN)); } else { throw GraqlQueryException.insertMetaType(label, superConcept); } setSuper(concept, superConcept); return concept; }