diff --git a/.gitignore b/.gitignore index 7f8b0be69..c8bb4b645 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,7 @@ deploy/.vagrant/ .vscode/ .vs/ *.user + +modules/ROOT/holding-bin/*.* +modules/ROOT/temp-bin/*.* +modules/swift/examples/thisbin/Untitled-1.swift diff --git a/modules/ROOT/examples/query-snippets.adoc b/modules/ROOT/examples/query-snippets.adoc new file mode 100644 index 000000000..fb202c391 --- /dev/null +++ b/modules/ROOT/examples/query-snippets.adoc @@ -0,0 +1,71 @@ + + +// DATA FORMAT RETURNED WHEN SELECTING SPECIFIC ID +// tag::query-result-format-id[] +[ + { + "id": "hotel123" + }, + { + "id": "hotel456" + }, +] +// end::query-result-format-id[] + + +// DATA FORMAT RETURNED WHEN SELECTING SPECIFIC PROPS +// tag::query-result-format-props[] +[ + { // <.> + "id": "hotel123", + "type": "hotel", + "name": "Hotel Ghia" + }, + { // <.> + "id": "hotel456", + "type": "hotel", + "name": "Hotel Deluxe", + } +] +// end::query-result-format-props[] + + +// DATA FORMAT RETURNED WHEN SELECTING COUNT ONLY +// tag::query-result-format-count[] +{ + "mycount": 6 +} + +// end::query-result-format-count[] + + +// DATA FORMAT RETURNED WHEN SELECTING SPECIFIC all +// tag::query-result-format-all[] +[ + { + "travel-sample": { // <.> + "callsign": "MILE-AIR", + "country": "United States", + "iata": "Q5", + "icao": "MLA", + "id": 10, + "name": "40-Mile Air", + "type": "airline" + } + }, + { + "travel-sample": { // <.> + "callsign": "ALASKAN-AIR", + "country": "United States", + "iata": "AA", + "icao": "AAA", + "id": 10, + "name": "Alaskan Airways", + "type": "airline" + } + } +] + +// end::query-result-format-all[] + + diff --git a/modules/android/examples/docsnippets/.gitignore b/modules/android/examples/docsnippets/.gitignore new file mode 100644 index 000000000..603b14077 --- /dev/null +++ b/modules/android/examples/docsnippets/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/modules/android/examples/docsnippets/.settings/org.eclipse.buildship.core.prefs b/modules/android/examples/docsnippets/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 000000000..c2a22258a --- /dev/null +++ b/modules/android/examples/docsnippets/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,13 @@ +arguments= +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) +connection.project.dir= +eclipse.preferences.version=1 +gradle.user.home=/Users/ianbridge/.gradle +java.home=/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/modules/android/examples/docsnippets/app/.classpath b/modules/android/examples/docsnippets/app/.classpath new file mode 100644 index 000000000..f38e320f5 --- /dev/null +++ b/modules/android/examples/docsnippets/app/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/modules/android/examples/docsnippets/app/.gitignore b/modules/android/examples/docsnippets/app/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/modules/android/examples/docsnippets/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/modules/android/examples/docsnippets/app/.settings/org.eclipse.buildship.core.prefs b/modules/android/examples/docsnippets/app/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 000000000..b1886adb4 --- /dev/null +++ b/modules/android/examples/docsnippets/app/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir=.. +eclipse.preferences.version=1 diff --git a/modules/android/examples/docsnippets/app/build.gradle b/modules/android/examples/docsnippets/app/build.gradle new file mode 100644 index 000000000..5d474d267 --- /dev/null +++ b/modules/android/examples/docsnippets/app/build.gradle @@ -0,0 +1,50 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 30 + + defaultConfig { + applicationId "com.example.docsnippet" + minSdkVersion 26 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +repositories { + maven { url 'https://mobile.maven.couchbase.com/maven2/dev/' } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.navigation:navigation-fragment-ktx:2.3.3' + implementation 'androidx.navigation:navigation-ui-ktx:2.3.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation "com.couchbase.lite:couchbase-lite-android-ee:2.8.5" +} \ No newline at end of file diff --git a/modules/android/examples/docsnippets/app/proguard-rules.pro b/modules/android/examples/docsnippets/app/proguard-rules.pro new file mode 100644 index 000000000..481bb4348 --- /dev/null +++ b/modules/android/examples/docsnippets/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/modules/android/examples/docsnippets/app/src/androidTest/java/com/example/docsnippet/ExampleInstrumentedTest.kt b/modules/android/examples/docsnippets/app/src/androidTest/java/com/example/docsnippet/ExampleInstrumentedTest.kt new file mode 100644 index 000000000..afac776d6 --- /dev/null +++ b/modules/android/examples/docsnippets/app/src/androidTest/java/com/example/docsnippet/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.docsnippet + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.docsnippet", appContext.packageName) + } +} \ No newline at end of file diff --git a/modules/android/examples/docsnippets/app/src/main/AndroidManifest.xml b/modules/android/examples/docsnippets/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..b57d867a1 --- /dev/null +++ b/modules/android/examples/docsnippets/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/android/examples/docsnippets/app/src/main/java/com/example/docsnippet/Datastore.java b/modules/android/examples/docsnippets/app/src/main/java/com/example/docsnippet/Datastore.java new file mode 100644 index 000000000..ed42e8f61 --- /dev/null +++ b/modules/android/examples/docsnippets/app/src/main/java/com/example/docsnippet/Datastore.java @@ -0,0 +1,166 @@ +package com.example.docsnippet; +import android.app.Application.*; +import android.content.Context; +import android.content.Context.*; +import java.lang.Object; +import java.util.*; +import com.couchbase.lite.*; + +public class Datastore { + + +//{ +// return = initialize_DB(dbName); +//} +// +private static boolean is_Connected; +private static boolean is_Initialized; +private static String dbName; +private static Database db; + +static { + init(); +} + + + + public Database getDB() { + + return db; + + } + + public boolean addItem(Item arg_item) throws CouchbaseLiteException { + boolean thisResult = false; + + if (is_Connected) + { + try { + db.save(arg_item.ToMutableDocument()); + } catch (CouchbaseLiteException egg) { + System.out.println("Exception saving item " + arg_item.toString()); + egg.printStackTrace(); + } + thisResult = true; + } + else + { + System.out.println("DB NOT CONNECTED"); + } + + return thisResult; + } + + + public Item getItem(String arg_id) { + + if (is_Connected) { + return new Item().FromMutableDocument(db.getDocument(arg_id).toMutable()); + } else { + return null; + } + } + + + public List getItems() { + + if (is_Connected) { + + List thisItemList = new ArrayList(); + + MutableDocument thisDoc = new MutableDocument(); + + Query query = QueryBuilder + .select(SelectResult.expression(Meta.id).as("this_id")) + .from(DataSource.database(db)); + + try { + List results = query.execute().allResults(); + + if (results.size() > 0) { + for (Result result : results) { + + String thisId = result.getString("this_id"); + + MutableDocument thisDocX = new MutableDocument(); + thisDocX = db.getDocument(thisId).toMutable(); + Item thisItem = new Item().FromMutableDocument(thisDocX); + thisItemList.add(thisItem); + +// thisItemList.add(new Item().FromMutableDocument(db.getDocument(result.getString("this_id")).toMutable())); + + } + } else {seedDB();} + + } catch(CouchbaseLiteException egg){ + egg.printStackTrace(); + } + + return thisItemList; + + } else{ + return null; + } + } + + + + + private static Database initialize_DB( String dbName) { + boolean thisResult = false; +// Context context = null; + +// if (is_Initialized == false) { +// CouchbaseLite.init(); +// is_Initialized = true; +// +// } + + db = null; + try { + db = new Database(dbName); + } catch (CouchbaseLiteException e) { + e.printStackTrace(); + } + + return db; + } + + public void forceSeedDB() throws CouchbaseLiteException { + + db.delete(); + initialize_DB(dbName); + try { + seedDB(); + } catch (CouchbaseLiteException e) { + e.printStackTrace(); + } + + } + + public static void init() { + is_Connected=false; + is_Initialized=false; + dbName="hotels"; + db = initialize_DB(dbName); + is_Connected = (db != null); + } + + private void seedDB() throws CouchbaseLiteException { + + MutableDocument thisMutDoc = new MutableDocument(); + thisMutDoc.setString("id", "1001"); + thisMutDoc.setString("Type", "hotel"); + thisMutDoc.setString("Name", "Hotel Fred"); + thisMutDoc.setString("City", "London"); + thisMutDoc.setString("Country", "England"); + thisMutDoc.setString("Description", "Seed hotel document description"); + thisMutDoc.setString("Text", "Seed hotel document text"); + + addItem(new Item().FromMutableDocument(thisMutDoc)); + + Item thisItem = new Item(); + + } + +} diff --git a/modules/android/examples/docsnippets/app/src/main/java/com/example/docsnippet/FirstFragment.java b/modules/android/examples/docsnippets/app/src/main/java/com/example/docsnippet/FirstFragment.java new file mode 100644 index 000000000..083a08cf8 --- /dev/null +++ b/modules/android/examples/docsnippets/app/src/main/java/com/example/docsnippet/FirstFragment.java @@ -0,0 +1,104 @@ +package com.example.docsnippet; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.View.OnClickListener; +import android.widget.Button; +import androidx.fragment.app.Fragment; +import androidx.navigation.fragment.FragmentKt; + +import java.util.ArrayList; +import java.util.HashMap; + +import kotlin.jvm.internal.Intrinsics; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.List; +import com.couchbase.lite.*; + +//@Metadata( +// mv = {1, 1, 16}, +// bv = {1, 0, 3}, +// k = 1, +// d1 = {"\u0000,\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J&\u0010\u0003\u001a\u0004\u0018\u00010\u00042\u0006\u0010\u0005\u001a\u00020\u00062\b\u0010\u0007\u001a\u0004\u0018\u00010\b2\b\u0010\t\u001a\u0004\u0018\u00010\nH\u0016J\u001a\u0010\u000b\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u00042\b\u0010\t\u001a\u0004\u0018\u00010\nH\u0016¨\u0006\u000e"}, +// d2 = {"Lcom/example/docsnippet/FirstFragment;", "Landroidx/fragment/app/Fragment;", "()V", "onCreateView", "Landroid/view/View;", "inflater", "Landroid/view/LayoutInflater;", "container", "Landroid/view/ViewGroup;", "savedInstanceState", "Landroid/os/Bundle;", "onViewCreated", "", "view", "app_debug"} +//) +public final class FirstFragment extends Fragment { + private HashMap _$_findViewCache; + + public List ItemList = new ArrayList(); + + @Nullable + public View onCreateView(@NotNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + Intrinsics.checkParameterIsNotNull(inflater, "inflater"); + + Datastore ds = new Datastore(); +// try { +// ds.forceSeedDB(); +// } catch (CouchbaseLiteException e) { +// e.printStackTrace(); +// } + TestQueries tq = new TestQueries(); + + ItemList = ds.getItems(); + + System.out.println(ItemList.toString()); + + try { +// tq.testQuerySyntaxAll(); +// tq.testQuerySyntaxProps(); +// tq.testQuerySyntaxCount(); + tq.testQuerySyntaxProps(); + tq.testQueryPagination(); + + } catch (CouchbaseLiteException e) { + e.printStackTrace(); + } + + return inflater.inflate(1300034, container, false); + } + + public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) { + Intrinsics.checkParameterIsNotNull(view, "view"); + super.onViewCreated(view, savedInstanceState); + ((Button)view.findViewById(1000220)).setOnClickListener((OnClickListener)(new OnClickListener() { + public final void onClick(View it) { + FragmentKt.findNavController(FirstFragment.this).navigate(1000292); + } + })); + } + + public View _$_findCachedViewById(int var1) { + if (this._$_findViewCache == null) { + this._$_findViewCache = new HashMap(); + } + + View var2 = (View)this._$_findViewCache.get(var1); + if (var2 == null) { + View var10000 = this.getView(); + if (var10000 == null) { + return null; + } + + var2 = var10000.findViewById(var1); + this._$_findViewCache.put(var1, var2); + } + + return var2; + } + + public void _$_clearFindViewByIdCache() { + if (this._$_findViewCache != null) { + this._$_findViewCache.clear(); + } + + } + + // $FF: synthetic method + public void onDestroyView() { + super.onDestroyView(); + this._$_clearFindViewByIdCache(); + } +} diff --git a/modules/android/examples/docsnippets/app/src/main/java/com/example/docsnippet/FirstFragment.kt b/modules/android/examples/docsnippets/app/src/main/java/com/example/docsnippet/FirstFragment.kt new file mode 100644 index 000000000..4e1c7ec87 --- /dev/null +++ b/modules/android/examples/docsnippets/app/src/main/java/com/example/docsnippet/FirstFragment.kt @@ -0,0 +1,35 @@ +//package com.example.docsnippet +// +//import android.os.Bundle +//import androidx.fragment.app.Fragment +//import android.view.LayoutInflater +//import android.view.View +//import android.view.ViewGroup +//import android.widget.Button +//import androidx.navigation.fragment.findNavController +// +///** +// * A simple [Fragment] subclass as the default destination in the navigation. +// */ +//class FirstFragment : Fragment() { +// +// override fun onCreateView( +// inflater: LayoutInflater, container: ViewGroup?, +// savedInstanceState: Bundle? +// ): View? { +// // Inflate the layout for this fragment +// +// var myds = Datastore.init(); +// +// +// return inflater.inflate(R.layout.fragment_first, container, false) +// } +// +// override fun onViewCreated(view: View, savedInstanceState: Bundle?) { +// super.onViewCreated(view, savedInstanceState) +// +// view.findViewById