48
48
import java .util .concurrent .ExecutorService ;
49
49
import java .util .concurrent .Executors ;
50
50
import java .util .concurrent .TimeUnit ;
51
+ import java .util .stream .Collectors ;
51
52
52
53
public class Main {
53
54
private final ExecutorService executorService ;
@@ -96,13 +97,14 @@ public static void main(String[] args) {
96
97
97
98
try {
98
99
p .getStartedDemo ();
99
- System .out .println (String .format ("Demo complete, please hold while resources are deleted " ));
100
+ System .out .println (String .format ("Demo complete, please hold while resources are released " ));
100
101
} catch (Exception e ) {
101
102
System .err .println (String .format ("DocumentDB GetStarted failed with %s" , e ));
102
103
} finally {
103
104
System .out .println ("close the client" );
104
105
p .close ();
105
106
}
107
+ System .exit (0 );
106
108
}
107
109
108
110
private void getStartedDemo () throws Exception {
@@ -112,7 +114,7 @@ private void getStartedDemo() throws Exception {
112
114
.withServiceEndpoint (AccountSettings .HOST )
113
115
.withMasterKeyOrResourceToken (AccountSettings .MASTER_KEY )
114
116
.withConnectionPolicy (ConnectionPolicy .GetDefault ())
115
- .withConsistencyLevel (ConsistencyLevel .Session )
117
+ .withConsistencyLevel (ConsistencyLevel .Eventual )
116
118
.build ();
117
119
118
120
createDatabaseIfNotExists ();
@@ -307,25 +309,29 @@ private void heavyWork() {
307
309
private void executeSimpleQueryAsyncAndRegisterListenerForResult (CountDownLatch completionLatch ) {
308
310
// Set some common query options
309
311
FeedOptions queryOptions = new FeedOptions ();
310
- queryOptions .setMaxItemCount (100 );
312
+ queryOptions .setMaxItemCount (10 );
311
313
queryOptions .setEnableCrossPartitionQuery (true );
312
314
313
315
String collectionLink = String .format ("/dbs/%s/colls/%s" , databaseName , collectionName );
314
316
Observable <FeedResponse <Document >> queryObservable =
315
317
client .queryDocuments (collectionLink ,
316
- "SELECT * FROM Family WHERE Family.lastName = 'Andersen'" , queryOptions );
318
+ "SELECT * FROM Family WHERE Family.lastName ! = 'Andersen'" , queryOptions );
317
319
318
320
queryObservable
319
321
.observeOn (scheduler )
320
322
.subscribe (
321
- queryResultPage -> {
323
+ page -> {
322
324
// we want to make sure heavyWork() doesn't block any of netty IO threads
323
325
// so we use observeOn(scheduler) to switch from the netty thread to user's thread.
324
326
heavyWork ();
325
327
326
328
System .out .println ("Got a page of query result with " +
327
- queryResultPage .getResults ().size () + " document(s)"
328
- + " and request charge of " + queryResultPage .getRequestCharge ());
329
+ page .getResults ().size () + " document(s)"
330
+ + " and request charge of " + page .getRequestCharge ());
331
+
332
+
333
+ System .out .println ("Document Ids " + page .getResults ().stream ().map (d -> d .getId ())
334
+ .collect (Collectors .toList ()));
329
335
},
330
336
// terminal error signal
331
337
e -> {
0 commit comments