SlideShare a Scribd company logo
1 of 49
CouchDB on Android
about
Sven Haiges, hybris GmbH
  Twitter @hansamann

    Android, HTML5,
    Groovy & Grails


 sven.haiges@hybris.de
about
Sven Haiges, hybris GmbH
  Twitter @hansamann

    Android, HTML5,
    Groovy & Grails


 sven.haiges@hybris.de
CouchDB
Erlang on
                                     Android!
Source: http://couchdb.apache.org/
sync
CouchDB
• document-based, RESTful HTTP API
• replication built-in
• both database and web server
• no locks, uses multi-version concurrency
  control
• Map & Reduce Functions = Views
<host>/_utils = Futon Admin
Mobile Futon
Accessing
your couch
adb forward tcp:5999 tcp:33595
build your own
#1 new android
    project
#2 add couchbase.zip
http://www.couchbase.org/get/couchbase-mobile-for-
                 android/current
#3 run as Ant file
done...
AndroidManifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
	   package="de.flavor.relax" android:versionCode="1" android:versionName="1.0">
	   <uses-sdk android:minSdkVersion="10" />

	   <application android:icon="@drawable/icon" android:label="@string/app_name">
	   	   <activity android:name=".RelaxActivity" android:label="@string/app_name">
	   	   	    <intent-filter>
	   	   	    	   <action android:name="android.intent.action.MAIN" />
	   	   	    	   <category android:name="android.intent.category.LAUNCHER" />
	   	   	    </intent-filter>
	   	   </activity>

	   	    <service android:exported="false" android:enabled="true"
	   	    	   android:name="com.couchbase.android.CouchbaseService" />
	   </application>
	   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
	   <uses-permission android:name="android.permission.INTERNET" />
	   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
in your Activity...
private final ICouchbaseDelegate mDelegate = new ICouchbaseDelegate() {

     public void couchbaseStarted(String host, int port) {
     	
     Toast.makeText(RelaxActivity.this, host + ":" + port, Toast.LENGTH_LONG).show();
     }

     public void installing(int completed, int total) {
     	
     Log.d("demo", "Installing... " + completed + "/" + total);
     }

     public void exit(String error) {
     	
     Log.d("demo", error);
     }
};
in your Activity...

@Override
protected void onResume() {
	   super.onResume();
	   CouchbaseMobile couch = new CouchbaseMobile(getBaseContext(), mDelegate);
	   couchServiceConnection = couch.startCouchbase();
}
ektorp
AndCouch
AndCouch

• https://github.com/daleharvey/Android-
  MobileFuton
• Just a quick HTTP wrapper, but gets the job
  done!
• CouchDemo App...
Todo.java
public class Todo {
	
	   private String id;
	   private String rev;
	   private String text;
	   private long timestamp;
	
	   public Todo(String id, String rev, String text, long timestamp) {
	   	    super();
	   	    this.id = id;
	   	    this.rev = rev;
	   	    this.text = text;
	   	    this.timestamp = timestamp;
	   }
	   ...
}
Creating
String value = input.getText().toString();

JSONObject obj = new JSONObject();

try   {
	     obj.put("type", "todo");
	     obj.put("text", value);
	     obj.put("timestamp", new Date().getTime());

	     JSONObject result = AndCouch.put(baseURL
	     	   	    + DB_NAME + "/"
	     	   	    + UUID.randomUUID().toString(),
	     	   	    obj.toString()).json;

	   if (result.getBoolean("ok") == true)
	   	    refreshTodos();
} catch (JSONException e) {
	   e.printStackTrace();
}
Reading (all)
try {
	   todos.clear();

	   JSONObject json = AndCouch.get(baseURL + DB_NAME + "/_design/todo/_view/all").json;
	   JSONArray rows = json.getJSONArray("rows");

	   for   (int i = 0; i < rows.length(); i++) {
	   	     JSONObject todoObj = rows.getJSONObject(i);
	   	     JSONArray value = todoObj.getJSONArray("value");
	   	     todos.add(new Todo(todoObj.getString("id"), value.getString(1),
	   	     	    	   value.getString(0), todoObj.getLong("key")));
	   }

	   todos.notifyDataSetChanged();

} catch (JSONException e) {
	   e.printStackTrace();
}
Reading (all)
try {
	   todos.clear();

	   JSONObject json = AndCouch.get(baseURL + DB_NAME + "/_design/todo/_view/all").json;
	   JSONArray rows = json.getJSONArray("rows");

	   for   (int i = 0; i < rows.length(); i++) {
	   	     JSONObject todoObj = rows.getJSONObject(i);
	   	     JSONArray value = todoObj.getJSONArray("value");
	   	     todos.add(new Todo(todoObj.getString("id"), value.getString(1),
	   	     	    	   value.getString(0), todoObj.getLong("key")));
	   }

	   todos.notifyDataSetChanged();

} catch (JSONException e) {
	   e.printStackTrace();
}
Design Documents

