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 |
static String |
NORMAL_CACHE_TIMEOUT_MS |
static String |
SHARDING_THRESHOLD |
| Constructor and Description |
|---|
AbstractGraknGraph(G graph,
String keyspace,
String engine,
Properties properties) |
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Reverts any changes done to the graph and closes the transaction.
|
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) |
protected void |
clearGraph() |
void |
close()
Closes the current transaction.
|
void |
closeSession()
Closes the root session this graph stems from.
|
void |
commit()
Commits any changes to the graph and closes the transaction.
|
Optional<String> |
commitNoLogs()
Commits to the graph without submitting any commit logs.
|
LabelId |
convertToId(Label label)
Converts a Type Label into a type Id for this specific graph.
|
void |
delete()
Immediately closes the session and deletes the graph.
|
boolean |
duplicateResourcesExist(String index,
Set<ConceptId> resourceVertexIds)
Check if the given index has duplicates to merge
|
boolean |
fixDuplicateResources(String index,
Set<ConceptId> resourceVertexIds)
Merges the provided duplicate resources
|
<T extends Concept> |
getConcept(ConceptId id)
Get the
Concept with identifier provided, if it exists. |
<T extends Concept> |
getConcept(Schema.VertexProperty key,
Object value) |
EntityType |
getEntityType(String label)
Get the Entity Type with the label provided, if it exists.
|
String |
getKeyspace()
Utility function to get the name of the keyspace where the graph is persisted.
|
OntologyConcept |
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.
|
Role |
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;
|
<T extends OntologyConcept> |
getOntologyConcept(Label label)
Get the
OntologyConcept with the label provided, if it exists. |
RelationType |
getRelationType(String label)
Get the Relation Type with the label 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 label)
Get the Resource Type with the label provided, if it exists.
|
Role |
getRole(String label)
Get the Role Type with the label provided, if it exists.
|
RuleType |
getRuleType(String label)
Get the Rule Type with the label 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(Label label)
Get the
Type with the label provided, if it exists. |
QueryBuilder |
graql()
Returns a QueryBuilder
|
boolean |
implicitConceptsVisible()
Utility function to specify whether implicit concepts should be exposed.
|
boolean |
isBatchGraph()
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) |
boolean |
isReadOnly()
Utility function used to check if the current transaction on the graph is a read only transaction
|
abstract boolean |
isSessionClosed() |
abstract int |
numOpenTx() |
void |
openTransaction(GraknTxType txType)
Opens the thread bound transaction
|
EntityType |
putEntityType(Label label)
Create a new
EntityType with super-type entity, or return a pre-existing EntityType,
with the specified label. |
EntityType |
putEntityType(String label)
Create a new
EntityType with super-type entity, or return a pre-existing EntityType,
with the specified label. |
RelationType |
putRelationType(Label label)
Create a
RelationType with super-type relation, or return a pre-existing RelationType,
with the specified label. |
RelationType |
putRelationType(String label)
Create a
RelationType with super-type relation, or return a pre-existing RelationType,
with the specified label. |
<V> ResourceType<V> |
putResourceType(Label label,
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 label and data type. |
<V> ResourceType<V> |
putResourceType(String label,
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 label and data type. |
Role |
putRole(Label label)
|
Role |
putRole(String label)
|
RuleType |
putRuleType(Label label)
|
RuleType |
putRuleType(String label)
|
void |
shard(ConceptId conceptId)
Creates a new shard for the concept
|
void |
showImplicitConcepts(boolean flag)
Utility function to specify whether implicit and system-generated types should be returned.
|
void |
updateConceptCounts(Map<ConceptId,Long> typeCounts)
Updates the counts of all the types
|
void |
validVertex(org.apache.tinkerpop.gremlin.structure.Vertex vertex) |
protected final org.slf4j.Logger LOG
public static final String SHARDING_THRESHOLD
public static final String NORMAL_CACHE_TIMEOUT_MS
public AbstractGraknGraph(G graph, String keyspace, String engine, Properties properties)
public LabelId convertToId(Label label)
GraknAdminconvertToId in interface GraknAdminlabel - The label to be converted to the idpublic abstract boolean isConceptModified(ai.grakn.graph.internal.ConceptImpl concept)
concept - A concept in the graphpublic abstract int numOpenTx()
public void openTransaction(GraknTxType txType)
public String getKeyspace()
GraknGraphgetKeyspace in interface GraknGraphpublic boolean isClosed()
GraknGraphisClosed in interface GraknGraphpublic abstract boolean isSessionClosed()
public boolean implicitConceptsVisible()
GraknGraphimplicitConceptsVisible in interface GraknGraphpublic boolean isReadOnly()
GraknGraphisReadOnly 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 isBatchGraph()
GraknAdminisBatchGraph in interface GraknAdminpublic 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.VertexProperty key, Object value)
getConcept in interface GraknAdminkey - The concept property tp search by.value - The value of the conceptpublic EntityType putEntityType(String label)
GraknGraphEntityType with super-type entity, or return a pre-existing EntityType,
with the specified label.putEntityType in interface GraknGraphlabel - A unique label for the EntityTypeEntityType with the provided labelpublic EntityType putEntityType(Label label)
GraknGraphEntityType with super-type entity, or return a pre-existing EntityType,
with the specified label.putEntityType in interface GraknGraphlabel - A unique label for the EntityTypeEntityType with the provided labelpublic RelationType putRelationType(String label)
GraknGraphRelationType with super-type relation, or return a pre-existing RelationType,
with the specified label.putRelationType in interface GraknGraphlabel - A unique label for the RelationTypeRelationType with the provided label.public RelationType putRelationType(Label label)
GraknGraphRelationType with super-type relation, or return a pre-existing RelationType,
with the specified label.putRelationType in interface GraknGraphlabel - A unique label for the RelationTypeRelationType with the provided label.public Role putRole(String label)
GraknGraphputRole in interface GraknGraphlabel - A unique label for the RoleRole with the provided Id.public Role putRole(Label label)
GraknGraphputRole in interface GraknGraphlabel - A unique label for the RoleRole with the provided Id.public <V> ResourceType<V> putResourceType(String label, ResourceType.DataType<V> dataType)
GraknGraphResourceType with super-type resource, or return a pre-existing
non-unique ResourceType, with the specified label 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 typelabel - A unique label for the ResourceTypedataType - The data type of the ResourceType.
Supported types include: DataType.STRING, DataType.LONG, DataType.DOUBLE, and DataType.BOOLEANResourceType with the provided label and data type.public <V> ResourceType<V> putResourceType(Label label, ResourceType.DataType<V> dataType)
GraknGraphResourceType with super-type resource, or return a pre-existing
non-unique ResourceType, with the specified label 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 typelabel - A unique label for the ResourceTypedataType - The data type of the ResourceType.
Supported types include: DataType.STRING, DataType.LONG, DataType.DOUBLE, and DataType.BOOLEANResourceType with the provided label and data type.public RuleType putRuleType(String label)
GraknGraphRuleType with super-type rule, or return a pre-existing RuleType, with the
specified label.putRuleType in interface GraknGraphlabel - A unique label for the RuleTypeRuleType with the provided label.public RuleType putRuleType(Label label)
GraknGraphRuleType with super-type rule, or return a pre-existing RuleType, with the
specified label.putRuleType in interface GraknGraphlabel - A unique label for the RuleTypeRuleType with the provided label.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 OntologyConcept> T getOntologyConcept(Label label)
GraknGraphOntologyConcept with the label provided, if it exists.getOntologyConcept in interface GraknGraphlabel - A unique label which identifies the OntologyConcept in the graph.OntologyConcept with the provided label or null if no such OntologyConcept exists.public <T extends Type> T getType(Label label)
GraknGraphType with the label provided, if it exists.getType in interface GraknGraphlabel - A unique label which identifies the Type in the graph.Type with the provided label or null if no such Type exists.public EntityType getEntityType(String label)
GraknGraphgetEntityType in interface GraknGraphlabel - A unique label which identifies the Entity Type in the graph.public RelationType getRelationType(String label)
GraknGraphgetRelationType in interface GraknGraphlabel - A unique label which identifies the Relation Type in the graph.public <V> ResourceType<V> getResourceType(String label)
GraknGraphgetResourceType in interface GraknGraphV - The data type of the value. Supported types include: String, Long, Double, and Boolean.label - A unique label which identifies the Resource Type in the graph.public Role getRole(String label)
GraknGraphgetRole in interface GraknGraphlabel - A unique label which identifies the Role Type in the graph.public RuleType getRuleType(String label)
GraknGraphgetRuleType in interface GraknGraphlabel - A unique label which identifies the Rule Type in the graph.public OntologyConcept getMetaConcept()
GraknAdmingetMetaConcept in interface GraknAdminpublic RelationType getMetaRelationType()
GraknAdmingetMetaRelationType in interface GraknAdminpublic Role 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 void delete()
GraknAdmindelete in interface GraknAdminprotected void clearGraph()
public void closeSession()
GraknAdmincloseSession in interface GraknAdminpublic void close()
GraknGraphGraknSession to
get a new open transaction.close in interface GraknGraphclose in interface AutoCloseablepublic void abort()
GraknGraphGraknSession to
get a new open transaction.abort in interface GraknGraphpublic void commit()
throws InvalidGraphException
GraknGraphGraknSession to
get a new open transaction.commit in interface GraknGraphInvalidGraphException - when the transaction contains graph mutations which does not conform to the Grakn
knowledge model.public Optional<String> commitNoLogs() throws InvalidGraphException
commitNoLogs in interface GraknAdminInvalidGraphException - when the graph does not conform to the object conceptpublic void validVertex(org.apache.tinkerpop.gremlin.structure.Vertex vertex)
public boolean duplicateResourcesExist(String index, Set<ConceptId> resourceVertexIds)
duplicateResourcesExist in interface GraknAdminindex - Index of the potentially duplicated resourceresourceVertexIds - Set of vertex ids containing potential duplicatespublic boolean fixDuplicateResources(String index, Set<ConceptId> resourceVertexIds)
GraknAdminfixDuplicateResources in interface GraknAdminresourceVertexIds - The resource vertex ids which need to be merged.public void updateConceptCounts(Map<ConceptId,Long> typeCounts)
GraknAdminupdateConceptCounts in interface GraknAdmintypeCounts - The concepts and the changes to put on their countspublic void shard(ConceptId conceptId)
GraknAdminshard in interface GraknAdminconceptId - the id of the concept to shardCopyright © 2017 Grakn Labs Ltd. All rights reserved.