Skip to content

Commit 72ecfbb

Browse files
authored
DOC-7520 -- PORT -- for 3.0 -- Database Close etc … (#433)
* DOC-7520 -- Database close not documented https://issues.couchbase.com/browse/DOC-7520 https://issues.couchbase.com/browse/DOC-8237 https://issues.couchbase.com/browse/DOC-3980 https://issues.couchbase.com/browse/DOC-5360 (cherry picked from commit 40d3779) (cherry picked from commit 4bcbe6640a114ee0eccb6052c2f3c11a31a19888) * DOC-7520 -- relocated android snippets * DOC-7520 -- Relocated Android snippets Update snippet attributes cherry picked file from 0bed5ca * DOC-7520 -- PORT -- for 3.0 -- Database Close etc https://issues.couchbase.com/browse/DOC-7520
1 parent 711ec7d commit 72ecfbb

File tree

26 files changed

+351
-493
lines changed

26 files changed

+351
-493
lines changed

modules/ROOT/pages/_partials/_attributes-local.adoc

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,46 +36,40 @@
3636
//
3737

3838
// Begin -- Source Languages
39-
// :langAndroid: kotlin
40-
// :langAndroidFull: java-android
41-
// :langClang: clang
42-
// :langCsharp: csharp
43-
// :langJava: java
44-
// :langJavaFull: java
45-
// :langJavascript: javascript
46-
// :langObjc: objc
47-
// :langObjcFull: objective-c
48-
// :langSwift: swift
39+
:langAndroid: android
40+
:langAndroidFull: java-android
41+
:langCsharp: csharp
42+
:langJava: java
43+
:langJavaFull: java
44+
:langJavascript: javascript
45+
:langObjc: objc
46+
:langObjcFull: objective-c
47+
:langSwift: swift
4948
:platform-android: android
50-
:platform-clang: clang
5149
:platform-jvm: jvm
5250
:platform-ios: ios
5351
:platform-web: web
5452
:platform-net: net
5553

5654
// Couchbase Lite
5755
:lang-mod-android: android
58-
:lang-mod-clang: clang
5956
:lang-mod-csharp: csharp
6057
:lang-mod-java: java
6158
:lang-mod-objc: objc
6259
:lang-mod-swift: swift
63-
:lang-name-android: kotlin
64-
:lang-name-clang: clang
60+
:lang-name-android: android
6561
:lang-name-csharp: csharp
6662
:lang-name-java: java
6763
:lang-name-objc: objc
6864
:lang-name-swift: swift
6965
:lang-name-javascript: javascript
7066
:lang-platform-android: {platform-android}
71-
:lang-platform-clang: {platform-clang}
7267
:lang-platform-csharp: {platform-net}
7368
:lang-platform-java: {platform-jvm}
7469
:lang-platform-objc: {platform-ios}
7570
:lang-platform-swift: {platform-ios}
7671
:lang-platform-javascript: {platform-web}
7772
:lang-title-android: Android
78-
:lang-title-clang: C
7973
:lang-title-csharp: C#/.Net
8074
:lang-title-java: Java
8175
:lang-title-objc: Objective C
@@ -91,13 +85,12 @@
9185
:nmStarterCode: StarterCode1.0
9286
:nmSampleAppUser: admin
9387
:nmSampleAppPassword: password
94-
// :nmLangJava: java
95-
// :nmLangJS: javascript
96-
// :nmLangClang: C
97-
// :nmLangNet: C#/.Net
98-
// :nmLangSwift: Swift
99-
// :nmLangobjc: Objective-C
100-
// :nmLangAndroid: Android
88+
:nmLangJava: java
89+
:nmLangJS: javascript
90+
:nmLangNet: C#/.Net
91+
:nmLangSwift: Swift
92+
:nmLangobjc: Objective-C
93+
:nmLangAndroid: Android
10194

10295
:tknwip: Under Construction
10396
:tknwip-note: This page is {tknwip} and is included as a place holder only.
@@ -135,7 +128,6 @@
135128
// deprecated that
136129

137130
:url-download-swift: https://packages.couchbase.com/releases/couchbase-lite-ios/2.8.0-beta/couchbase-lite-swift_community_2.8.0.zip[Couchbase Lite Swift]
138-
:url-download-clang: https://packages.couchbase.com/releases/couchbase-lite-c/2.8.0-beta/couchbase-lite-objc_community_2.8.0.zip[Couchbase Lite C]
139131
:url-download-objc: https://packages.couchbase.com/releases/couchbase-lite-ios/2.8.0-beta/couchbase-lite-objc_community_2.8.0.zip[Couchbase Lite ObjC]
140132
:url-download-android: https://packages.couchbase.com/releases/couchbase-lite-android/2.8.0-beta/couchbase-lite-android_community_2.8.0.zip[Couchbase Lite Android]
141133
:url-download-java: https://packages.couchbase.com/releases/couchbase-lite-java/2.8.0-beta/couchbase-lite-java_community_2.8.0.zip[Couchbase Lite Java]
@@ -149,7 +141,6 @@
149141
:url-api-references-production: http://docs.couchbase.com/mobile/{version-full}/couchbase-lite-
150142
:url-api-references-pfx: {url-api-references-production}
151143
:url-api-references-android: {url-api-references-pfx}{lang-mod-android}
152-
:url-api-references-clang: {url-api-references-pfx}c
153144
:url-api-references-csharp: {url-api-references-pfx}net
154145
// :url-api-references-csharp: {url-api-references-pfx}{lang-mod-csharp}
155146
:url-api-references-java: {url-api-references-pfx}{lang-mod-java}
@@ -168,7 +159,6 @@
168159

169160
// Issue Links
170161
:url-issues-android: {url-github-cbl}-android/issues
171-
:url-issues-clang: {url-github-cbl}-c/issues
172162
:url-issues-csharp: {url-github-cbl}-csharp/issues
173163
:url-issues-java: {url-github-cbl}-android/issues
174164
:url-issues-objc: {url-github-cbl}-ios/issues
@@ -188,7 +178,6 @@
188178

189179
:android-pages: {lang-mod-android}:page$
190180
:android-examples: {lang-mod-android}:example$
191-
:clang-examples: {lang-mod-clang}:example$
192181
:csharp-examples: {lang-mod-csharp}:example$
193182
:java-examples: {lang-mod-java}:example$
194183
:objc-examples: {lang-mod-objc}:example$
@@ -198,16 +187,13 @@
198187
:snippets-pfx--android-kt: {snippets-pfx--android}kotlin/com/couchbase/code_snippets/
199188
:snippets-pfx--android-java: {snippets-pfx--android}java/com/couchbase/code_snippets/
200189
:snippets-pfx: example$code_snippets/
201-
:snippets-content--android-kotlin: {lang-mod-android}:{snippets-pfx--android-kt}Examples.kt
202-
:snippets-content--android-java: {lang-mod-android}:{snippets-pfx--android-java}Examples.java
203-
:snippets-content--clang: {lang-mod-clang}:{snippets-pfx}SampleCodeTest.cc
190+
:snippets-content--android: {lang-mod-android}:{snippets-pfx--android-java}Examples.java
204191
:snippets-content--csharp: {lang-mod-csharp}:{snippets-pfx}Program.cs
205192
:snippets-content--java: {lang-mod-java}:{snippets-pfx}Examples.java
206193
:snippets-content--objc: {lang-mod-objc}:{snippets-pfx}SampleCodeTest.m
207194
:snippets-content--swift: {lang-mod-swift}:{snippets-pfx}SampleCodeTest.swift
208195

209-
// :snippets-p2psync-ws--android: {lang-mod-android}:{snippets-pfx--android}/code_snippets/p2psync-websocket.java
210-
:snippets-p2psync-ws--clang: {snippets-content--clang}
196+
:snippets-p2psync-ws--android: {lang-mod-android}:{snippets-pfx--android-java}p2psync-websocket.java
211197
:snippets-p2psync-ws--csharp: {lang-mod-csharp}:{snippets-pfx}p2psync-websocket.cs
212198
:snippets-p2psync-ws--java: {lang-mod-java}:{snippets-pfx}p2psync-websocket.java
213199
:snippets-p2psync-ws--objc: {lang-mod-objc}:{snippets-pfx}p2psync-websocket.m

modules/ROOT/pages/_partials/_page-index.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ ifndef::version[:version: version undefined]
8888
:cbl-pg-pfx-api: pfx-api.adoc
8989
:cbl-pg-refer-glossary: refer-glossary.adoc
9090
:cbl-pg-releasenotes-all: releasenotes.adoc
91-
:cbl-pg-releasenotes: releasenotes.adoc
91+
// :cbl-pg-releasenotes: releasenotes.adoc
92+
:cbl-pg-releasenotes: product/{param-name}-releasenotes.adoc
93+
:cbl-pg-replication: learn/{param-name}-replication.adoc
9294
:cbl-pg-replication--delta-sync: {cbl-pg-replication}#delta-sync
9395
:cbl-pg-replication--status: {cbl-pg-replication}#lbl-repl-status
9496
:cbl-pg-replication--states: {cbl-pg-replication}#lbl-repl-states
@@ -113,7 +115,7 @@ ifndef::version[:version: version undefined]
113115
:xref-cbl-pfx-p2psync-websocket: {xref-pfx-cbl}{cbl-pg-p2psync-websocket}
114116
:xref-cbl-pfx-replication: {xref-pfx-cbl}{cbl-pg-replication}
115117

116-
:xref-cbl-bmk-database-findfile: {xref-cbl-pfx-database}#finding-a-database-file[Finding a Database File]
118+
:xref-cbl-bmk-database-findfile: {xref-cbl-pfx-database}#lbl-find-db-loc[Finding a Database File]
117119
:xref-cbl-bmk-dbo-p2psync-websocket-using-active-auth-listener: {xref-cbl-pfx-dbo-p2psync-websocket-using-active}#authenticating-the-listener[Active Peer - authenticating the listener]
118120
:xref-cbl-bmk-replication-deltasync: {xref-cbl-pfx-replication}#delta-sync[Delta-Sync Replications]
119121
:xref-cbl-pg-blob: {xref-pfx-cbl}{cbl-pg-blob}[Blobs]

modules/ROOT/pages/_partials/commons/common-database.adoc

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ include::{root-partials}_set-platform.adoc[]
77
:topic-group: Topic Group -- Data Model
88
include::{root-partials}block-abstract.adoc[]
99

10+
:fn-2-8: footnote:fn28[Commencing with Release 2.8]
11+
:fnref-2-8: footnote:fn28[]
12+
1013
// BEGIN: Conditional Block -- applies to Android and JVM Java
1114
ifdef::is-android,is-java[]
1215
// Output block only for Android and Java modules
@@ -26,129 +29,128 @@ include::{snippet}[tag=sdk-initializer,indent=0]
2629
endif::[]
2730
// END: Conditional Block -- applies to Android and JVM Java
2831

29-
// == Default Database Location
30-
// By default, _Couchbase Lite on {param-title}_ creates databases in the following path location shown in <<default-path>>.
32+
[#open-db]
33+
== Create or Open Database
3134

32-
// [#default-path]
33-
// .Default database path
34-
// ====
35-
// [source, {console}]
36-
// ----
37-
// <root dir>/.couchbase/<db name>.cblite // <.>
38-
// ----
35+
You can create a new database and-or open and existing database, using the {url-api-class-database} class.
36+
Just pass in a database name and optionally a {url-api-class-databasecfg} -- see <<ex-dbopen>>.
3937

40-
// ifdef::is-java[<.> Where the <root dir> is the directory in which JVM was started.]
41-
// ifdef::is-android[<.> Where the <root dir> can be identified using `context.getFilesDir()`]
38+
Things to watch for include:
4239

43-
// ====
40+
* Opening/Creating a database is an asynchronous process
41+
* If the named database does not exist in the specified, or default, location then a new one is created
42+
* The database is created in a default location unless you specify a directory for it -- see: {url-api-class-databasecfg} and {url-api-method-databasecfg-setdir}
43+
+
44+
--
45+
TIP: Best Practice is to always specify the path to the database explicitly.
4446
45-
[#open-db]
46-
== New Database
47-
As the top-level entity in the API, new databases can be created using the `Database` class by passing in a name, configuration, or both.
48-
The following example opens, or creates, a database using the `Database(String name, DatabaseConfiguration config)` method.
47+
Typically, the default location for {param-title} is
48+
ifndef::is-csharp[]
49+
the application sandbox.
50+
endif::[]
51+
ifdef::is-csharp[]
52+
a platform-dependant location:
53+
54+
include::{module-partials}database-finding-file.adoc[tags=list-only]
55+
endif::[]
56+
57+
See also <<lbl-find-db-loc>>.
58+
--
4959

60+
[#ex-dbopen]
5061
.Open or create a database
5162
====
5263
[source, {source-language}]
5364
----
5465
include::{snippet}[tag=new-database,indent=0]
5566
----
5667

57-
Just as before, the database will be created in a default location.
58-
Alternatively, the `Database(string name, DatabaseConfiguration config)` initializer can be used to provide specific options in the {url-api-references}/com/couchbase/lite/DatabaseConfiguration.html[`DatabaseConfiguration`] object.
59-
6068
<.> Here we are specifying the database directory path.
69+
6170
====
6271
63-
* Remember that:
64-
** Opening (or creating) a database is asynchronous.
65-
** Closing a database is a *synchronous* operation, it is effective immediately
72+
== Close Database
73+
You are advised to incorporate the closing of all open databases into your application workflow.
6674
67-
[NOTE]
68-
--
69-
You cannot close a database that is not fully open.
75+
Closing a database is a simple, just use {url-api-method-database-close} -- see: <<ex-dbclose>>. +
76+
However, there are a number of things to be aware of:
7077
78+
* Closing a database is a *synchronous* operation, it is effective immediately
79+
* You cannot close a database that is not open. +
80+
Remember that opening (or creating) a database is asynchronous.
7181
So issuing a close immediately after initiating an open/create, may result in an error if that process has not completed.
72-
--
7382
74-
== Database Encryption
75-
// tag::database-encryption[]
76-
include::{root-partials}_block-caveats.adoc[tag=ee-only-feature]
83+
* Closing a database {fn-2-8} also closes any active replications, listeners and-or live queries attached to the database. +
84+
Closing a database immediately after kicking-off a replication could cause the sync to generate an exception. +
85+
For example: +
86+
`IllegalStateException: Attempt to perform an operation on a closed database`
7787
78-
_Couchbase Lite on {param-title}_ includes the ability to encrypt Couchbase Lite databases.
79-
This allows mobile applications to secure the data at rest, when it is being stored on the device.
80-
The algorithm used to encrypt the database is 256-bit AES.
88+
.Safely Closing a Database pre 2.8
89+
[TIP]
90+
--
91+
. Stop any active live queries -- by removing the query's change listener
92+
. Remove any active replication change listeners
93+
. Stop any active replications -- this is an asynchronous operation
94+
. Wait for all active replications to fully stop -- for this you can monitor the replication status -- see: {xref-cbl-pg-replication--monitor-status}.
95+
. Finally, close the database
8196
82-
To enable encryption, you must set the `DatabaseConfiguration.encryptionKey` property to the encryption key of your choice.
83-
Provide this encryption key every time the database is opened.
97+
--
8498
85-
.Database encryption
99+
[#ex-dbclose]
100+
.Close a Database
86101
====
87102
[source, {source-language}]
88103
----
89-
include::{snippet}[tag=database-encryption,indent=0]
104+
include::{snippet}[tag=close-database,indent=0]
90105
----
106+
91107
====
92108
93-
Couchbase Lite does not persist the key.
94-
It is the application's responsibility to manage the key and store it in a platform specific secure store such as Apple's https://developer.apple.com/documentation/security/keychain_services[Keychain] or Android's https://developer.android.com/training/articles/keystore[Keystore].
109+
== Database Encryption
95110
96-
An encrypted database can only be opened with the same language SDK that was used to encrypt it in the first place.
97-
So a database encrypted using the Swift SDK, and then exported, is readable only by the Swift SDK.
111+
:param-language: {param-name}
112+
include::{root-partials}database-encryption.adoc[]
98113
99-
=== Upgrading from 1.x when Encryption is Enabled
100114
101-
If you're migrating an application from Couchbase Lite 1.x to 2.x, note that the <<database-upgrade,automatic database upgrade>> functionality is *not supported* for encrypted databases.
102-
Thus, to upgrade an encrypted 1.x database, you should do the following:
115+
[#lbl-find-db-loc]
116+
== Finding a Database File
103117
104-
// set the correct language name for 1.4 pages
105-
ifeval::["{param-name}"=="{lang-name-android}"]
106-
:param-language: {lang-name-java}
118+
:tags: {empty}
119+
ifdef::is-csharp[]
120+
:tags: "tags=list-only"
107121
endif::[]
108-
. Disable encryption using the Couchbase Lite 1.x framework (see https://docs-archive.couchbase.com/couchbase-lite/1.4/{param-name}.html#database-encryption[1.x encryption guide])
109-
. Open the database file with encryption enabled using the Couchbase Lite 2.x framework.
110-
111-
Since it is not possible to package Couchbase Lite 1.x and Couchbase Lite 2.x in the same application this upgrade path would require two successive upgrades.
112-
If you are using Sync Gateway to synchronize the database content, it may be preferable to run a pull replication from a new 2.x database with encryption enabled and delete the 1.x local database.
113-
114-
// end::database-encryption[]
115-
116-
== Finding a Database File
117122
118-
include::{module-partials}database-finding-file.adoc[]
123+
include::{module-partials}database-finding-file.adoc[{tags}]
119124
120125
121126
[#cli-tool]
122127
== Command Line Tool
123128
124129
// tag::cli-tool[]
125-
126-
`cblite` is a command-line tool for inspecting and querying Couchbase Lite 2.x databases.
127-
128-
You can download and build it from the couchbaselabs https://github.com/couchbaselabs/couchbase-mobile-tools/blob/master/README.cblite.md[GitHub repository].
129-
130-
NOTE: The `cblite` tool is not covered under the https://www.couchbase.com/support-policy[Couchbase Support Policy].
130+
include::{root-partials}cli-tool.adoc[]
131131
132132
// end::cli-tool[]
133133
134-
== Logging
135-
136-
If you are using a Couchbase Lite release prior to 2.5 see <<pre-2x5-logging, Deprecated functionality>>
134+
== Troubleshooting
135+
You should use Couchbase's console logs as your first source of diagnostic information.
136+
If the information in the default logging level is insufficient you can focus it on database errors and generate more verbose messages -- see: <<ex-logdb>>.
137137
138-
include::{root-commons}logging.adoc[leveloffset=+2]
139-
140-
[#pre-2x5-logging]
141-
=== Logging functionality prior to Release 2.5
142-
143-
include::{root-partials}logging-pre2.5.adoc[]
138+
For more on using Couchbase logs -- see: {xref-cbl-pg-troubleshooting-logs}.
144139
140+
[#ex-logdb]
141+
.Increase Level of Database Log Messages
142+
====
143+
[source, {source-language}]
144+
----
145+
include::{snippet}[tag=console-logging-db, indent=0]
145146
146-
// == Loading a pre-built database
147+
----
148+
====
147149
148-
// include::{root-partials}database-load-prebuilt.adoc[]
149150
150151
// DO NOT DELETE
151-
// Include standard footer
152+
// Include standard
153+
152154
include::{root-partials}block-related-content-std.adoc[]
153155
// DO NOT DELETE
154156

modules/ROOT/pages/_partials/commons/common-logging.adoc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ ifeval::["{param-platform}"=="{platform-net}"]
3434
:logging-classes: {url-api-class-logging}
3535
endif::[]
3636

37-
ifdef::is-android[]
3837
.Constraints
39-
endif::[]
40-
4138
[NOTE]
4239
--
43-
The retrieval of logs from the device is out of scope of this feature.
44-
4540
ifdef::is-android[]
46-
The value returned by `LogLevel.getValue()` is not the Android log level.
41+
* The value returned by `LogLevel.getValue()` is not the Android log level.
4742
Do not use this API call.
4843
endif::[]
44+
45+
* The retrieval of logs from the device is out of scope of this feature.
46+
* This content applies to the post 2.5 versions.
47+
If you are using a Couchbase Lite release prior to 2.5 see <<pre-2x5-logging, Deprecated functionality>>
48+
4949
--
5050

5151

@@ -266,6 +266,12 @@ $ .\cbl-log.exe logcat LOGFILE <OUTPUT_PATH>
266266
====
267267
=====
268268

269+
[#pre-2x5-logging]
270+
=== Logging functionality prior to Release 2.5
271+
272+
include::{root-partials}logging-pre2.5.adoc[]
273+
274+
269275
// Begin - Output related content unless this inclusion is used as part of an encompassing page
270276
ifdef::param-fullpage[]
271277
include::{root-partials}block-related-content-query.adoc[]

0 commit comments

Comments
 (0)