• normal json documents, but ids begin with
  _design/, e.g. _design/myapp (no %2F :-)
• contain views (Map & Reduce functions) as
  well as other application functions
  (validation, show/list)
Simple Design Doc

{
	    "_id":"_design/todo",
	    "views" : {
	    	    "all" : {
	    	    	   "map": "function(doc) { if (doc.type && doc.type === 'todo')
{   emit(doc.timestamp, [doc.text, doc._rev]); }};"
	    	    }
	    }
}
Deleting
SparseBooleanArray spar = getListView().getCheckedItemPositions();

for   (int i = 0; i < todos.getCount(); i++) {
	     if (spar.get(i)) {
	     	    Todo todo = todos.getItem(i);
	     	    getListView().setItemChecked(i, false); 	

	   	    try {
	   	    	   AndCouch.httpRequest("DELETE", baseURL + DB_NAME + "/" + todo.getId() + "?
rev=" + todo.getRev(),
	   	    	   null, new String[][] {});
	   	    } catch (JSONException e) {
	   	    	   e.printStackTrace();
	   	    }
	   }
}

refreshTodos();
Remote Push
JSONObject obj = new JSONObject();

try   {
	     obj.put("create_target", true);
	     obj.put("source", baseURL + DB_NAME);
	     obj.put("target",
	     	   	    "http://	hansamann.iriscouch.com/todo");

	   JSONObject result = AndCouch.post(baseURL + "_replicate",
	   	    	   obj.toString()).json;
} catch (JSONException e) {
	   // TODO Auto-generated catch block
	   e.printStackTrace();
}
CouchApps
CouchApps
• JavaScript and HTML5 apps served from
  CouchDB
• No middle tier, Couch is DB + application
  server
• CouchApp.org hosts the CouchApp
  development tool that pushes changes to a
  Couch instance
about
Sven Haiges, hybris GmbH
  Twitter @hansamann

    Android, HTML5,
    Groovy & Grails


 sven.haiges@hybris.de
about
Sven Haiges, hybris GmbH
  Twitter @hansamann

    Android, HTML5,
    Groovy & Grails


 sven.haiges@hybris.de

                           NFC

More Related Content

What's hot

Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...MongoDB
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDBTakahiro Inoue
 
20110514 mongo dbチューニング
20110514 mongo dbチューニング20110514 mongo dbチューニング
20110514 mongo dbチューニングYuichi Matsuo
 
NoSQL & MongoDB
NoSQL & MongoDBNoSQL & MongoDB
NoSQL & MongoDBShuai Liu
 
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMongoDB
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB
 
神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)guregu
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETTomas Jansson
 
7주 JavaScript 실습
7주 JavaScript 실습7주 JavaScript 실습
7주 JavaScript 실습지수 윤
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Groupkchodorow
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSMongoDB
 
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
High Performance XQuery Processing in PHP with Zorba by Vikram VaswaniHigh Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswanivvaswani
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! aleks-f
 
Mongoose and MongoDB 101
Mongoose and MongoDB 101Mongoose and MongoDB 101
Mongoose and MongoDB 101Will Button
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserHoward Lewis Ship
 
Mongoose getting started-Mongo Db with Node js
Mongoose getting started-Mongo Db with Node jsMongoose getting started-Mongo Db with Node js
Mongoose getting started-Mongo Db with Node jsPallavi Srivastava
 

What's hot (20)

Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
 
Indexing
IndexingIndexing
Indexing
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDB
 
20110514 mongo dbチューニング
20110514 mongo dbチューニング20110514 mongo dbチューニング
20110514 mongo dbチューニング
 
NoSQL & MongoDB
NoSQL & MongoDBNoSQL & MongoDB
NoSQL & MongoDB
 
Elastic search 검색
Elastic search 검색Elastic search 검색
Elastic search 검색
 
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() Output
 
神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)神に近づくx/net/context (Finding God with x/net/context)
神に近づくx/net/context (Finding God with x/net/context)
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
7주 JavaScript 실습
7주 JavaScript 실습7주 JavaScript 실습
7주 JavaScript 실습
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJS
 
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
High Performance XQuery Processing in PHP with Zorba by Vikram VaswaniHigh Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
 
MongoDB
MongoDBMongoDB
MongoDB
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
 
