Skip to content

Commit 98b96e2

Browse files
page improvements
1 parent 05df962 commit 98b96e2

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

modules/howtos/pages/kv-operations.adoc

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
= Data Operations
22
:description: Data service offers the simplest way to retrieve or mutate data where the key is known.
3-
:page-topic-type: howto
43
:page-aliases: ROOT:document-operations.adoc,ROOT:documents-creating,ROOT:documents-updating,ROOT:documents-retrieving,ROOT:documents-deleting
5-
:example-source: 3.2@java-sdk:howtos:example$Queries.java
4+
// :example-source: 3.8@java-sdk:devguide:example$java/Queries.java
65
:page-toclevels: 2
76
:page-pagination: full
87

9-
include::project-docs:partial$attributes.adoc[]
8+
109

1110
[abstract]
1211
{description}
13-
Here we cover CRUD operations, document expiration, and optimistic locking with CAS.
12+
Here we cover CRUD operations, document expiration, and optimistic locking with CAS --
13+
as well as KV Range scan, for querying without an index.
14+
15+
1416

15-
The complete code sample used on this page can be downloaded from https://github.com/couchbase/docs-sdk-java/blob/release/3.2/modules/howtos/examples/KvOperations.java[here].
17+
The complete code sample used on this page can be downloaded from https://github.com/couchbase/docs-sdk-java/blob/release/3.8/modules/devguide/examples/java/KvOperations.java[here].
1618

1719
At its heart Couchbase Server is a high-performance key-value store, and the key-value interface outlined below is the fastest and best method to perform operations involving single documents.
1820

@@ -36,7 +38,9 @@ include::devguide:example$java/KvOperations.java[tag=imports]
3638
{sqlpp_url}[{sqlpp} (formerly N1QL)] can also be used to perform many single-document operations but we very strongly recommend using the key-value API for this instead, as it can be much more efficient. The request can go directly to the correct node, there's no query parsing overhead, and it's over the highly optimized memcached binary protocol.
3739
====
3840

41+
3942
== JSON
43+
4044
The Couchbase Server is a key-value store that's agnostic to what's stored, but it's very common to store JSON so most of the examples below will focus on that use-case.
4145

