G - A vendor specific implementation of a Tinkerpop Graph.public abstract class AbstractGraknGraph<G extends org.apache.tinkerpop.gremlin.structure.Graph> extends Object implements GraknGraph, GraknAdmin
The Grakn Graph Base Implementation
This defines how a grakn graph sits on top of a Tinkerpop Graph.
It mostly act as a construction object which ensure the resulting graph conforms to the Grakn Object model.
| Modifier and Type | Field and Description |
|---|---|
protected org.slf4j.Logger |
LOG |
| Constructor and Description |
|---|
AbstractGraknGraph(G graph,
String keyspace,
String engine,
boolean batchLoadingEnabled) |
| Modifier and Type | Method and Description |
|---|---|
GraknAdmin |
admin()
Returns access to the low-level details of the graph via GraknAdmin
|
<T extends Concept> |
buildConcept(org.apache.tinkerpop.gremlin.structure.Vertex vertex) |
void |
clear()
Clears the graph completely.
|
protected void |
clearGraph() |
void |
close()
Closes the current graph, rendering it unusable.
|
void |
closeGraph(String closedReason) |
void |
closePermanent() |
void |
commit()
Commits the graph
|
void |
commit(java.util.function.BiConsumer<Set<org.javatuples.Pair<String,ConceptId>>,Set<org.javatuples.Pair<String,ConceptId>>> conceptLogger) |
void |
commit(Map<String,Set<ConceptId>> resourceCache,
Map<String,Set<ConceptId>> castingCache)
Commits the graph and adds concepts for post processing directly to the cache
|
void |
commitNoLogs()
Commits to the graph without submitting any commit logs.
|
protected void |
commitTransaction() |
void |
finaliseClose(Runnable closer,
String closedReason) |
boolean |
fixDuplicateCastings(String index,
Set<ConceptId> castingVertexIds)
Merges the provided duplicate castings.
|
boolean |
fixDuplicateResources(String index,
Set<ConceptId> resourceVertexIds) |
<T extends Concept> |
getConcept(ConceptId id)
Get the
Concept with identifier provided, if it exists. |
<T extends Concept> |
getConcept(Schema.ConceptProperty key,
String value) |
<T extends Concept> |
getConceptByBaseIdentifier(Object baseIdentifier) |
EntityType |
getEntityType(String name)
Get the Entity Type with the name provided, if it exists.
|
String |
getKeyspace()
Utility function to get the name of the keyspace where the graph is persisted.
|
Type |
getMetaConcept()
Get the root of all Types.
|
EntityType |
getMetaEntityType()
Get the root of all the Entity Types.
|
RelationType |
getMetaRelationType()
Get the root of all Relation Types.
|
ResourceType |
getMetaResourceType()
Get the root of all the Resource Types.
|
RoleType |
getMetaRoleType()
Get the root of all the Role Types.
|
RuleType |
getMetaRuleConstraint()
Get the root of all constraint rules.
|
RuleType |
getMetaRuleInference()
Get the root of all inference rules.
|
RuleType |
getMetaRuleType()
Get the root of all Rule Types;
|
Relation |
getRelation(RelationType relationType,
Map<RoleType,Instance> roleMap)
Get a Relation that has the specified Relation Type and role map, if it exists.
|
RelationType |
getRelationType(String name)
Get the Relation Type with the name provided, if it exists.
|
<V> Collection<Resource<V>> |
getResourcesByValue(V value)
Get all Resources holding the value provided, if they exist.
|
<V> ResourceType<V> |
getResourceType(String name)
Get the Resource Type with the name provided, if it exists.
|
RoleType |
getRoleType(String name)
Get the Role Type with the name provided, if it exists.
|
RuleType |
getRuleType(String name)
Get the Rule Type with the name provided, if it exists.
|
G |
getTinkerPopGraph() |
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal<org.apache.tinkerpop.gremlin.structure.Vertex,org.apache.tinkerpop.gremlin.structure.Vertex> |
getTinkerTraversal()
Utility function to get a read-only Tinkerpop traversal.
|
<T extends Type> |
getType(TypeName name)
Get the
Type with the name provided, if it exists. |
QueryBuilder |
graql()
Returns a QueryBuilder
|
boolean |
hasCommitted() |
boolean |
implicitConceptsVisible()
Utility function to specify whether implicit concepts should be exposed.
|
boolean |
initialiseMetaConcepts() |
boolean |
isBatchLoadingEnabled()
A flag to check if batch loading is enabled and consistency checks are switched off
|
boolean |
isClosed()
Utility function to determine whether the graph has been closed.
|
abstract boolean |
isConceptModified(ai.grakn.graph.internal.ConceptImpl concept) |
void |
open()
Opens the graph.
|
EntityType |
putEntityType(String name)
Create a new
EntityType with super-type entity, or return a pre-existing EntityType,
with the specified name. |
EntityType |
putEntityType(TypeName name)
Create a new
EntityType with super-type entity, or return a pre-existing EntityType,
with the specified name. |
RelationType |
putRelationType(String name)
Create a
RelationType with super-type relation, or return a pre-existing RelationType,
with the specified name. |
RelationType |
putRelationType(TypeName name)
Create a
RelationType with super-type relation, or return a pre-existing RelationType,
with the specified name. |
<V> ResourceType<V> |
putResourceType(String name,
ResourceType.DataType<V> dataType)
Create a new non-unique
ResourceType with super-type resource, or return a pre-existing
non-unique ResourceType, with the specified name and data type. |
<V> ResourceType<V> |
putResourceType(TypeName name,
ResourceType.DataType<V> dataType)
Create a new non-unique
ResourceType with super-type resource, or return a pre-existing
non-unique ResourceType, with the specified name and data type. |
<V> ResourceType<V> |
putResourceTypeUnique(String name,
ResourceType.DataType<V> dataType)
Create a unique
ResourceType with super-type resource, or return a pre-existing
unique ResourceType, with the specified name and data type. |
<V> ResourceType<V> |
putResourceTypeUnique(TypeName name,
ResourceType.DataType<V> dataType)
Create a unique
ResourceType with super-type resource, or return a pre-existing
unique ResourceType, with the specified name and data type. |
RoleType |
putRoleType(String name)
|
RoleType |
putRoleType(TypeName name)
|
RuleType |
putRuleType(String name)
|
RuleType |
putRuleType(TypeName name)
|
void |
rollback()
Resets the current transaction without committing.
|
void |
showImplicitConcepts(boolean flag)
Utility function to specify whether implicit and system-generated types should be returned.
|
boolean |
validVertex(org.apache.tinkerpop.gremlin.structure.Vertex vertex) |
public abstract boolean isConceptModified(ai.grakn.graph.internal.ConceptImpl concept)
concept - A concept in the graphpublic String getKeyspace()
GraknGraphgetKeyspace in interface GraknGraphpublic boolean isClosed()
GraknGraphisClosed in interface GraknGraphpublic boolean implicitConceptsVisible()
GraknGraphimplicitConceptsVisible in interface GraknGraphpublic void showImplicitConcepts(boolean flag)
GraknGraphshowImplicitConcepts in interface GraknGraphflag - Specifies if implicit and system-generated types should be returned.public GraknAdmin admin()
GraknGraphadmin in interface GraknGraphGraknAdminpublic <T extends Concept> T buildConcept(org.apache.tinkerpop.gremlin.structure.Vertex vertex)
buildConcept in interface GraknAdminT - The type of the concept being builtvertex - A vertex which contains properties necessary to build a concept from.public boolean hasCommitted()
public boolean isBatchLoadingEnabled()
GraknAdminisBatchLoadingEnabled in interface GraknAdminpublic boolean initialiseMetaConcepts()
public G getTinkerPopGraph()
public org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal<org.apache.tinkerpop.gremlin.structure.Vertex,org.apache.tinkerpop.gremlin.structure.Vertex> getTinkerTraversal()
GraknAdmingetTinkerTraversal in interface GraknAdminpublic QueryBuilder graql()
GraknGraphgraql in interface GraknGraphQueryBuilderpublic <T extends Concept> T getConcept(Schema.ConceptProperty key, String value)
getConcept in interface GraknAdminkey - The concept property tp search by.value - The value of the conceptpublic EntityType putEntityType(String name)
GraknGraphEntityType with super-type entity, or return a pre-existing EntityType,
with the specified name.putEntityType in interface GraknGraphname - A unique name for the EntityTypeEntityType with the provided namepublic EntityType putEntityType(TypeName name)
GraknGraphEntityType with super-type entity, or return a pre-existing EntityType,
with the specified name.putEntityType in interface GraknGraphname - A unique name for the EntityTypeEntityType with the provided namepublic RelationType putRelationType(String name)
GraknGraphRelationType with super-type relation, or return a pre-existing RelationType,
with the specified name.putRelationType in interface GraknGraphname - A unique name for the RelationTypeRelationType with the provided name.public RelationType putRelationType(TypeName name)
GraknGraphRelationType with super-type relation, or return a pre-existing RelationType,
with the specified name.putRelationType in interface GraknGraphname - A unique name for the RelationTypeRelationType with the provided name.public RoleType putRoleType(String name)
GraknGraphputRoleType in interface GraknGraphname - A unique name for the RoleTypeRoleType with the provided Id.public RoleType putRoleType(TypeName name)
GraknGraphputRoleType in interface GraknGraphname - A unique name for the RoleTypeRoleType with the provided Id.public <V> ResourceType<V> putResourceType(String name, ResourceType.DataType<V> dataType)
GraknGraphResourceType with super-type resource, or return a pre-existing
non-unique ResourceType, with the specified name and data type.putResourceType in interface GraknGraphV - The data type of the resource type. Supported types include: String, Long, Double, Boolean.
This should match the parameter typename - A unique name for the ResourceTypedataType - The data type of the ResourceType.
Supported types include: DataType.STRING, DataType.LONG, DataType.DOUBLE, and DataType.BOOLEANResourceType with the provided name and data type.public <V> ResourceType<V> putResourceType(TypeName name, ResourceType.DataType<V> dataType)
GraknGraphResourceType with super-type resource, or return a pre-existing
non-unique ResourceType, with the specified name and data type.putResourceType in interface GraknGraphV - The data type of the resource type. Supported types include: String, Long, Double, Boolean.
This should match the parameter typename - A unique name for the ResourceTypedataType - The data type of the ResourceType.
Supported types include: DataType.STRING, DataType.LONG, DataType.DOUBLE, and DataType.BOOLEANResourceType with the provided name and data type.public <V> ResourceType<V> putResourceTypeUnique(String name, ResourceType.DataType<V> dataType)
GraknGraphResourceType with super-type resource, or return a pre-existing
unique ResourceType, with the specified name and data type.
The ResourceType is guaranteed to be unique, in that its instances can be connected to one entity.putResourceTypeUnique in interface GraknGraphV - The data type of the resource type. Supported types include: String, Long, Double, Boolean.
This should match the parameter typename - A unique name for the ResourceTypedataType - The data type of the ResourceType.
Supported types include: DataType.STRING, DataType.LONG, DataType.DOUBLE, and DataType.BOOLEANResourceType with the provided name.public <V> ResourceType<V> putResourceTypeUnique(TypeName name, ResourceType.DataType<V> dataType)
GraknGraphResourceType with super-type resource, or return a pre-existing
unique ResourceType, with the specified name and data type.
The ResourceType is guaranteed to be unique, in that its instances can be connected to one entity.putResourceTypeUnique in interface GraknGraphV - The data type of the resource type. Supported types include: String, Long, Double, Boolean.
This should match the parameter typename - A unique name for the ResourceTypedataType - The data type of the ResourceType.
Supported types include: DataType.STRING, DataType.LONG, DataType.DOUBLE, and DataType.BOOLEANResourceType with the provided name.public RuleType putRuleType(String name)
GraknGraphputRuleType in interface GraknGraphname - A unique name for the RuleTypeRuleType with the provided name.public RuleType putRuleType(TypeName name)
GraknGraphputRuleType in interface GraknGraphname - A unique name for the RuleTypeRuleType with the provided name.public <T extends Concept> T getConceptByBaseIdentifier(Object baseIdentifier)
public <T extends Concept> T getConcept(ConceptId id)
GraknGraphConcept with identifier provided, if it exists.getConcept in interface GraknGraphid - A unique identifier for the Concept in the graph.Concept with the provided id or null if no such Concept exists.public <V> Collection<Resource<V>> getResourcesByValue(V value)
GraknGraphgetResourcesByValue in interface GraknGraphV - The data type of the value. Supported types include: String, Long, Double, and Boolean.value - A value which a Resource in the graph may be holding.public <T extends Type> T getType(TypeName name)
GraknGraphType with the name provided, if it exists.getType in interface GraknGraphname - A unique name which identifies the Type in the graph.Type with the provided name or null if no such Type exists.public EntityType getEntityType(String name)
GraknGraphgetEntityType in interface GraknGraphname - A unique name which identifies the Entity Type in the graph.public RelationType getRelationType(String name)
GraknGraphgetRelationType in interface GraknGraphname - A unique name which identifies the Relation Type in the graph.public <V> ResourceType<V> getResourceType(String name)
GraknGraphgetResourceType in interface GraknGraphV - The data type of the value. Supported types include: String, Long, Double, and Boolean.name - A unique name which identifies the Resource Type in the graph.public RoleType getRoleType(String name)
GraknGraphgetRoleType in interface GraknGraphname - A unique name which identifies the Role Type in the graph.public RuleType getRuleType(String name)
GraknGraphgetRuleType in interface GraknGraphname - A unique name which identifies the Rule Type in the graph.public Type getMetaConcept()
GraknAdmingetMetaConcept in interface GraknAdminpublic RelationType getMetaRelationType()
GraknAdmingetMetaRelationType in interface GraknAdminpublic RoleType getMetaRoleType()
GraknAdmingetMetaRoleType in interface GraknAdminpublic ResourceType getMetaResourceType()
GraknAdmingetMetaResourceType in interface GraknAdminpublic EntityType getMetaEntityType()
GraknAdmingetMetaEntityType in interface GraknAdminpublic RuleType getMetaRuleType()
GraknAdmingetMetaRuleType in interface GraknAdminpublic RuleType getMetaRuleInference()
GraknAdmingetMetaRuleInference in interface GraknAdminpublic RuleType getMetaRuleConstraint()
GraknAdmingetMetaRuleConstraint in interface GraknAdminpublic Relation getRelation(RelationType relationType, Map<RoleType,Instance> roleMap)
GraknGraphnull.
Caller specifies a Relation Type and a role map, which lists the Instances or Resources in the relationship, and the roles each play.getRelation in interface GraknGraphrelationType - The Relation Type which we wish to find a Relation instance of.roleMap - A role map specifying the rolePlayers (Instances or Resources) in the relationship and the roles (Role Types) they play.null if no relationship exists fulfilling the above requirements.public void rollback()
GraknGraphrollback in interface GraknGraphpublic void clear()
clear in interface GraknGraphprotected void clearGraph()
public void close()
close in interface GraknGraphclose in interface AutoCloseablepublic void open()
open in interface GraknGraphpublic void closeGraph(String closedReason)
public void closePermanent()
public void commit()
throws GraknValidationException
commit in interface GraknGraphGraknValidationException - when the graph does not conform to the object conceptpublic void commit(Map<String,Set<ConceptId>> resourceCache, Map<String,Set<ConceptId>> castingCache) throws GraknValidationException
commit in interface GraknAdminresourceCache - The cache of resource jobs to be executedcastingCache - The cache of the casting jobs to be executedGraknValidationException - when the graph does not conform to the object conceptpublic void commitNoLogs()
throws GraknValidationException
commitNoLogs in interface GraknAdminGraknValidationException - when the graph does not conform to the object conceptpublic void commit(java.util.function.BiConsumer<Set<org.javatuples.Pair<String,ConceptId>>,Set<org.javatuples.Pair<String,ConceptId>>> conceptLogger) throws GraknValidationException
GraknValidationExceptionprotected void commitTransaction()
public boolean validVertex(org.apache.tinkerpop.gremlin.structure.Vertex vertex)
validVertex in interface GraknAdminvertex - The vertex to be checked against the underlaying graphpublic boolean fixDuplicateCastings(String index, Set<ConceptId> castingVertexIds)
fixDuplicateCastings in interface GraknAdmincastingVertexIds - The vertex Ids of the duplicate castingspublic boolean fixDuplicateResources(String index, Set<ConceptId> resourceVertexIds)
fixDuplicateResources in interface GraknAdminresourceVertexIds - The resource vertex ids which need to be merged.Copyright © 2017 Grakn Labs Ltd. All rights reserved.