Mongoose and MongoDB 101
Mongoose and MongoDB 101Mongoose and MongoDB 101
Mongoose and MongoDB 101
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
Mongoose getting started-Mongo Db with Node js
Mongoose getting started-Mongo Db with Node jsMongoose getting started-Mongo Db with Node js
Mongoose getting started-Mongo Db with Node js
 

Similar to CouchDB on Android: Access Database Remotely

Paris js extensions
Paris js extensionsParis js extensions
Paris js extensionserwanl
 
Spicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QASpicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QAAlban Gérôme
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineRicardo Silva
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineAndy McKay
 
Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology updateDoug Domeny
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomerzefhemel
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourPeter Friese
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajaxbaygross
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecturezefhemel
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Matthew Groves
 
Full Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLFull Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLAll Things Open
 
API Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API DocumentationAPI Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API DocumentationRouven Weßling
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyHuiyi Yan
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCpootsbook
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)MongoDB
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 

Similar to CouchDB on Android: Access Database Remotely (20)

Paris js extensions
Paris js extensionsParis js extensions
Paris js extensions
 
mobl
moblmobl
mobl
 
huhu
huhuhuhu
huhu
 
Spicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QASpicy javascript: Create your first Chrome extension for web analytics QA
Spicy javascript: Create your first Chrome extension for web analytics QA
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
Html5 and web technology update
Html5 and web technology updateHtml5 and web technology update
Html5 and web technology update
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomer
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 Hour
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecture
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
Full Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQLFull Stack Development with Node.js and NoSQL
Full Stack Development with Node.js and NoSQL
 
API Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API DocumentationAPI Days Paris - Automatic Testing of (RESTful) API Documentation
API Days Paris - Automatic Testing of (RESTful) API Documentation
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 

More from Sven Haiges

NFC and Commerce combined
NFC and Commerce combinedNFC and Commerce combined
NFC and Commerce combinedSven Haiges
 
End to End Realtime Communication using Mobiel Devices and the Web
End to End Realtime Communication using Mobiel Devices and the WebEnd to End Realtime Communication using Mobiel Devices and the Web
End to End Realtime Communication using Mobiel Devices and the WebSven Haiges
 
NFC Android Introduction
NFC Android IntroductionNFC Android Introduction
NFC Android IntroductionSven Haiges
 
Gesture-controlled web-apps
Gesture-controlled web-appsGesture-controlled web-apps
Gesture-controlled web-appsSven Haiges
 
NFC on Android - Near Field Communication
NFC on Android - Near Field CommunicationNFC on Android - Near Field Communication
NFC on Android - Near Field CommunicationSven Haiges
 
Grails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleyGrails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleySven Haiges
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishSven Haiges
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006
Grails 0.3-SNAPSHOT Presentation WJAX 2006Grails 0.3-SNAPSHOT Presentation WJAX 2006
Grails 0.3-SNAPSHOT Presentation WJAX 2006Sven Haiges
 

More from Sven Haiges (11)

NFC and Commerce combined
NFC and Commerce combinedNFC and Commerce combined
NFC and Commerce combined
 
End to End Realtime Communication using Mobiel Devices and the Web
End to End Realtime Communication using Mobiel Devices and the WebEnd to End Realtime Communication using Mobiel Devices and the Web
End to End Realtime Communication using Mobiel Devices and the Web
 
NFC Android Introduction
NFC Android IntroductionNFC Android Introduction
NFC Android Introduction
 
Gesture-controlled web-apps
Gesture-controlled web-appsGesture-controlled web-apps
Gesture-controlled web-apps
 
NFC on Android - Near Field Communication
NFC on Android - Near Field CommunicationNFC on Android - Near Field Communication
NFC on Android - Near Field Communication
 
Android UI
Android UIAndroid UI
Android UI
 
Html5
Html5Html5
Html5
 
Grails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleyGrails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon Valley
 
Grails and Dojo
Grails and DojoGrails and Dojo
Grails and Dojo
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006
Grails 0.3-SNAPSHOT Presentation WJAX 2006Grails 0.3-SNAPSHOT Presentation WJAX 2006
Grails 0.3-SNAPSHOT Presentation WJAX 2006
 

Recently uploaded

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

