Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 4b22935

Browse files
author
Alex Walker
authored
API cleanup: close on commit, isX methods (#145)
## What is the goal of this PR? As we close transactions on commit at the server end, it makes sense to also close transactions when they are committed at client side. This change does that. Additionally, for user experience reasons, "isX" functions have been added to the Concept interface to determine what variety of Concept an object represents. ## What are the changes implemented in this PR? We added a try/finally to `commit()` that closes the transaction when it completes or fails. We added is[Concept] functions to all Concepts indicating if the current Concept is an instance of that Concept variety.
1 parent 1cd56f1 commit 4b22935

File tree

6 files changed

+58
-49
lines changed

6 files changed

+58
-49
lines changed

grakn/concept/concept.py

+48
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,33 @@ class Concept(object):
2323
def is_type(self):
2424
return False
2525

26+
def is_thing_type(self):
27+
return False
28+
29+
def is_entity_type(self):
30+
return False
31+
32+
def is_attribute_type(self):
33+
return False
34+
35+
def is_relation_type(self):
36+
return False
37+
38+
def is_role_type(self):
39+
return False
40+
2641
def is_thing(self):
2742
return False
2843

44+
def is_entity(self):
45+
return False
46+
47+
def is_attribute(self):
48+
return False
49+
50+
def is_relation(self):
51+
return False
52+
2953
def is_remote(self):
3054
return False
3155

@@ -44,5 +68,29 @@ def is_deleted(self):
4468
def is_type(self):
4569
return False
4670

71+
def is_thing_type(self):
72+
return False
73+
74+
def is_entity_type(self):
75+
return False
76+
77+
def is_attribute_type(self):
78+
return False
79+
80+
def is_relation_type(self):
81+
return False
82+
83+
def is_role_type(self):
84+
return False
85+
4786
def is_thing(self):
4887
return False
88+
89+
def is_entity(self):
90+
return False
91+
92+
def is_attribute(self):
93+
return False
94+
95+
def is_relation(self):
96+
return False

grakn/concept/thing/thing.py

-18
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ def get_iid(self):
4141
def is_thing(self):
4242
return True
4343

44-
def is_entity(self):
45-
return False
46-
47-
def is_attribute(self):
48-
return False
49-
50-
def is_relation(self):
51-
return False
52-
5344
def __str__(self):
5445
return type(self).__name__ + "[iid:" + self.get_iid() + "]"
5546

@@ -142,15 +133,6 @@ def is_deleted(self):
142133
def is_thing(self):
143134
return True
144135

145-
def is_entity(self):
146-
return False
147-
148-
def is_attribute(self):
149-
return False
150-
151-
def is_relation(self):
152-
return False
153-
154136
def _thing_stream(self, method: concept_proto.Thing.Req, thing_list_getter: Callable[[concept_proto.Thing.Res], List[concept_proto.Thing]]):
155137
method.iid = concept_proto_builder.iid(self.get_iid())
156138
request = transaction_proto.Transaction.Req()

grakn/concept/type/relation_type.py

+3
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,6 @@ def unset_relates(self, role_label: str):
7575
unset_relates_req.label = role_label
7676
method.relation_type_unset_relates_req.CopyFrom(unset_relates_req)
7777
self._execute(method)
78+
79+
def is_relation_type(self):
80+
return True

grakn/concept/type/thing_type.py

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class ThingType(Type):
2828
def as_remote(self, transaction):
2929
return RemoteThingType(transaction, self.get_label(), self.is_root())
3030

31+
def is_thing_type(self):
32+
return True
33+
3134

3235
class RemoteThingType(RemoteType):
3336

grakn/concept/type/type.py

-30
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,6 @@ def is_root(self):
4545
def is_type(self):
4646
return True
4747

48-
def is_thing_type(self):
49-
return False
50-
51-
def is_entity_type(self):
52-
return False
53-
54-
def is_attribute_type(self):
55-
return False
56-
57-
def is_relation_type(self):
58-
return False
59-
60-
def is_role_type(self):
61-
return False
62-
6348
def __str__(self):
6449
return type(self).__name__ + "[label:" + self.get_label() + "]"
6550

@@ -110,21 +95,6 @@ def is_abstract(self):
11095
def is_type(self):
11196
return True
11297

113-
def is_thing_type(self):
114-
return False
115-
116-
def is_entity_type(self):
117-
return False
118-
119-
def is_attribute_type(self):
120-
return False
121-
122-
def is_relation_type(self):
123-
return False
124-
125-
def is_role_type(self):
126-
return False
127-
12898
def set_supertype(self, _type: Type):
12999
req = concept_proto.Type.Req()
130100
supertype_req = concept_proto.Type.SetSupertype.Req()

grakn/rpc/transaction.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ def commit(self):
8989
req = transaction_proto.Transaction.Req()
9090
commit_req = transaction_proto.Transaction.Commit.Req()
9191
req.commit_req.CopyFrom(commit_req)
92-
self._execute(req)
92+
try:
93+
self._execute(req)
94+
finally:
95+
self.close()
9396

9497
def rollback(self):
9598
req = transaction_proto.Transaction.Req()

0 commit comments

Comments
 (0)