SlideShare a Scribd company logo
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
CouchDB on Android
<host>/_utils = Futon Admin
Mobile Futon
CouchDB on Android
Accessing
your couch
adb forward tcp:5999 tcp:33595
CouchDB on Android
CouchDB on Android
build your own
#1 new android
    project
CouchDB on Android
#2 add couchbase.zip
http://www.couchbase.org/get/couchbase-mobile-for-
                 android/current
CouchDB on Android
#3 run as Ant file
CouchDB on Android
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...
CouchDB on Android
CouchDB on Android
CouchDB on Android
CouchDB on Android
CouchDB on Android
CouchDB on Android
CouchDB on Android
CouchDB on Android
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 (20)

PPTX
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
MongoDB
 
PDF
Indexing
Mike Dirolf
 
PDF
はじめてのMongoDB
Takahiro Inoue
 
PDF
20110514 mongo dbチューニング
Yuichi Matsuo
 
PDF
NoSQL & MongoDB
Shuai Liu
 
PDF
Elastic search 검색
HyeonSeok Choi
 
PDF
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB
 
PPTX
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
PDF
MongoDB World 2016: Deciphering .explain() Output
MongoDB
 
PDF
神に近づくx/net/context (Finding God with x/net/context)
guregu
 
PPTX
Getting started with Elasticsearch and .NET
Tomas Jansson
 
PDF
7주 JavaScript 실습
지수 윤
 
PDF
San Francisco Java User Group
kchodorow
 
PPTX
Getting Started with MongoDB and NodeJS
MongoDB
 
ODP
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
vvaswani
 
KEY
MongoDB
Steve Klabnik
 
PDF
Look Ma, “update DB to HTML5 using C++”, no hands! 
aleks-f
 
PPTX
Mongoose and MongoDB 101
Will Button
 
PDF
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship
 
DOCX
Mongoose getting started-Mongo Db with Node js
Pallavi Srivastava
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
MongoDB
 
Indexing
Mike Dirolf
 
はじめてのMongoDB
Takahiro Inoue
 
20110514 mongo dbチューニング
Yuichi Matsuo
 
NoSQL & MongoDB
Shuai Liu
 
Elastic search 검색
HyeonSeok Choi
 
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB
 
神に近づくx/net/context (Finding God with x/net/context)
guregu
 
Getting started with Elasticsearch and .NET
Tomas Jansson
 
7주 JavaScript 실습
지수 윤
 
San Francisco Java User Group
kchodorow
 
Getting Started with MongoDB and NodeJS
MongoDB
 
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
vvaswani
 
MongoDB
Steve Klabnik
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
aleks-f
 
Mongoose and MongoDB 101
Will Button
 
Backbone.js: Run your Application Inside The Browser
Howard Lewis Ship
 
Mongoose getting started-Mongo Db with Node js
Pallavi Srivastava
 

Similar to CouchDB on Android (20)

PDF
CouchDB Mobile - From Couch to 5K in 1 Hour
Peter Friese
 
PPTX
Quick and Easy Development with Node.js and Couchbase Server
Nic Raboy
 
PPTX
Mobile App Development With IBM Cloudant
IBM Cloud Data Services
 
PDF
Sync is hard: building offline-first Android apps from the ground up
droidcon Dubai
 
KEY
OSCON 2011 CouchApps
Bradley Holt
 
PDF
Couchbase Mobile on Android
Philipp Fehre
 
PDF
Agile Document Models & Data Structures
Clarence J M Tauro
 
PPTX
Developing for Offline First Mobile Experiences
Nic Raboy
 
PDF
From 0 to syncing
Philipp Fehre
 
PDF
Playing with parse.com
JUG Genova
 
ODP
CouchApp - Build scalable web applications and relax
openForce Information Technology GesmbH
 
PDF
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
IBM
 
PPTX
Couchbase Data Pipeline
Justin Michaels
 
PDF
Manuel Hurtado. Couchbase paradigma4oct
Paradigma Digital
 
PPTX
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Red Hat Developers
 
PDF
Full stack development with Node and NoSQL - Austin Node.JS Group - October ...
Matthew Groves
 
PPTX
Couchbase Data Platform | Big Data Demystified
Omid Vahdaty
 
ODP
Intro to CouchDB
sbisbee
 
PPTX
Beacon talk
ldoguin
 
PDF
Mobile Offline First
Julio Castro
 
CouchDB Mobile - From Couch to 5K in 1 Hour
Peter Friese
 
Quick and Easy Development with Node.js and Couchbase Server
Nic Raboy
 
Mobile App Development With IBM Cloudant
IBM Cloud Data Services
 
Sync is hard: building offline-first Android apps from the ground up
droidcon Dubai
 
OSCON 2011 CouchApps
Bradley Holt
 
Couchbase Mobile on Android
Philipp Fehre
 
Agile Document Models & Data Structures
Clarence J M Tauro
 
Developing for Offline First Mobile Experiences
Nic Raboy
 
From 0 to syncing
Philipp Fehre
 
Playing with parse.com
JUG Genova
 
CouchApp - Build scalable web applications and relax
openForce Information Technology GesmbH
 
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
IBM
 
Couchbase Data Pipeline
Justin Michaels
 
Manuel Hurtado. Couchbase paradigma4oct
Paradigma Digital
 
Full Stack Development With Node.Js And NoSQL (Nic Raboy & Arun Gupta)
Red Hat Developers
 
Full stack development with Node and NoSQL - Austin Node.JS Group - October ...
Matthew Groves
 
Couchbase Data Platform | Big Data Demystified
Omid Vahdaty
 
Intro to CouchDB
sbisbee
 
Beacon talk
ldoguin
 
Mobile Offline First
Julio Castro
 
Ad

More from Sven Haiges (11)

PDF
NFC and Commerce combined
Sven Haiges
 
PDF
End to End Realtime Communication using Mobiel Devices and the Web
Sven Haiges
 
PDF
NFC Android Introduction
Sven Haiges
 
PDF
Gesture-controlled web-apps
Sven Haiges
 
KEY
NFC on Android - Near Field Communication
Sven Haiges
 
PDF
Android UI
Sven Haiges
 
KEY
Html5
Sven Haiges
 
PDF
Grails @ Java User Group Silicon Valley
Sven Haiges
 
PPT
Grails and Dojo
Sven Haiges
 
ODP
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Sven Haiges
 
ODP
Grails 0.3-SNAPSHOT Presentation WJAX 2006
Sven Haiges
 
NFC and Commerce combined
Sven Haiges
 
End to End Realtime Communication using Mobiel Devices and the Web
Sven Haiges
 
NFC Android Introduction
Sven Haiges
 
Gesture-controlled web-apps
Sven Haiges
 
NFC on Android - Near Field Communication
Sven Haiges
 
Android UI
Sven Haiges
 
Grails @ Java User Group Silicon Valley
Sven Haiges
 
Grails and Dojo
Sven Haiges
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Sven Haiges
 
Grails 0.3-SNAPSHOT Presentation WJAX 2006
Sven Haiges
 
Ad

Recently uploaded (20)

PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
July Patch Tuesday
Ivanti
 
Python basic programing language for automation
DanialHabibi2
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 

CouchDB on Android

  • 2. about Sven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails [email protected]
  • 3. about Sven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails [email protected]
  • 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
  • 13. adb forward tcp:5999 tcp:33595
  • 17. #1 new android project
  • 21. #3 run as Ant file
  • 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...
  • 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 [email protected]
  • 49. about Sven Haiges, hybris GmbH Twitter @hansamann Android, HTML5, Groovy & Grails [email protected] NFC

Editor's Notes