CouchDB on Android: Access Database Remotely

  • 2. about Sven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails sven.haiges@hybris.de
  • 3. about Sven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails sven.haiges@hybris.de
  • 5. Erlang on Android! Source: http://couchdb.apache.org/
  • 7. CouchDB • document-based, RESTful HTTP API • replication built-in • both database and web server • no locks, uses multi-version concurrency control • Map & Reduce Functions = Views
  • 8.
  • 11.
  • 13. adb forward tcp:5999 tcp:33595
  • 14.
  • 15.
  • 17. #1 new android project
  • 18.
  • 20.
  • 21. #3 run as Ant file
  • 22.
  • 24. AndroidManifest.xml <?xml version="1.0" encoding="UTF-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.flavor.relax" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="10" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".RelaxActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:exported="false" android:enabled="true" android:name="com.couchbase.android.CouchbaseService" /> </application> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> </manifest>
  • 25. in your Activity... private final ICouchbaseDelegate mDelegate = new ICouchbaseDelegate() { public void couchbaseStarted(String host, int port) { Toast.makeText(RelaxActivity.this, host + ":" + port, Toast.LENGTH_LONG).show(); } public void installing(int completed, int total) { Log.d("demo", "Installing... " + completed + "/" + total); } public void exit(String error) { Log.d("demo", error); } };
  • 26. in your Activity... @Override protected void onResume() { super.onResume(); CouchbaseMobile couch = new CouchbaseMobile(getBaseContext(), mDelegate); couchServiceConnection = couch.startCouchbase(); }
  • 29. AndCouch • https://github.com/daleharvey/Android- MobileFuton • Just a quick HTTP wrapper, but gets the job done! • CouchDemo App...
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38. Todo.java public class Todo { private String id; private String rev; private String text; private long timestamp; public Todo(String id, String rev, String text, long timestamp) { super(); this.id = id; this.rev = rev; this.text = text; this.timestamp = timestamp; } ... }
  • 39. Creating String value = input.getText().toString(); JSONObject obj = new JSONObject(); try { obj.put("type", "todo"); obj.put("text", value); obj.put("timestamp", new Date().getTime()); JSONObject result = AndCouch.put(baseURL + DB_NAME + "/" + UUID.randomUUID().toString(), obj.toString()).json; if (result.getBoolean("ok") == true) refreshTodos(); } catch (JSONException e) { e.printStackTrace(); }
  • 40. Reading (all) try { todos.clear(); JSONObject json = AndCouch.get(baseURL + DB_NAME + "/_design/todo/_view/all").json; JSONArray rows = json.getJSONArray("rows"); for (int i = 0; i < rows.length(); i++) { JSONObject todoObj = rows.getJSONObject(i); JSONArray value = todoObj.getJSONArray("value"); todos.add(new Todo(todoObj.getString("id"), value.getString(1), value.getString(0), todoObj.getLong("key"))); } todos.notifyDataSetChanged(); } catch (JSONException e) { e.printStackTrace(); }
  • 41. Reading (all) try { todos.clear(); JSONObject json = AndCouch.get(baseURL + DB_NAME + "/_design/todo/_view/all").json; JSONArray rows = json.getJSONArray("rows"); for (int i = 0; i < rows.length(); i++) { JSONObject todoObj = rows.getJSONObject(i); JSONArray value = todoObj.getJSONArray("value"); todos.add(new Todo(todoObj.getString("id"), value.getString(1), value.getString(0), todoObj.getLong("key"))); } todos.notifyDataSetChanged(); } catch (JSONException e) { e.printStackTrace(); }
  • 42. Design Documents • normal json documents, but ids begin with _design/, e.g. _design/myapp (no %2F :-) • contain views (Map & Reduce functions) as well as other application functions (validation, show/list)
  • 43. Simple Design Doc { "_id":"_design/todo", "views" : { "all" : { "map": "function(doc) { if (doc.type && doc.type === 'todo') { emit(doc.timestamp, [doc.text, doc._rev]); }};" } } }
  • 44. Deleting SparseBooleanArray spar = getListView().getCheckedItemPositions(); for (int i = 0; i < todos.getCount(); i++) { if (spar.get(i)) { Todo todo = todos.getItem(i); getListView().setItemChecked(i, false); try { AndCouch.httpRequest("DELETE", baseURL + DB_NAME + "/" + todo.getId() + "? rev=" + todo.getRev(), null, new String[][] {}); } catch (JSONException e) { e.printStackTrace(); } } } refreshTodos();
  • 45. Remote Push JSONObject obj = new JSONObject(); try { obj.put("create_target", true); obj.put("source", baseURL + DB_NAME); obj.put("target", "http:// hansamann.iriscouch.com/todo"); JSONObject result = AndCouch.post(baseURL + "_replicate", obj.toString()).json; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); }
  • 47. CouchApps • JavaScript and HTML5 apps served from CouchDB • No middle tier, Couch is DB + application server • CouchApp.org hosts the CouchApp development tool that pushes changes to a Couch instance
  • 48. about Sven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails sven.haiges@hybris.de
  • 49. about Sven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails sven.haiges@hybris.de NFC

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n