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

Commit 345e8ca

Browse files
author
Alex Walker
authored
Unused code cleanup and streaming fixes (typedb#189)
## What is the goal of this PR? To clean up redundant code and fix errors when performing streaming requests. ## What are the changes implemented in this PR? - Clear unused methods from `concept` package - Fix error in `RPCTransaction` when the server sends a `DONE` response and then receives a `CONTINUE` request from the client - this is, in fact, the expected flow and should not trigger an error. - Fix `setLabel` not updating the `label` locally.
1 parent 9d5bff5 commit 345e8ca

19 files changed

+43
-150
lines changed

Grakn.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public interface Grakn {
2828

2929
interface Client extends AutoCloseable {
3030

31-
Session session(String databaseName, Session.Type type);
31+
Session session(String database, Session.Type type);
3232

33-
Session session(String databaseName, Session.Type type, GraknOptions options);
33+
Session session(String database, Session.Type type, GraknOptions options);
3434

3535
DatabaseManager databases();
3636

common/exception/ErrorMessage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static class Concept extends ErrorMessage {
4949
public static final Concept INVALID_CONCEPT_CASTING =
5050
new Concept(1, "Invalid concept conversion from '%s' to '%s'.");
5151
public static final Concept MISSING_TRANSACTION =
52-
new Concept(2, "Transaction can not be null.");
52+
new Concept(2, "Transaction cannot be null.");
5353
public static final Concept MISSING_IID =
5454
new Concept(3, "IID cannot be null or empty.");
5555
public static final Concept MISSING_LABEL =

concept/ConceptManager.java

+14-20
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public EntityType putEntityType(String label) {
8484
@Nullable
8585
@CheckReturnValue
8686
public EntityType getEntityType(String label) {
87-
final Type concept = getType(label);
88-
if (concept instanceof EntityType) return concept.asEntityType();
87+
final Type type = getType(label);
88+
if (type instanceof EntityType) return type.asEntityType();
8989
else return null;
9090
}
9191

@@ -100,8 +100,8 @@ public RelationType putRelationType(String label) {
100100
@Nullable
101101
@CheckReturnValue
102102
public RelationType getRelationType(String label) {
103-
final Type concept = getType(label);
104-
if (concept instanceof RelationType) return concept.asRelationType();
103+
final Type type = getType(label);
104+
if (type instanceof RelationType) return type.asRelationType();
105105
else return null;
106106
}
107107

@@ -117,8 +117,8 @@ public AttributeType putAttributeType(String label, AttributeType.ValueType valu
117117
@Nullable
118118
@CheckReturnValue
119119
public AttributeType getAttributeType(String label) {
120-
final Type concept = getType(label);
121-
if (concept instanceof AttributeType) return concept.asAttributeType();
120+
final Type type = getType(label);
121+
if (type instanceof AttributeType) return type.asAttributeType();
122122
else return null;
123123
}
124124

@@ -139,13 +139,10 @@ public Thing getThing(String iid) {
139139
.setGetThingReq(ConceptProto.ConceptManager.GetThing.Req.newBuilder().setIid(iid(iid))).build();
140140

141141
final ConceptProto.ConceptManager.Res response = execute(req);
142-
switch (response.getGetThingRes().getResCase()) {
143-
case THING:
144-
return ThingImpl.of(response.getGetThingRes().getThing());
145-
default:
146-
case RES_NOT_SET:
147-
return null;
148-
}
142+
if (response.getGetThingRes().getResCase() == ConceptProto.ConceptManager.GetThing.Res.ResCase.THING)
143+
return ThingImpl.of(response.getGetThingRes().getThing());
144+
else
145+
return null;
149146
}
150147

151148
@Nullable
@@ -155,13 +152,10 @@ public Type getType(String label) {
155152
.setGetTypeReq(ConceptProto.ConceptManager.GetType.Req.newBuilder().setLabel(label)).build();
156153

157154
final ConceptProto.ConceptManager.Res response = execute(req);
158-
switch (response.getGetTypeRes().getResCase()) {
159-
case TYPE:
160-
return TypeImpl.of(response.getGetTypeRes().getType());
161-
default:
162-
case RES_NOT_SET:
163-
return null;
164-
}
155+
if (response.getGetTypeRes().getResCase() == ConceptProto.ConceptManager.GetType.Res.ResCase.TYPE)
156+
return TypeImpl.of(response.getGetTypeRes().getType());
157+
else
158+
return null;
165159
}
166160

167161
@Nullable

concept/thing/impl/AttributeImpl.java

-18
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,6 @@ public abstract static class Remote<VALUE> extends ThingImpl.Remote implements A
100100
super(transaction, iid);
101101
}
102102

103-
public static AttributeImpl.Remote<?> of(Grakn.Transaction transaction, ConceptProto.Thing thingProto) {
104-
switch (thingProto.getValueType()) {
105-
case BOOLEAN:
106-
return AttributeImpl.Boolean.Remote.of(transaction, thingProto);
107-
case LONG:
108-
return AttributeImpl.Long.Remote.of(transaction, thingProto);
109-
case DOUBLE:
110-
return AttributeImpl.Double.Remote.of(transaction, thingProto);
111-
case STRING:
112-
return AttributeImpl.String.Remote.of(transaction, thingProto);
113-
case DATETIME:
114-
return AttributeImpl.DateTime.Remote.of(transaction, thingProto);
115-
case UNRECOGNIZED:
116-
default:
117-
throw new GraknClientException(BAD_VALUE_TYPE.message(thingProto.getValueType()));
118-
}
119-
}
120-
121103
@Override
122104
public final Stream<ThingImpl> getOwners() {
123105
return stream(

concept/thing/impl/EntityImpl.java

-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ public Remote(Grakn.Transaction transaction, String iid) {
5151
super(transaction, iid);
5252
}
5353

54-
public static EntityImpl.Remote of(Grakn.Transaction transaction, ConceptProto.Thing protoThing) {
55-
return new EntityImpl.Remote(transaction, Bytes.bytesToHexString(protoThing.getIid().toByteArray()));
56-
}
57-
5854
@Override
5955
public EntityImpl.Remote asRemote(Grakn.Transaction transaction) {
6056
return new EntityImpl.Remote(transaction, getIID());

concept/thing/impl/RelationImpl.java

-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ public Remote(Grakn.Transaction transaction, String iid) {
7272
super(transaction, iid);
7373
}
7474

75-
public static RelationImpl.Remote of(Grakn.Transaction transaction, ConceptProto.Thing protoThing) {
76-
return new RelationImpl.Remote(transaction, Bytes.bytesToHexString(protoThing.getIid().toByteArray()));
77-
}
78-
7975
@Override
8076
public RelationImpl.Remote asRemote(Grakn.Transaction transaction) {
8177
return new RelationImpl.Remote(transaction, getIID());

concept/thing/impl/ThingImpl.java

-15
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,6 @@ public abstract static class Remote implements Thing.Remote {
149149
this.hash = Objects.hash(this.rpcTransaction, this.getIID());
150150
}
151151

152-
public static ThingImpl.Remote of(Grakn.Transaction transaction, ConceptProto.Thing protoThing) {
153-
154-
switch (protoThing.getEncoding()) {
155-
case ENTITY:
156-
return EntityImpl.Remote.of(transaction, protoThing);
157-
case RELATION:
158-
return RelationImpl.Remote.of(transaction, protoThing);
159-
case ATTRIBUTE:
160-
return AttributeImpl.Remote.of(transaction, protoThing);
161-
default:
162-
case UNRECOGNIZED:
163-
throw new GraknClientException(BAD_ENCODING.message(protoThing.getEncoding()));
164-
}
165-
}
166-
167152
@Override
168153
public final String getIID() {
169154
return iid;

concept/type/ThingType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ interface Remote extends Type.Remote, ThingType {
5656

5757
void setPlays(RoleType roleType, RoleType overriddenType);
5858

59-
void setOwns(AttributeType attributeType, AttributeType otherType, boolean isKey);
59+
void setOwns(AttributeType attributeType, AttributeType overriddenType, boolean isKey);
6060

6161
void setOwns(AttributeType attributeType, AttributeType overriddenType);
6262

concept/type/impl/AttributeTypeImpl.java

+2-23
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,6 @@ public static class Remote extends ThingTypeImpl.Remote implements AttributeType
143143
super(transaction, label, isRoot);
144144
}
145145

146-
public static AttributeTypeImpl.Remote of(Grakn.Transaction transaction, ConceptProto.Type typeProto) {
147-
switch (typeProto.getValueType()) {
148-
case BOOLEAN:
149-
return new AttributeTypeImpl.Boolean.Remote(transaction, typeProto.getLabel(), typeProto.getRoot());
150-
case LONG:
151-
return new AttributeTypeImpl.Long.Remote(transaction, typeProto.getLabel(), typeProto.getRoot());
152-
case DOUBLE:
153-
return new AttributeTypeImpl.Double.Remote(transaction, typeProto.getLabel(), typeProto.getRoot());
154-
case STRING:
155-
return new AttributeTypeImpl.String.Remote(transaction, typeProto.getLabel(), typeProto.getRoot());
156-
case DATETIME:
157-
return new AttributeTypeImpl.DateTime.Remote(transaction, typeProto.getLabel(), typeProto.getRoot());
158-
case OBJECT:
159-
assert typeProto.getRoot();
160-
return new AttributeTypeImpl.Remote(transaction, typeProto.getLabel(), typeProto.getRoot());
161-
case UNRECOGNIZED:
162-
default:
163-
throw new GraknClientException(BAD_VALUE_TYPE.message(typeProto.getValueType()));
164-
}
165-
}
166-
167146
@Override
168147
public ValueType getValueType() {
169148
return ValueType.OBJECT;
@@ -229,7 +208,7 @@ protected final AttributeImpl<?> put(Object value) {
229208
final ConceptProto.Type.Req.Builder method = ConceptProto.Type.Req.newBuilder()
230209
.setAttributeTypePutReq(ConceptProto.AttributeType.Put.Req.newBuilder()
231210
.setValue(attributeValue(value)));
232-
return ThingImpl.of(execute(method).getAttributeTypePutRes().getAttribute()).asAttribute();
211+
return AttributeImpl.of(execute(method).getAttributeTypePutRes().getAttribute());
233212
}
234213

235214
@Nullable
@@ -240,7 +219,7 @@ protected final AttributeImpl<?> get(Object value) {
240219
final ConceptProto.AttributeType.Get.Res response = execute(method).getAttributeTypeGetRes();
241220
switch (response.getResCase()) {
242221
case ATTRIBUTE:
243-
return ThingImpl.of(response.getAttribute()).asAttribute();
222+
return AttributeImpl.of(response.getAttribute());
244223
default:
245224
case RES_NOT_SET:
246225
return null;

concept/type/impl/EntityTypeImpl.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424
import grakn.client.concept.thing.impl.ThingImpl;
2525
import grakn.client.concept.type.EntityType;
2626
import grakn.protocol.ConceptProto;
27-
import grakn.protocol.ConceptProto.EntityType.Create;
2827

2928
import java.util.stream.Stream;
3029

3130
public class EntityTypeImpl extends ThingTypeImpl implements EntityType {
3231

33-
public EntityTypeImpl(String label, boolean isRoot) {
32+
EntityTypeImpl(String label, boolean isRoot) {
3433
super(label, isRoot);
3534
}
3635

@@ -50,14 +49,10 @@ public EntityTypeImpl asEntityType() {
5049

5150
public static class Remote extends ThingTypeImpl.Remote implements EntityType.Remote {
5251

53-
public Remote(Grakn.Transaction transaction, String label, boolean isRoot) {
52+
Remote(Grakn.Transaction transaction, String label, boolean isRoot) {
5453
super(transaction, label, isRoot);
5554
}
5655

57-
public static EntityTypeImpl.Remote of(Grakn.Transaction transaction, ConceptProto.Type proto) {
58-
return new EntityTypeImpl.Remote(transaction, proto.getLabel(), proto.getRoot());
59-
}
60-
6156
@Override
6257
public final void setSupertype(EntityType superEntityType) {
6358
this.setSupertypeExecute(superEntityType);
@@ -91,8 +86,8 @@ public final Stream<EntityTypeImpl> getSubtypes() {
9186
@Override
9287
public final EntityImpl create() {
9388
final ConceptProto.Type.Req.Builder method = ConceptProto.Type.Req.newBuilder()
94-
.setEntityTypeCreateReq(Create.Req.getDefaultInstance());
95-
return ThingImpl.of(execute(method).getEntityTypeCreateRes().getEntity()).asEntity();
89+
.setEntityTypeCreateReq(ConceptProto.EntityType.Create.Req.getDefaultInstance());
90+
return EntityImpl.of(execute(method).getEntityTypeCreateRes().getEntity());
9691
}
9792

9893
@Override

concept/type/impl/RelationTypeImpl.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
public class RelationTypeImpl extends ThingTypeImpl implements RelationType {
3535

36-
public RelationTypeImpl(String label, boolean isRoot) {
36+
RelationTypeImpl(String label, boolean isRoot) {
3737
super(label, isRoot);
3838
}
3939

@@ -57,10 +57,6 @@ public Remote(Grakn.Transaction transaction, String label, boolean isRoot) {
5757
super(transaction, label, isRoot);
5858
}
5959

60-
public static RelationTypeImpl.Remote of(Grakn.Transaction transaction, ConceptProto.Type proto) {
61-
return new RelationTypeImpl.Remote(transaction, proto.getLabel(), proto.getRoot());
62-
}
63-
6460
@Override
6561
public final Stream<RelationImpl> getInstances() {
6662
return super.getInstances(ThingImpl::asRelation);
@@ -95,7 +91,7 @@ public final void setSupertype(RelationType type) {
9591
public final RelationImpl create() {
9692
final ConceptProto.Type.Req.Builder method = ConceptProto.Type.Req.newBuilder().setRelationTypeCreateReq(
9793
ConceptProto.RelationType.Create.Req.getDefaultInstance());
98-
return ThingImpl.of(execute(method).getRelationTypeCreateRes().getRelation()).asRelation();
94+
return RelationImpl.of(execute(method).getRelationTypeCreateRes().getRelation());
9995
}
10096

10197
@Override

concept/type/impl/RoleTypeImpl.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class RoleTypeImpl extends TypeImpl implements RoleType {
3636
private final String scope;
3737
private final int hash;
3838

39-
public RoleTypeImpl(String label, String scope, boolean root) {
39+
RoleTypeImpl(String label, String scope, boolean root) {
4040
super(label, root);
4141
this.scope = scope;
4242
this.hash = Objects.hash(this.scope, label);
@@ -92,10 +92,6 @@ public Remote(Grakn.Transaction transaction, String label,
9292
this.hash = Objects.hash(transaction, label, scope);
9393
}
9494

95-
public static RoleTypeImpl.Remote of(Grakn.Transaction transaction, ConceptProto.Type proto) {
96-
return new RoleTypeImpl.Remote(transaction, proto.getLabel(), proto.getScope(), proto.getRoot());
97-
}
98-
9995
@Nullable
10096
@Override
10197
public RoleTypeImpl getSupertype() {

concept/type/impl/RuleImpl.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public int hashCode() {
102102
public static class Remote implements Rule.Remote {
103103

104104
final RPCTransaction rpcTransaction;
105-
private final String label;
105+
private String label;
106106
private final Conjunction<? extends Pattern> when;
107107
private final ThingVariable<?> then;
108108
private final int hash;
@@ -139,6 +139,7 @@ public ThingVariable<?> getThen() {
139139
@Override
140140
public void setLabel(String label) {
141141
execute(ConceptProto.Rule.Req.newBuilder().setRuleSetLabelReq(ConceptProto.Rule.SetLabel.Req.newBuilder().setLabel(label)));
142+
this.label = label;
142143
}
143144

144145
@Override

concept/type/impl/ThingTypeImpl.java

-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ public static class Remote extends TypeImpl.Remote implements ThingType.Remote {
8383
super(transaction, label, isRoot);
8484
}
8585

86-
public static ThingTypeImpl.Remote of(Grakn.Transaction transaction, ConceptProto.Type type) {
87-
return new ThingTypeImpl.Remote(transaction, type.getLabel(), type.getRoot());
88-
}
89-
9086
@Override
9187
public ThingTypeImpl getSupertype() {
9288
return super.getSupertypeExecute(TypeImpl::asThingType);

concept/type/impl/TypeImpl.java

+2-19
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public int hashCode() {
143143
public abstract static class Remote implements Type.Remote {
144144

145145
final RPCTransaction rpcTransaction;
146-
private final String label;
146+
private String label;
147147
private final boolean isRoot;
148148
private final int hash;
149149

@@ -156,24 +156,6 @@ public abstract static class Remote implements Type.Remote {
156156
this.hash = Objects.hash(transaction, label);
157157
}
158158

159-
public static TypeImpl.Remote of(Grakn.Transaction transaction, ConceptProto.Type type) {
160-
switch (type.getEncoding()) {
161-
case ENTITY_TYPE:
162-
return EntityTypeImpl.Remote.of(transaction, type);
163-
case RELATION_TYPE:
164-
return RelationTypeImpl.Remote.of(transaction, type);
165-
case ATTRIBUTE_TYPE:
166-
return AttributeTypeImpl.Remote.of(transaction, type);
167-
case ROLE_TYPE:
168-
return RoleTypeImpl.Remote.of(transaction, type);
169-
case THING_TYPE:
170-
return ThingTypeImpl.Remote.of(transaction, type);
171-
case UNRECOGNIZED:
172-
default:
173-
throw new GraknClientException(BAD_ENCODING.message(type.getEncoding()));
174-
}
175-
}
176-
177159
@Override
178160
public final String getLabel() {
179161
return label;
@@ -193,6 +175,7 @@ public final boolean isRemote() {
193175
public final void setLabel(String label) {
194176
execute(ConceptProto.Type.Req.newBuilder()
195177
.setTypeSetLabelReq(ConceptProto.Type.SetLabel.Req.newBuilder().setLabel(label)));
178+
this.label = label;
196179
}
197180

198181
@Override

dependencies/graknlabs/artifacts.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ def graknlabs_grakn_core_artifacts():
2727
artifact_name = "grakn-core-server-{platform}-{version}.tar.gz",
2828
tag_source = deployment_private["artifact.release"],
2929
commit_source = deployment_private["artifact.snapshot"],
30-
commit = "ab1b7109401b861b82d8ee7b132db6ffd2fdb327",
30+
commit = "75add9c31b68bea8a1d285a133cc3e2dad9e5af5",
3131
)

rpc/QueryFuture.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ public class QueryFuture<T> implements Future<T> {
3333
private final RPCTransaction.ResponseCollector.Single collector;
3434
private final Function<TransactionProto.Transaction.Res, T> transformResponse;
3535

36-
QueryFuture(TransactionProto.Transaction.Req request, StreamObserver<TransactionProto.Transaction.Req> requestObserver,
37-
RPCTransaction.ResponseCollector.Single collector, Function<TransactionProto.Transaction.Res, T> transformResponse) {
36+
QueryFuture(RPCTransaction.ResponseCollector.Single collector, Function<TransactionProto.Transaction.Res, T> transformResponse) {
3837
this.collector = collector;
3938
this.transformResponse = transformResponse;
40-
requestObserver.onNext(request);
4139
}
4240

4341
@Override

0 commit comments

Comments
 (0)