@@ -87,16 +87,24 @@ public class GraknClient implements AutoCloseable {
87
87
public static final String DEFAULT_URI = "localhost:48555" ;
88
88
89
89
private ManagedChannel channel ;
90
+ private String username ;
91
+ private String password ;
90
92
private Keyspaces keyspaces ;
91
93
92
94
public GraknClient () {
93
95
this (DEFAULT_URI );
94
96
}
95
97
96
98
public GraknClient (String address ) {
99
+ this (address , null , null );
100
+ }
101
+
102
+ public GraknClient (String address , String username , String password ) {
97
103
SimpleURI parsedURI = new SimpleURI (address );
98
104
channel = ManagedChannelBuilder .forAddress (parsedURI .getHost (), parsedURI .getPort ())
99
105
.usePlaintext (true ).build ();
106
+ this .username = username ;
107
+ this .password = password ;
100
108
keyspaces = new Keyspaces (channel );
101
109
}
102
110
@@ -116,7 +124,7 @@ public void close() {
116
124
}
117
125
118
126
public Session session (String keyspace ) {
119
- return new Session (channel , keyspace );
127
+ return new Session (channel , username , password , keyspace );
120
128
}
121
129
122
130
public Keyspaces keyspaces () {
@@ -131,21 +139,37 @@ public Keyspaces keyspaces() {
131
139
*/
132
140
public static class Session implements grakn .core .api .Session {
133
141
134
- private final ManagedChannel channel ;
135
- private final String keyspace ;
136
- private final SessionServiceGrpc .SessionServiceBlockingStub sessionStub ;
137
- private final String sessionId ;
138
- private boolean isOpen ;
142
+ protected ManagedChannel channel ;
143
+ private String username ;
144
+ private String password ;
145
+ protected String keyspace ;
146
+ protected SessionServiceGrpc .SessionServiceBlockingStub sessionStub ;
147
+ protected String sessionId ;
148
+ protected boolean isOpen ;
139
149
140
- private Session (ManagedChannel channel , String keyspace ) {
150
+ protected Session () {
151
+ }
152
+
153
+ private Session (ManagedChannel channel , String username , String password , String keyspace ) {
141
154
if (!Validator .isValidKeyspaceName (keyspace )) {
142
155
throw GraknClientException .invalidKeyspaceName (keyspace );
143
156
}
157
+ this .username = username ;
158
+ this .password = password ;
144
159
this .keyspace = keyspace ;
145
160
this .channel = channel ;
146
161
this .sessionStub = SessionServiceGrpc .newBlockingStub (channel );
147
162
148
- SessionProto .Session .Open .Res response = sessionStub .open (RequestBuilder .Session .open (keyspace ));
163
+ SessionProto .Session .Open .Req .Builder open = RequestBuilder .Session .open (keyspace ).newBuilderForType ();
164
+ if (username != null ) {
165
+ open = open .setUsername (username );
166
+ }
167
+ if (password != null ) {
168
+ open = open .setPassword (password );
169
+ }
170
+ open = open .setKeyspace (keyspace );
171
+
172
+ SessionProto .Session .Open .Res response = sessionStub .open (open .build ());
149
173
sessionId = response .getSessionId ();
150
174
isOpen = true ;
151
175
}
@@ -172,7 +196,6 @@ public Keyspace keyspace() {
172
196
* Remote implementation of grakn.core.api.Transaction that communicates with a Grakn server using gRPC.
173
197
*/
174
198
public static class Transaction implements grakn .core .api .Transaction {
175
-
176
199
private final Session session ;
177
200
private final Type type ;
178
201
private final Transceiver transceiver ;
@@ -183,7 +206,7 @@ public static class Builder implements grakn.core.api.Transaction.Builder {
183
206
private GraknClient .Session session ;
184
207
private String sessionId ;
185
208
186
- Builder (ManagedChannel channel , GraknClient .Session session , String sessionId ) {
209
+ public Builder (ManagedChannel channel , GraknClient .Session session , String sessionId ) {
187
210
this .channel = channel ;
188
211
this .session = session ;
189
212
this .sessionId = sessionId ;
@@ -200,9 +223,9 @@ public GraknClient.Transaction write() {
200
223
}
201
224
202
225
private Transaction (ManagedChannel channel , Session session , String sessionId , Type type ) {
226
+ this .transceiver = Transceiver .create (SessionServiceGrpc .newStub (channel ));
203
227
this .session = session ;
204
228
this .type = type ;
205
- this .transceiver = Transceiver .create (SessionServiceGrpc .newStub (channel ));
206
229
transceiver .send (RequestBuilder .Transaction .open (sessionId , type ));
207
230
responseOrThrow ();
208
231
}
@@ -541,7 +564,7 @@ public static final class Keyspaces {
541
564
542
565
private KeyspaceServiceBlockingStub keyspaceBlockingStub ;
543
566
544
- private Keyspaces (ManagedChannel channel ) {
567
+ public Keyspaces (ManagedChannel channel ) {
545
568
keyspaceBlockingStub = KeyspaceServiceGrpc .newBlockingStub (channel );
546
569
}
547
570
0 commit comments