4246
The Java SDK provides you with several options for working with JSON.
@@ -45,7 +49,8 @@ If you pass any object (like the provided `JsonObject` and `JsonArray`), includi
4549
the SDK will use its internal JSON codec (utilizing https://github.com/FasterXML/jackson[Jackson]) to encode/decode those objects transparently.
4650
The SDK also supports custom transcoders and serializers which are covered separately.
4751

48-
== Upsert
52+
53+
== CRUD
4954

5055
[TIP]
5156
.Sub-Document Operations
@@ -55,6 +60,7 @@ Where the number of operations or other circumstances make bandwidth a significa
5560
the SDK can work on just a specific _path_ of the document with xref:subdocument-operations.adoc[Sub-Document Operations].
5661
====
5762

63+
=== Upsert
5864
Here is a simple upsert operation, which will insert the document if it does not exist, or replace it if it does.
5965

6066
We'll use the built-in JSON types for simplicity, but you can use different types if you want.
@@ -77,15 +83,16 @@ include::devguide:example$java/KvOperations.java[tag=apis,indent=0]
7783
----
7884
=====
7985

80-
== Insert
86+
=== Insert
87+
8188
Insert works very similarly to upsert, but will fail if the document already exists with a `DocumentExistsException`:
8289

8390
[source,java]
8491
----
8592
include::devguide:example$java/KvOperations.java[tag=insert,indent=0]
8693
----
8794

88-
== Retrieving documents
95+
=== Retrieving documents
8996

9097
We've tried upserting and inserting documents into Couchbase Server, let's get them back:
9198

@@ -105,7 +112,8 @@ Once we have a `GetResult`, we can use `contentAsObject()` to turn the content b
105112
or use the more generic `contentAs(T.class)` equivalent to turn it back into other entity structures.
106113
In fact, the `contentAsObject()` method is just a convenience method for `contentAs(JsonObject.class)`.
107114

108-
== Replace
115+
=== Replace
116+
109117
A very common sequence of operations is to `get` a document, modify its contents, and `replace` it.
110118

111119
[source,java]
@@ -129,7 +137,7 @@ See xref:concurrent-document-mutations.adoc[this detailed description of CAS] fo
129137

130138
In general, you'll want to provide a CAS value whenever you `replace` a document, to prevent overwriting another agent's mutations.
131139

132-
== Retrying on CAS failures
140+
=== Retrying on CAS failures
133141

134142
But if we get a CAS mismatch, we usually just want to retry the operation.
135143
Let's see a more advanced `replace` example that shows one way to handle this:
@@ -147,7 +155,7 @@ In later chapters we cover more sophisticated approaches to this, including asyn
147155
All these should be in place for robust, production ready code.
148156

149157

150-
== Removing
158+
=== Removing
151159

152160
Removing a document is straightforward:
153161

@@ -181,14 +189,16 @@ If 6.5 or above is being used, you can take advantage of the xref:concept-docs:d
181189
in which Couchbase Server will only return success to the SDK after the requested replication level has been achieved.
182190
The three replication levels are:
183191

184-
* `Majority` - The server will ensure that the change is available in memory on the majority of configured replicas.
185-
* `MajorityAndPersistToActive` - Majority level, plus persisted to disk on the active node.
186-
* `PersistToMajority` - Majority level, plus persisted to disk on the majority of configured replicas.
192+
* `Majority` -- The server will ensure that the change is available in memory on the majority of configured replicas.
193+
* `MajorityAndPersistToActive` -- Majority level, plus persisted to disk on the active node.
194+
* `PersistToMajority` -- Majority level, plus persisted to disk on the majority of configured replicas.
187195

188196
The options are in increasing levels of safety.
189-
Note that nothing comes for free - for a given node, waiting for writes to storage is considerably slower than waiting for it to be available in-memory.
197+
Note that nothing comes for free -- for a given node, waiting for writes to storage is considerably slower than waiting for it to be available in-memory.
190198
These tradeoffs, as well as which settings may be tuned, are discussed in the xref:concept-docs:durability-replication-failure-considerations.adoc#durable-writes[durability page].
191199

200+
// remove 6.5 stuff once 8.0 is released?
201+
192202
If a version of Couchbase Server lower than 6.5 is being used then the application can fall-back to xref:concept-docs:durability-replication-failure-considerations.adoc#older-server-versions['client verified' durability].
193203
Here the SDK will do a simple poll of the replicas and only return once the requested durability level is achieved.
194204
This can be achieved like this:
@@ -285,6 +295,8 @@ include::example$KvOperations.cs[tag=binarydecrementwithoptions,indent=0]
285295
////
286296
NOTE: Increment & Decrement are considered part of the ‘binary’ API and as such may still be subject to change
287297

298+
See the https://docs.couchbase.com/sdk-api/couchbase-java-client/com/couchbase/client/java/kv/Increment.html[API Reference] for full details.
299+
288300
TIP: Setting the document expiry time only works when a document is created, and it is not possible to update the expiry time of an existing counter document with the Increment method -- to do this during an increment, use with the `Touch()` method.
289301

290302

@@ -387,4 +399,4 @@ Another way of increasing network performance is to _pipeline_ operations with x
387399

388400
As well as various xref:concept-docs:data-model.adoc[Formats] of JSON, Couchbase can work directly with xref:concept-docs:nonjson.adoc[arbitrary bytes, or binary format].
389401

390-
Our xref:n1ql-queries-with-sdk.adoc[Query Engine] enables retrieval of information using the SQL-like syntax of {sqlpp}.
402+
Our xref:sqlpp-queries-with-sdk.adoc[Query Engine] enables retrieval of information using the SQL-like syntax of {sqlpp}.

0 commit comments

Comments
 (0)