@@ -56,7 +56,7 @@ public static void main(String[] args) {
5656 logger .info ("Demo complete, please hold while resources are released" );
5757 } catch (Exception e ) {
5858 e .printStackTrace ();
59- logger .error (String . format ( "Cosmos getStarted failed with %s " , e ) );
59+ logger .error ("Cosmos getStarted failed with {} " , e );
6060 } finally {
6161 logger .info ("Closing the client" );
6262 p .shutdown ();
@@ -67,7 +67,7 @@ private void autoscaleContainerCRUDDemo() throws Exception {
6767
6868 logger .info ("Using Azure Cosmos DB endpoint: " + AccountSettings .HOST );
6969
70- // Create sync client
70+ // Create async client
7171 client = new CosmosClientBuilder ()
7272 .endpoint (AccountSettings .HOST )
7373 .key (AccountSettings .MASTER_KEY )
@@ -88,7 +88,7 @@ private void autoscaleContainerCRUDDemo() throws Exception {
8888
8989 // Database Create
9090 private void createDatabaseIfNotExists () throws Exception {
91- logger .info ("Create database " + databaseName + " if not exists..." );
91+ logger .info ("Create database {} if not exists..." , databaseName );
9292
9393 // Create database if not exists
9494 CosmosDatabaseResponse databaseResponse = client .createDatabaseIfNotExists (databaseName ).block ();
@@ -99,7 +99,7 @@ private void createDatabaseIfNotExists() throws Exception {
9999
100100 // Container create
101101 private void createContainerIfNotExists () throws Exception {
102- logger .info ("Create autoscale container " + containerName + " if not exists." );
102+ logger .info ("Create autoscale container {} if not exists." , containerName );
103103
104104 // Container and autoscale throughput settings
105105 CosmosContainerProperties autoscaleContainerProperties = new CosmosContainerProperties (containerName , "/lastName" );
@@ -115,7 +115,7 @@ private void createContainerIfNotExists() throws Exception {
115115
116116 // Update container throughput
117117 private void updateContainerThroughput () throws Exception {
118- logger .info ("Update autoscale max throughput for container " + containerName + "." );
118+ logger .info ("Update autoscale max throughput for container {}." , containerName );
119119
120120 // Change the autoscale max throughput (RU/s)
121121 container .replaceThroughput (ThroughputProperties .createAutoscaledThroughput (8000 )).block ();
@@ -138,7 +138,7 @@ private void readContainerThroughput() throws Exception {
138138
139139 // Container read
140140 private void readContainerById () throws Exception {
141- logger .info ("Read container " + containerName + " by ID." );
141+ logger .info ("Read container {} by ID." , containerName );
142142
143143 // Read container by ID
144144 container = database .getContainer (containerName );
@@ -148,17 +148,15 @@ private void readContainerById() throws Exception {
148148
149149 // Container read all
150150 private void readAllContainers () throws Exception {
151- logger .info ("Read all containers in database " + databaseName + "." );
151+ logger .info ("Read all containers in database {}." , databaseName );
152152
153153 // Read all containers in the account
154154 CosmosPagedFlux <CosmosContainerProperties > containers = database .readAllContainers ();
155155
156156 // Print
157157 String msg ="Listing containers in database:\n " ;
158158 containers .byPage (100 ).flatMap (readAllContainersResponse -> {
159- logger .info ("read " +
160- readAllContainersResponse .getResults ().size () + " containers(s)"
161- + " with request charge of " + readAllContainersResponse .getRequestCharge ());
159+ logger .info ("read {} containers(s) with request charge of {}" , readAllContainersResponse .getResults ().size (),readAllContainersResponse .getRequestCharge ());
162160
163161 for (CosmosContainerProperties response : readAllContainersResponse .getResults ()) {
164162 logger .info ("container id: " +response .getId ());
@@ -173,7 +171,7 @@ private void readAllContainers() throws Exception {
173171
174172 // Container delete
175173 private void deleteAContainer () throws Exception {
176- logger .info ("Delete container " + containerName + " by ID." );
174+ logger .info ("Delete container {} by ID." , containerName );
177175
178176 // Delete container
179177 CosmosContainerResponse containerResp = database .getContainer (containerName ).delete (new CosmosContainerRequestOptions ()).block ();
@@ -184,7 +182,7 @@ private void deleteAContainer() throws Exception {
184182
185183 // Database delete
186184 private void deleteADatabase () throws Exception {
187- logger .info ("Last step: delete database " + databaseName + " by ID." );
185+ logger .info ("Last step: delete database {} by ID." , databaseName );
188186
189187 // Delete database
190188 CosmosDatabaseResponse dbResp = client .getDatabase (databaseName ).delete (new CosmosDatabaseRequestOptions ()).block ();
@@ -203,8 +201,10 @@ private void shutdown() {
203201 logger .error ("Deleting Cosmos DB resources failed, will still attempt to close the client. See stack trace below." );
204202 err .printStackTrace ();
205203 }
206- client .close ();
207- logger .info ("Done with sample." );
204+ finally {
205+ client .close ();
206+ logger .info ("Done with sample." );
207+ }
208208 }
209209
210210}
0 commit comments