use of ai.grakn.kb.internal.concept.SchemaConceptImpl in project grakn by graknlabs.
the class EmbeddedGraknTx method putSchemaConcept.
/**
* This is a helper method which will either find or create a {@link SchemaConcept}.
* When a new {@link SchemaConcept} is created it is added for validation through it's own creation method for
* example {@link ai.grakn.kb.internal.concept.RoleImpl#create(VertexElement, Role)}.
*
* When an existing {@link SchemaConcept} is found it is build via it's get method such as
* {@link ai.grakn.kb.internal.concept.RoleImpl#get(VertexElement)} and skips validation.
*
* Once the {@link SchemaConcept} is found or created a few checks for uniqueness and correct
* {@link ai.grakn.util.Schema.BaseType} are performed.
*
* @param label The {@link Label} of the {@link SchemaConcept} to find or create
* @param baseType The {@link Schema.BaseType} of the {@link SchemaConcept} to find or create
* @param isImplicit a flag indicating if the label we are creating is for an implicit {@link Type} or not
* @param newConceptFactory the factory to be using when creating a new {@link SchemaConcept}
* @param <T> The type of {@link SchemaConcept} to return
* @return a new or existing {@link SchemaConcept}
*/
private <T extends SchemaConcept> T putSchemaConcept(Label label, Schema.BaseType baseType, boolean isImplicit, Function<VertexElement, T> newConceptFactory) {
checkSchemaMutationAllowed();
// Get the type if it already exists otherwise build a new one
SchemaConceptImpl schemaConcept = getSchemaConcept(convertToId(label));
if (schemaConcept == null) {
if (!isImplicit && label.getValue().startsWith(Schema.ImplicitType.RESERVED.getValue())) {
throw GraknTxOperationException.invalidLabelStart(label);
}
VertexElement vertexElement = addTypeVertex(getNextId(), label, baseType);
// Mark it as implicit here so we don't have to pass it down the constructors
if (isImplicit) {
vertexElement.property(Schema.VertexProperty.IS_IMPLICIT, true);
}
schemaConcept = SchemaConceptImpl.from(buildSchemaConcept(label, () -> newConceptFactory.apply(vertexElement)));
} else if (!baseType.equals(schemaConcept.baseType())) {
throw labelTaken(schemaConcept);
}
// noinspection unchecked
return (T) schemaConcept;
}
Aggregations