Skip to content

Commit e490c4c

Browse files
Quick fixes
1 parent 754ff38 commit e490c4c

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

modules/hello-world/pages/start-using-sdk.adoc

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ Couchbase Capella::
205205
--
206206
[source,java]
207207
----
208-
include::devguide:example$java/StartUsingCapella.java[tags=connect-info,indent=0]
208+
include::devguide:example$java/StartUsingCapella.java[tags=connect,indent=0]
209209
----
210210
--
211211
@@ -344,24 +344,22 @@ include::devguide:example$java/StartUsingCapella.java[tag=upsert,indent=0]
344344
The `get` method reads a document from a collection.
345345
// If the collection does not have a document with this ID, the `get` method also throws `DocumentNotFoundException`.
346346

347-
As mentioned above, the Scala SDK will not throw exceptions.
348-
Instead, methods that can error -- such as the `upsert` above --
349-
will return a Scala `Try` result, which can either be a `Success` containing the result, or a `Failure` containing a _Throwable_ exception.
350-
The easiest way to handle a single operation is with pattern matching, as shown above.
351-
352-
Now let's get the data back (this example will look a little messy due the nested handling of multiple `Try` results, but we'll see how to clean it up shortly):
347+
Wrapping the method in a `Try` / `Catch` is a good way to handle exceptions:
353348

354349
[source,java]
355350
----
356351
include::devguide:example$java/StartUsingCapella.java[tag=get,indent=0]
357352
----
358353

354+
////
359355
Here we're fetching the value for the key `docId`,
360356
converting that value to a `JsonObjectSafe`
361357
(a simple wrapper around `JsonObject` that returns `Try` results -- see
362358
xref:howtos:json.adoc#error-handling-and-jsonobjectsafe[JsonObjectSafe] for details),
363359
and then accessing the value of the *status* key as a String.
360+
////
364361

362+
////
365363
==== Better Error Handling
366364
367365
All three of these operations could fail, so there's quite a lot of error handling code here to do something quite simple.
@@ -382,19 +380,23 @@ include::devguide:example$java/StartUsingCapella.java[tag=get-for,indent=0]
382380
Either of these methods will stop on the first failed operation. So the final returned `Try` contains either
383381
a) `Success` and the result of the final operation, indicating that everything was successful, or
384382
b) `Failure` with the error returned by the first failing operation.
383+
////
385384

386385
=== Replace (Update) and Overloads
387386

387+
////
388388
You'll notice that most operations in the Scala SDK have two overloads.
389389
One will take an Options builder, which provides all possible options that operation takes.
390390
For instance:
391+
////
391392

392393
.The replace method updates the value of an existing document
393394
[source,java]
394395
----
395396
include::devguide:example$java/StartUsingCapella.java[tag=replace-options,indent=0]
396397
----
397398

399+
////
398400
These options blocks are implemented as Scala case classes:
399401
they are immutable data objects that return a copy of themselves on each change.
400402
@@ -405,6 +407,7 @@ It takes named arguments instead of an Options object, and provides only the mos
405407
----
406408
include::devguide:example$java/StartUsingCapella.java[tag=replace-named,indent=0]
407409
----
410+
////
408411

409412
CAUTION: When you replace a document, it's usually good practice to use xref:howtos:kv-operations.adoc#optimistic-locking[optimistic locking].
410413
Otherwise, changes might get lost if two people change the same document at the same time.
@@ -415,9 +418,15 @@ The remove method deletes a document from a collection:
415418

416419
[source,java]
417420
----
418-
include::devguide:example$java/StartUsingCapella.java[indent=0,tag=remove]
421+
try {
422+
collection.remove("my-document");
423+
} catch (DocumentNotFoundException ex) {
424+
System.out.println("Document did not exist when trying to remove");
425+
}
419426
----
420427

428+
Like `replace`, `remove` also optionally takes the CAS value if you want to make sure you are only removing the document if it hasn’t changed since you last fetched it.
429+
421430

422431
== Data Modeling
423432

@@ -481,13 +490,15 @@ Now you're up and running, try one of the following:
481490

482491
=== Additional Resources
483492

493+
////
484494
The Scala SDK includes three APIs.
485495
The examples above show the simple blocking API, for simplicity, but you can also perform all operations in an async style using Scala `Future`, and a reactive style using Project Reactor `SMono` and `SFlux`.
486496
Please see xref:howtos:concurrent-async-apis.adoc[Choosing an API] for more details.
497+
////
487498

488499
The API reference is generated for each release and the latest can be found https://docs.couchbase.com/sdk-api/couchbase-scala-client/com/couchbase/client/scala/index.html[here].
489500

490-
Couchbase welcomes community contributions to the Scala SDK.
501+
Couchbase welcomes community contributions to the Java SDK.
491502
The SDK source code is available on https://github.com/couchbase/couchbase-jvm-clients[GitHub].
492503

493504
=== Troubleshooting
@@ -497,7 +508,7 @@ If you're running the SDK on your laptop against a Capella cluster, see further
497508
** Notes on xref:ref:client-settings.adoc#constrained-network-environments[Constrained Network Environments].
498509
** xref:project-docs:compatibility.adoc#network-requirements[Network Requirements].
499510
** If you have a consumer-grade router which has problems with DNS-SRV records review our xref:howtos:troubleshooting-cloud-connections.adoc#troubleshooting-host-not-found[Troubleshooting Guide].
500-
* Our https://forums.couchbase.com/c/scala-sdk/37[community forum] is a great source of help.
511+
* Our https://www.couchbase.com/forums/c/java-sdk/5[community forum] is a great source of help.
501512
////
502513
503514

0 commit comments

Comments
 (0)