@Override protected final T generateFromTx() { T thing; S type = genFromTx(generatorClass).makeExcludeAbstractTypes().excludeMeta().generate(random, status); //noinspection unchecked Collection<T> instances = (Collection<T> ) type.instances().collect(toSet()); if (instances.isEmpty()) { thing = newInstance(type); } else { thing = random.choose(instances); } if(withResource && !thing.attributes().findAny().isPresent()){ //A new attribute type is created every time a attribute is lacking. //Existing attribute types and resources of those types are not used because we end up mutating the // the schema in strange ways. This approach is less complex but ensures everything has a attribute // without conflicting with the schema //Create a new attribute type AttributeType.DataType<?> dataType = gen(AttributeType.DataType.class); Label label = genFromTx(Labels.class).mustBeUnused().generate(random, status); AttributeType attributeType = tx().putAttributeType(label, dataType); //Create new attribute Attribute attribute = newResource(attributeType); //Link everything together type.has(attributeType); thing.has(attribute); } return thing; }
@Override public Collection<PropertyExecutor> define(Var var) throws GraqlQueryException { PropertyExecutor.Method method = executor -> { Type entityTypeConcept = executor.get(var).asType(); AttributeType attributeTypeConcept = executor.get(resourceType().var()).asAttributeType(); if (required()) { entityTypeConcept.key(attributeTypeConcept); } else { entityTypeConcept.has(attributeTypeConcept); } }; return ImmutableSet.of(PropertyExecutor.builder(method).requires(var, resourceType().var()).build()); }
cluster.has(name); tx.getType(Schema.ImplicitType.HAS.getLabel("title")).has(provenance);