Skip to content

Commit 30cd219

Browse files
Add autoclosable to session (#41)
## What is the goal of this PR? Previous PR #39 neglected to implement `AutoClosable` on `Session`, which is expected in Grakn Core for now ## What are the changes implemented in this PR? * Implement `AutoClosable`
1 parent c909167 commit 30cd219

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

GraknClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public Keyspaces keyspaces() {
133133
* @see Transaction
134134
* @see GraknClient
135135
*/
136-
public static class Session {
136+
public static class Session implements AutoCloseable {
137137

138138
protected ManagedChannel channel;
139139
private String username; // TODO: Do we need to save this? It's not used.

rpc/RequestBuilder.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import grakn.client.GraknClient;
2323
import grakn.client.concept.AttributeType;
24+
import grakn.client.concept.Concept;
2425
import grakn.client.concept.ConceptId;
2526
import grakn.client.concept.Label;
2627
import grakn.client.exception.GraknClientException;
@@ -162,14 +163,14 @@ public static SessionProto.Transaction.Req iterate(int iteratorId) {
162163
*/
163164
public static class ConceptMessage {
164165

165-
public static ConceptProto.Concept from(grakn.client.concept.Concept concept) {
166+
public static ConceptProto.Concept from(Concept concept) {
166167
return ConceptProto.Concept.newBuilder()
167168
.setId(concept.id().getValue())
168169
.setBaseType(getBaseType(concept))
169170
.build();
170171
}
171172

172-
private static ConceptProto.Concept.BASE_TYPE getBaseType(grakn.client.concept.Concept concept) {
173+
private static ConceptProto.Concept.BASE_TYPE getBaseType(Concept concept) {
173174
if (concept.isEntityType()) {
174175
return ConceptProto.Concept.BASE_TYPE.ENTITY_TYPE;
175176
} else if (concept.isRelationType()) {
@@ -193,7 +194,7 @@ private static ConceptProto.Concept.BASE_TYPE getBaseType(grakn.client.concept.C
193194
}
194195
}
195196

196-
public static Collection<ConceptProto.Concept> concepts(Collection<grakn.client.concept.Concept> concepts) {
197+
public static Collection<ConceptProto.Concept> concepts(Collection<Concept> concepts) {
197198
return concepts.stream().map(ConceptMessage::from).collect(toList());
198199
}
199200

@@ -222,42 +223,42 @@ public static ConceptProto.ValueObject attributeValue(Object value) {
222223
return builder.build();
223224
}
224225

225-
public static grakn.client.concept.AttributeType.DataType dataType(ConceptProto.AttributeType.DATA_TYPE dataType) {
226+
public static AttributeType.DataType dataType(ConceptProto.AttributeType.DATA_TYPE dataType) {
226227
switch (dataType) {
227228
case STRING:
228-
return grakn.client.concept.AttributeType.DataType.STRING;
229+
return AttributeType.DataType.STRING;
229230
case BOOLEAN:
230-
return grakn.client.concept.AttributeType.DataType.BOOLEAN;
231+
return AttributeType.DataType.BOOLEAN;
231232
case INTEGER:
232-
return grakn.client.concept.AttributeType.DataType.INTEGER;
233+
return AttributeType.DataType.INTEGER;
233234
case LONG:
234-
return grakn.client.concept.AttributeType.DataType.LONG;
235+
return AttributeType.DataType.LONG;
235236
case FLOAT:
236-
return grakn.client.concept.AttributeType.DataType.FLOAT;
237+
return AttributeType.DataType.FLOAT;
237238
case DOUBLE:
238-
return grakn.client.concept.AttributeType.DataType.DOUBLE;
239+
return AttributeType.DataType.DOUBLE;
239240
case DATE:
240-
return grakn.client.concept.AttributeType.DataType.DATE;
241+
return AttributeType.DataType.DATE;
241242
default:
242243
case UNRECOGNIZED:
243244
throw new IllegalArgumentException("Unrecognised " + dataType);
244245
}
245246
}
246247

247-
static ConceptProto.AttributeType.DATA_TYPE setDataType(grakn.client.concept.AttributeType.DataType dataType) {
248-
if (dataType.equals( grakn.client.concept.AttributeType.DataType.STRING)) {
248+
static ConceptProto.AttributeType.DATA_TYPE setDataType(AttributeType.DataType dataType) {
249+
if (dataType.equals( AttributeType.DataType.STRING)) {
249250
return ConceptProto.AttributeType.DATA_TYPE.STRING;
250-
} else if (dataType.equals( grakn.client.concept.AttributeType.DataType.BOOLEAN)) {
251+
} else if (dataType.equals( AttributeType.DataType.BOOLEAN)) {
251252
return ConceptProto.AttributeType.DATA_TYPE.BOOLEAN;
252-
} else if (dataType.equals( grakn.client.concept.AttributeType.DataType.INTEGER)) {
253+
} else if (dataType.equals( AttributeType.DataType.INTEGER)) {
253254
return ConceptProto.AttributeType.DATA_TYPE.INTEGER;
254-
} else if (dataType.equals( grakn.client.concept.AttributeType.DataType.LONG)) {
255+
} else if (dataType.equals( AttributeType.DataType.LONG)) {
255256
return ConceptProto.AttributeType.DATA_TYPE.LONG;
256-
} else if (dataType.equals( grakn.client.concept.AttributeType.DataType.FLOAT)) {
257+
} else if (dataType.equals( AttributeType.DataType.FLOAT)) {
257258
return ConceptProto.AttributeType.DATA_TYPE.FLOAT;
258-
} else if (dataType.equals( grakn.client.concept.AttributeType.DataType.DOUBLE)) {
259+
} else if (dataType.equals( AttributeType.DataType.DOUBLE)) {
259260
return ConceptProto.AttributeType.DATA_TYPE.DOUBLE;
260-
} else if (dataType.equals( grakn.client.concept.AttributeType.DataType.DATE)) {
261+
} else if (dataType.equals( AttributeType.DataType.DATE)) {
261262
return ConceptProto.AttributeType.DATA_TYPE.DATE;
262263
} else {
263264
throw GraknClientException.unreachableStatement("Unrecognised " + dataType);

0 commit comments

Comments
 (0)