Skip to content

Commit f5b6b4a

Browse files
authored
Formats all Java snippets to be indented consistently (#125)
1 parent d7ba735 commit f5b6b4a

File tree

1 file changed

+50
-54
lines changed

1 file changed

+50
-54
lines changed

README.md

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ grab via Maven:
4949
<artifactId>dgraph4j</artifactId>
5050
<version>2.0.1</version>
5151
</dependency>
52-
5352
```
5453
or Gradle:
5554
```groovy
@@ -140,10 +139,10 @@ side-effects.
140139
```java
141140
Transaction txn = dgraphClient.newTransaction();
142141
try {
143-
// Do something here
144-
// ...
142+
// Do something here
143+
// ...
145144
} finally {
146-
txn.discard();
145+
txn.discard();
147146
}
148147
```
149148

@@ -173,8 +172,8 @@ This data will be serialized into JSON.
173172

174173
```java
175174
class Person {
176-
String name
177-
Person() {}
175+
String name
176+
Person() {}
178177
}
179178
```
180179

@@ -189,10 +188,9 @@ person.name = "Alice";
189188
Gson gson = new Gson();
190189
String json = gson.toJson(p);
191190
// Run mutation
192-
Mutation mu =
193-
Mutation.newBuilder()
194-
.setSetJson(ByteString.copyFromUtf8(json.toString()))
195-
.build();
191+
Mutation mu = Mutation.newBuilder()
192+
.setSetJson(ByteString.copyFromUtf8(json.toString()))
193+
.build();
196194
txn.mutate(mu);
197195
```
198196

@@ -204,8 +202,8 @@ Mutation can be run using the `doRequest` function as well.
204202

205203
```java
206204
Request request = Request.newBuilder()
207-
.addMutations(mu)
208-
.build();
205+
.addMutations(mu)
206+
.build();
209207
txn.doRequest(request);
210208
```
211209

@@ -221,17 +219,17 @@ modified in this transaction. It is up to the user to retry transactions when th
221219
Transaction txn = dgraphClient.newTransaction();
222220

223221
try {
224-
 //
225-
// Perform any number of queries and mutations
226-
 //
227-
 // and finally …
228-
 txn.commit()
222+
//
223+
// Perform any number of queries and mutations
224+
//
225+
// and finally …
226+
txn.commit()
229227
} catch (TxnConflictException ex) {
230-
// Retry or handle exception.
228+
// Retry or handle exception.
231229
} finally {
232-
// Clean up. Calling this after txn.commit() is a no-op
233-
// and hence safe.
234-
txn.discard();
230+
// Clean up. Calling this after txn.commit() is a no-op
231+
// and hence safe.
232+
txn.discard();
235233
}
236234
```
237235

@@ -257,8 +255,8 @@ First we must create a `People` class that will help us deserialize the JSON res
257255

258256
```java
259257
class People {
260-
List<Person> all;
261-
People() {}
258+
List<Person> all;
259+
People() {}
262260
}
263261
```
264262

@@ -294,8 +292,8 @@ You can also use `doRequest` function to run the query.
294292

295293
```java
296294
Request request = Request.newBuilder()
297-
.setQuery(query)
298-
.build();
295+
.setQuery(query)
296+
.build();
299297
txn.doRequest(request);
300298
```
301299

@@ -312,15 +310,14 @@ https://docs.dgraph.io/mutations/#upsert-block.
312310
String query = "query {\n" +
313311
"user as var(func: eq(email, \"[email protected]\"))\n" +
314312
"}\n";
315-
Mutation mu =
316-
Mutation.newBuilder()
317-
.setSetNquads(ByteString.copyFromUtf8("uid(user) <email> \"[email protected]\" ."))
318-
.build();
313+
Mutation mu = Mutation.newBuilder()
314+
.setSetNquads(ByteString.copyFromUtf8("uid(user) <email> \"[email protected]\" ."))
315+
.build();
319316
Request request = Request.newBuilder()
320-
.setQuery(query)
321-
.addMutations(mu)
322-
.setCommitNow(true)
323-
.build();
317+
.setQuery(query)
318+
.addMutations(mu)
319+
.setCommitNow(true)
320+
.build();
324321
txn.doRequest(request);
325322
```
326323

@@ -335,11 +332,10 @@ See more about Conditional Upsert [Here](https://docs.dgraph.io/mutations/#condi
335332
String query = "query {\n" +
336333
"user as var(func: eq(email, \"[email protected]\"))\n" +
337334
"}\n";
338-
Mutation mu =
339-
Mutation.newBuilder()
340-
.setSetNquads(ByteString.copyFromUtf8("uid(user) <email> \"[email protected]\" ."))
341-
.setCond("@if(eq(len(user), 1))")
342-
.build();
335+
Mutation mu = Mutation.newBuilder()
336+
.setSetNquads(ByteString.copyFromUtf8("uid(user) <email> \"[email protected]\" ."))
337+
.setCond("@if(eq(len(user), 1))")
338+
.build();
343339
Request request = Request.newBuilder()
344340
.setQuery(query)
345341
.addMutations(mu)
@@ -357,11 +353,11 @@ Read [this forum post][deadline-post] for more details.
357353
channel = ManagedChannelBuilder.forAddress("localhost", 9080).usePlaintext(true).build();
358354
DgraphGrpc.DgraphStub stub = DgraphGrpc.newStub(channel);
359355
ClientInterceptor timeoutInterceptor = new ClientInterceptor(){
360-
@Override
361-
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
362-
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
363-
return next.newCall(method, callOptions.withDeadlineAfter(500, TimeUnit.MILLISECONDS));
364-
}
356+
@Override
357+
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
358+
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
359+
return next.newCall(method, callOptions.withDeadlineAfter(500, TimeUnit.MILLISECONDS));
360+
}
365361
};
366362
stub.withInterceptors(timeoutInterceptor);
367363
DgraphClient dgraphClient = new DgraphClient(stub);
@@ -381,7 +377,7 @@ DgraphStub stub = DgraphGrpc.newStub(channel);
381377
// use MetadataUtils to augment the stub with headers
382378
Metadata metadata = new Metadata();
383379
metadata.put(
384-
Metadata.Key.of("auth-token", Metadata.ASCII_STRING_MARSHALLER), "the-auth-token-value");
380+
Metadata.Key.of("auth-token", Metadata.ASCII_STRING_MARSHALLER), "the-auth-token-value");
385381
stub = MetadataUtils.attachHeaders(stub, metadata);
386382

387383
// create the DgraphClient wrapper around the stub
@@ -399,9 +395,9 @@ The helper method takes an existing mutation, and returns a new mutation
399395
with the deletions applied.
400396

401397
```java
402-
Mutation mu = Mutation.newBuilder().build()
403-
mu = Helpers.deleteEdges(mu, uid, "friends", "loc");
404-
dgraphClient.newTransaction().mutate(mu);
398+
Mutation mu = Mutation.newBuilder().build()
399+
mu = Helpers.deleteEdges(mu, uid, "friends", "loc");
400+
dgraphClient.newTransaction().mutate(mu);
405401
```
406402

407403
### Closing the DB Connection
@@ -456,16 +452,16 @@ If you would like to see the latency for either a mutation or
456452
query request, the latency field in the returned result can be helpful. Here is an example to log
457453
the latency of a query request:
458454
```java
459-
Response resp = txn.query(query);
460-
Latency latency = resp.getLatency();
461-
logger.info("parsing latency:" + latency.getParsingNs());
462-
logger.info("processing latency:" + latency.getProcessingNs());
463-
logger.info("encoding latency:" + latency.getEncodingNs());
455+
Response resp = txn.query(query);
456+
Latency latency = resp.getLatency();
457+
logger.info("parsing latency:" + latency.getParsingNs());
458+
logger.info("processing latency:" + latency.getProcessingNs());
459+
logger.info("encoding latency:" + latency.getEncodingNs());
464460
```
465461
Similarly you can get the latency of a mutation request:
466462
```java
467-
Assigned assignedIds = dgraphClient.newTransaction().mutate(mu);
468-
Latency latency = assignedIds.getLatency();
463+
Assigned assignedIds = dgraphClient.newTransaction().mutate(mu);
464+
Latency latency = assignedIds.getLatency();
469465
```
470466

471467
## Development

0 commit comments

Comments
 (0)