Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
minor cleanup, reformattig, pretty printing etc
Browse files Browse the repository at this point in the history
  • Loading branch information
moderakh committed Oct 25, 2018
1 parent f528d53 commit 2ae5719
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion azure-cosmosdb-get-started/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<version>1.6.0</version>
<configuration>
<mainClass>com.microsoft.azure.cosmosdb.sample.Main</mainClass>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Families {

public static Family getAndersenFamilyDocument() {
Family andersenFamily = new Family();
andersenFamily.setId("Andersen" + System.currentTimeMillis());
andersenFamily.setId("Andersen-" + System.currentTimeMillis());
andersenFamily.setLastName("Andersen");

Parent parent1 = new Parent();
Expand Down Expand Up @@ -61,7 +61,7 @@ public static Family getAndersenFamilyDocument() {

public static Family getWakefieldFamilyDocument() {
Family wakefieldFamily = new Family();
wakefieldFamily.setId("Wakefield" + System.currentTimeMillis());
wakefieldFamily.setId("Wakefield-" + System.currentTimeMillis());
wakefieldFamily.setLastName("Wakefield");

Parent parent1 = new Parent();
Expand Down Expand Up @@ -108,7 +108,7 @@ public static Family getWakefieldFamilyDocument() {

public static Family getJohnsonFamilyDocument() {
Family andersenFamily = new Family();
andersenFamily.setId("Johnson" + System.currentTimeMillis());
andersenFamily.setId("Johnson-" + System.currentTimeMillis());
andersenFamily.setLastName("Johnson");

Parent parent1 = new Parent();
Expand All @@ -122,7 +122,7 @@ public static Family getJohnsonFamilyDocument() {

public static Family getSmithFamilyDocument() {
Family andersenFamily = new Family();
andersenFamily.setId("Smith" + System.currentTimeMillis());
andersenFamily.setId("Smith-" + System.currentTimeMillis());
andersenFamily.setLastName("Smith");

Parent parent1 = new Parent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

public class Main {
private final ExecutorService executorService;
Expand Down Expand Up @@ -96,13 +97,14 @@ public static void main(String[] args) {

try {
p.getStartedDemo();
System.out.println(String.format("Demo complete, please hold while resources are deleted"));
System.out.println(String.format("Demo complete, please hold while resources are released"));
} catch (Exception e) {
System.err.println(String.format("DocumentDB GetStarted failed with %s", e));
} finally {
System.out.println("close the client");
p.close();
}
System.exit(0);
}

private void getStartedDemo() throws Exception {
Expand All @@ -112,7 +114,7 @@ private void getStartedDemo() throws Exception {
.withServiceEndpoint(AccountSettings.HOST)
.withMasterKeyOrResourceToken(AccountSettings.MASTER_KEY)
.withConnectionPolicy(ConnectionPolicy.GetDefault())
.withConsistencyLevel(ConsistencyLevel.Session)
.withConsistencyLevel(ConsistencyLevel.Eventual)
.build();

createDatabaseIfNotExists();
Expand Down Expand Up @@ -307,25 +309,29 @@ private void heavyWork() {
private void executeSimpleQueryAsyncAndRegisterListenerForResult(CountDownLatch completionLatch) {
// Set some common query options
FeedOptions queryOptions = new FeedOptions();
queryOptions.setMaxItemCount(100);
queryOptions.setMaxItemCount(10);
queryOptions.setEnableCrossPartitionQuery(true);

String collectionLink = String.format("/dbs/%s/colls/%s", databaseName, collectionName);
Observable<FeedResponse<Document>> queryObservable =
client.queryDocuments(collectionLink,
"SELECT * FROM Family WHERE Family.lastName = 'Andersen'", queryOptions);
"SELECT * FROM Family WHERE Family.lastName != 'Andersen'", queryOptions);

queryObservable
.observeOn(scheduler)
.subscribe(
queryResultPage -> {
page -> {
// we want to make sure heavyWork() doesn't block any of netty IO threads
// so we use observeOn(scheduler) to switch from the netty thread to user's thread.
heavyWork();

System.out.println("Got a page of query result with " +
queryResultPage.getResults().size() + " document(s)"
+ " and request charge of " + queryResultPage.getRequestCharge());
page.getResults().size() + " document(s)"
+ " and request charge of " + page.getRequestCharge());


System.out.println("Document Ids " + page.getResults().stream().map(d -> d.getId())
.collect(Collectors.toList()));
},
// terminal error signal
e -> {
Expand Down

0 comments on commit 2ae5719

Please sign in to comment.