Skip to content

Commit a2496b7

Browse files
Merge pull request #363 from couchbase/polish-getting-started
Polish "Getting Started"
2 parents bd00a12 + f3241d8 commit a2496b7

File tree

5 files changed

+82
-75
lines changed

5 files changed

+82
-75
lines changed

modules/devguide/examples/Cloud.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
/**
4444
* Example of Cas (Check and Set) handling in Java for the Couchbase Developer
45-
* Guide ported from 2.x. See StartUsingCloud.java for 3.x.
45+
* Guide ported from 2.x. See StartUsingCapella.java for 3.x.
4646
*/
4747

4848
public class Cloud {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// tag::simple-connect[]
2+
// tag::imports[]
3+
import com.couchbase.client.java.*;
4+
// end::imports[]
5+
6+
public class SimpleConnect {
7+
static String connectionString = "couchbases://example.com";
8+
static String username = "username";
9+
static String password = "Password!123";
10+
static String bucketName = "travel-sample";
11+
12+
public static void main(String... args) {
13+
// tag::connect-string[]
14+
// Alternatively, connect without customizing the cluster envionrment.
15+
Cluster cluster = Cluster.connect(connectionString, username, password);
16+
// end::connect-string[]
17+
cluster.disconnect();
18+
}
19+
}
20+
// end::simple-connect[]

modules/devguide/examples/StartUsingCloud.java renamed to modules/devguide/examples/StartUsingCapella.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,25 @@
88
import java.time.Duration;
99
// end::imports[]
1010

11-
12-
public class StartUsingCloud {
11+
public class StartUsingCapella {
1312
// tag::connect-info[]
1413
// Update these variables to point to your Couchbase Capella instance and credentials.
15-
static String connectionString = "cb.<your-endpoint-here>.cloud.couchbase.com";
14+
static String connectionString = "couchbases://cb.<your-endpoint-here>.cloud.couchbase.com";
1615
static String username = "username";
1716
static String password = "Password!123";
1817
static String bucketName = "travel-sample";
1918
// end::connect-info[]
2019

2120
public static void main(String... args) {
22-
// tag::connect-string[]
23-
// Simple connection.
24-
Cluster cluster = Cluster.connect("couchbases://" + connectionString, username, password);
25-
// end::connect-string[]
26-
cluster.disconnect();
27-
2821
// tag::connect-env[]
29-
// Custom environment connection.
30-
cluster = Cluster.connect(
31-
"couchbases://" + connectionString,
32-
ClusterOptions.clusterOptions(username, password).environment(env -> {
33-
// Sets a pre-configured profile called "wan-development" to help avoid latency issues
34-
// when accessing Capella from a different Wide Area Network
35-
// or Availability Zone (e.g. your laptop).
36-
env.applyProfile("wan-development");
37-
})
22+
Cluster cluster = Cluster.connect(
23+
connectionString,
24+
ClusterOptions.clusterOptions(username, password).environment(env -> {
25+
// Sets a pre-configured profile called "wan-development" to help avoid
26+
// latency issues when accessing Capella from a different Wide Area Network
27+
// or Availability Zone (e.g. your laptop).
28+
env.applyProfile("wan-development");
29+
})
3830
);
3931
// end::connect-env[]
4032

@@ -45,16 +37,16 @@ public static void main(String... args) {
4537
// end::bucket[]
4638

4739
// tag::collection[]
48-
// Get a user defined collection reference
40+
// Get a user-defined collection reference
4941
Scope scope = bucket.scope("tenant_agent_00");
5042
Collection collection = scope.collection("users");
5143
// end::collection[]
5244

5345
// tag::upsert-get[]
5446
// Upsert Document
5547
MutationResult upsertResult = collection.upsert(
56-
"my-document",
57-
JsonObject.create().put("name", "mike")
48+
"my-document",
49+
JsonObject.create().put("name", "mike")
5850
);
5951

6052
// Get Document

modules/hello-world/examples/StartUsing.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,39 @@
1111
public class StartUsing {
1212
// tag::connect-info[]
1313
// Update these variables to point to your Couchbase Server instance and credentials.
14-
static String connectionString = "localhost";
14+
static String connectionString = "couchbase://127.0.0.1";
1515
static String username = "Administrator";
1616
static String password = "password";
1717
static String bucketName = "travel-sample";
1818
// end::connect-info[]
1919

2020
public static void main(String... args) {
21-
// tag::connect-string[]
22-
// For a secure cluster connection, use `couchbases://<your-cluster-ip>` instead.
23-
Cluster cluster = Cluster.connect("couchbase://" + connectionString, username, password);
24-
// end::connect-string[]
25-
cluster.disconnect();
26-
2721
// tag::connect-env[]
28-
// For a secure cluster connection, use `couchbases://<your-cluster-ip>` instead.
29-
cluster = Cluster.connect(
30-
"couchbase://" + connectionString,
31-
ClusterOptions.clusterOptions(username, password).environment(env -> {
32-
// Customize client settings by calling methods on the "env" variable.
33-
})
22+
Cluster cluster = Cluster.connect(
23+
connectionString,
24+
ClusterOptions.clusterOptions(username, password).environment(env -> {
25+
// Customize client settings by calling methods on the "env" variable.
26+
})
3427
);
3528
// end::connect-env[]
36-
29+
3730
// tag::bucket[]
3831
// get a bucket reference
3932
Bucket bucket = cluster.bucket(bucketName);
4033
bucket.waitUntilReady(Duration.ofSeconds(10));
4134
// end::bucket[]
4235

4336
// tag::collection[]
44-
// get a user defined collection reference
37+
// get a user-defined collection reference
4538
Scope scope = bucket.scope("tenant_agent_00");
4639
Collection collection = scope.collection("users");
4740
// end::collection[]
4841

4942
// tag::upsert-get[]
5043
// Upsert Document
5144
MutationResult upsertResult = collection.upsert(
52-
"my-document",
53-
JsonObject.create().put("name", "mike")
45+
"my-document",
46+
JsonObject.create().put("name", "mike")
5447
);
5548

5649
// Get Document
@@ -63,7 +56,7 @@ public static void main(String... args) {
6356
// Call the query() method on the scope object and store the result.
6457
Scope inventoryScope = bucket.scope("inventory");
6558
QueryResult result = inventoryScope.query("SELECT * FROM airline WHERE id = 10;");
66-
59+
6760
// Return the result rows with the rowsAsObject() method and print to the terminal.
6861
System.out.println(result.rowsAsObject());
6962
// end::n1ql-query[]

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

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,35 @@ In this guide, you will learn:
2424
2525
== Hello Couchbase
2626

27-
We will go through the code sample step by step, but for those in a hurry to see it, here it is:
27+
We will go through the code sample step by step, but for those in a hurry, here's the complete code:
2828

29-
[{tabs}]
29+
[{tabs}]
3030
====
3131
Couchbase Capella Sample::
3232
+
3333
--
34-
If you are connecting to https://docs.couchbase.com/cloud/index.html[Couchbase Capella], be sure to get the correct endpoint as well as user, password.
34+
If you are connecting to https://docs.couchbase.com/cloud/index.html[Couchbase Capella], you'll need to know the endpoint address, as well as a username and password.
35+
36+
This example requires the Travel Sample Bucket.
37+
The Couchbase Capella free trial version comes with this bucket, and its Query indexes, loaded and ready.
3538
3639
[source,java]
3740
----
38-
include::devguide:example$StartUsingCloud.java[tag=cloud-connect,indent=0]
41+
include::devguide:example$StartUsingCapella.java[tag=cloud-connect,indent=0]
3942
----
40-
41-
The Couchbase Capella free trial version comes with the Travel Sample Bucket, and its Query indexes, loaded and ready.
4243
--
4344
4445
Local Couchbase Server::
45-
+
46-
--
46+
+
47+
--
48+
Before running this example, you will need to install the Travel Sample Bucket
49+
using either the xref:{version-server}@server:manage:manage-settings/install-sample-buckets.adoc#install-sample-buckets-with-the-ui[Web interface]
50+
or the xref:{version-server}@server:manage:manage-settings/install-sample-buckets.adoc#install-sample-buckets-with-the-cli[command line].
51+
4752
[source.try-it,java]
4853
----
4954
include::example$StartUsing.java[tags=start-using,indent=0]
5055
----
51-
52-
As well as the Java SDK (see below), and a running instance of Couchbase Server, you will need to load up the Travel Sample Bucket
53-
using either the xref:{version-server}@server:manage:manage-settings/install-sample-buckets.adoc#install-sample-buckets-with-the-ui[Web interface]
54-
or the xref:{version-server}@server:manage:manage-settings/install-sample-buckets.adoc#install-sample-buckets-with-the-cli[command line].
5556
--
5657
====
5758

@@ -138,7 +139,7 @@ Here are all the imports needed to run the sample code:
138139

139140
[source,java]
140141
----
141-
include::devguide:example$StartUsingCloud.java[tags=imports,indent=0]
142+
include::devguide:example$StartUsingCapella.java[tags=imports,indent=0]
142143
----
143144

144145
If you haven't already, create an empty class and add a `main()` method.
@@ -161,7 +162,7 @@ Couchbase Capella::
161162
--
162163
[source,java]
163164
----
164-
include::devguide:example$StartUsingCloud.java[tags=connect-info,indent=0]
165+
include::devguide:example$StartUsingCapella.java[tags=connect-info,indent=0]
165166
----
166167
--
167168
@@ -188,19 +189,14 @@ The basic connection details that you’ll need are given below -- for more back
188189
Couchbase Capella::
189190
+
190191
--
191-
[source,java]
192-
----
193-
include::devguide:example$StartUsingCloud.java[tags=connect-string,indent=0]
194-
----
195-
196-
From version 3.3, the Java SDK includes Capella’s standard certificates by default, so you don't need any additional configuration.
197-
You do need to enable TLS, which can be done by simply using `couchbases://` in the connection string as in this example.
192+
From version 3.3, the Java SDK includes Capella’s standard Certificate Authority (CA) certificates by default, so you don't need any additional configuration.
193+
Capella requires TLS, which you can enable by using a connection string that starts with `couchbases://` (note the final 's').
198194
199-
Alternatively, you can use a xref:howtos:managing-connections.adoc#cluster-environment[Cluster Environment] when you need to customize the client’s behavior (e.g. changing connection timeout settings).
195+
This example shows how to connect and customize the xref:howtos:managing-connections.adoc#cluster-environment[Cluster Environment] settings.
200196
201197
[source,java]
202198
----
203-
include::devguide:example$StartUsingCloud.java[tags=connect-env,indent=0]
199+
include::devguide:example$StartUsingCapella.java[tags=connect-env,indent=0]
204200
----
205201
206202
When accessing Capella from a different Wide Area Network or Availability Zone, you may experience latency issues with the default connection settings.
@@ -213,28 +209,34 @@ CAUTION: The Configuration Profiles feature is currently a xref:java-sdk:project
213209
Local Couchbase Server::
214210
+
215211
--
212+
For developing locally on the same machine as Couchbase Server, your connection string can be `couchbase://127.0.0.1` as shown here.
213+
For production deployments, you will want to enable TLS by using `couchbases://` (note the final 's') instead of `couchbase://`.
214+
215+
This example shows how to connect and customize the xref:howtos:managing-connections.adoc#cluster-environment[Cluster Environment] settings.
216+
216217
[source,java]
217218
----
218-
include::example$StartUsing.java[tags=connect-string,indent=0]
219+
include::example$StartUsing.java[tags=connect-env,indent=0]
219220
----
221+
--
222+
====
220223

221-
For developing locally on the same machine as Couchbase Server, your URI can be `couchbase://localhost` as shown here.
222-
For production deployments, you will want to use a secure server, with `couchbases://`.
223-
224-
Alternatively, you can use a xref:howtos:managing-connections.adoc#cluster-environment[Cluster Environment] when you need to customize the client’s behavior (e.g. changing connection timeout settings).
224+
[TIP]
225+
.Simpler Connection
226+
====
227+
There's also a simpler version of `Cluster.connect()` for when you don't need to customize the cluster environment:
225228
226229
[source,java]
227230
----
228-
include::example$StartUsing.java[tags=connect-env,indent=0]
231+
include::devguide:example$SimpleConnect.java[tags=connect-string,indent=0]
229232
----
230-
--
231233
====
232234

233-
Following successful authentication, add this code snippet to access your `Bucket`:
235+
Now that you have a `Cluster`, add this code snippet to access your `Bucket`:
234236

235237
[source,java]
236238
----
237-
include::devguide:example$StartUsingCloud.java[tag=bucket,indent=0]
239+
include::devguide:example$StartUsingCapella.java[tag=bucket,indent=0]
238240
----
239241

240242
=== Add and Retrieve Documents
@@ -246,7 +248,7 @@ Here we refer to the `users` collection within the `tenant_agent_00` scope from
246248

247249
[source,java]
248250
----
249-
include::devguide:example$StartUsingCloud.java[tag=collection,indent=0]
251+
include::devguide:example$StartUsingCapella.java[tag=collection,indent=0]
250252
----
251253

252254
xref:howtos:kv-operations.adoc[Data operations], like storing and retrieving documents, can be done using simple methods on the `Collection` class such as `Collection.get()` and `Collection.upsert()`.
@@ -255,7 +257,7 @@ Add the following code to create a new document and retrieve it:
255257

256258
[source,java]
257259
----
258-
include::devguide:example$StartUsingCloud.java[tag=upsert-get,indent=0]
260+
include::devguide:example$StartUsingCapella.java[tag=upsert-get,indent=0]
259261
----
260262

261263
=== {sqlpp} Lookup
@@ -267,7 +269,7 @@ However, with a Scope level query you only need to specify the Collection name -
267269

268270
[source,java]
269271
----
270-
include::devguide:example$StartUsingCloud.java[tag=n1ql-query,indent=0]
272+
include::devguide:example$StartUsingCapella.java[tag=n1ql-query,indent=0]
271273
----
272274

273275
You can learn more about {sqlpp} queries on the xref:howtos:n1ql-queries-with-sdk.adoc[] page.

0 commit comments

Comments
 (0)