SlideShare a Scribd company logo
NoSQL databases
Sometimes being unstructured helps
Amrit Sanjeev
Organizer @ Blrdroid
Who am I ?
Agenda
● Type of databases available in Android
● When to use them
● How they help ?
● Some feature of popular db products
Data trends
- Amount of data stored is increasing
- Data is more unstructured
- Efficiency and performance are critical
- Relations are more complex
Datastore evolution
RDBMS vs NoSQL
- Structured data
- Transform data policy
- Atomic transactions
- Data model != Entity model
- Scale up
- Semi or unstructured data
- Update schema policy
- Eventual consistency
- Data model ~= Entity model
- Scale out
Real time database
- NoSQL, JSON database
- Maps each piece of data to a URL
- Offline support
- Supports iOS , Android and Web
- Pushes updates in milliseconds when
things change
Cross platform support
Listening to data changes
● Attach an asynchronous listener to a Firebase reference.
● The listener will be triggered
○ once for the initial state of the data
○ again anytime the data changes
Firebase ref = new Firebase("https://docs-examples.firebaseio.com/web/saving-data/fireblog/posts");
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
System.out.println(snapshot.getValue());
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
Reading data once
● Callback will be called only once
● removed after the first trigger
Firebase ref = new Firebase("https://docs-examples.firebaseio.com/web/saving-data/fireblog/posts");
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
// do some stuff once
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
Querying data
● Selectively retrieve data based on various factors.
● Start by specifying how you want your data to be ordered
○ orderByChild()
○ orderByKey()
○ orderByValue()
○ orderByPriority()
● combine these other methods to conduct complex queries
○ limitToFirst()
○ limitToLast()
○ startAt()
○ endAt()
○ equalTo()
What is Realm ?
- Zero copy object store database
- Easy setup
- Optimized for read , not writes
- Cross platform
- Simple Querying interface
Defining objects in realm
public class Person extends RealmObject {
@PrimaryKey
private long id;
private String name;
private RealmList<Dog> dogs;
// Declare one-to-many relationships
// ... Generated getters and setters ...
}
@RealmClass
public class Person implements RealmModel {
@PrimaryKey
private long id;
private String name;
private RealmList<Dog> dogs;
// Declare one-to-many relationships
// ... Generated getters and setters ...
}
Relationships
public class Person extends RealmObject {
private String firstName;
private String lastName;
private Dog dog;
// ... Generated getters and setters ...
}
public class Person extends RealmObject {
private String firstName;
private String lastName;
private RealmList<Dog> dogs;
// ... Generated getters and setters ...
}
public class Person extends RealmObject {
private String firstName;
private String lastName;
private RealmList<Person> friends;
// .. getters/setters
}
Saving objects in realm
// Use them like regular java objects
Dog dog = new Dog();
dog.setName("Rex");
dog.setAge("1");
// Get a Realm instance
Realm realm = Realm.getDefaultInstance();
// Persist your data easily
realm.beginTransaction();
realm.copyToRealm(dog);
realm.commitTransaction();
// Get a Realm instance
Realm realm = Realm.getDefaultInstance();
// Create and persist your data easily
realm.beginTransaction();
Dog dog = realm.createObject(Dog.class);
dog.setName("Rex");
dog.setAge("1");
realm.commitTransaction();
Transactions
try {
realm.beginTransaction();
Dog dog = realm.where(Dog.class).
equalTo("name", "Fido").findFirst();
dog.setAge(15);
realm.commitTransaction();
}
catch (Exception ex) {
// rollback
realm.cancelTransaction();
}
realm.executeTransaction(
new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Dog dog= realm.where(Dog.class).
equalTo("name", "Fido").findFirst();
dog.setAge(15);
}
})
Async Transactions
// Use them like regular java objects
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm bgRealm) {
User user = bgRealm.createObject(User.class);
user.setName("John");
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
// Transaction was a success.
}
}, new Realm.Transaction.OnError() {
@Override
public void onError(Throwable error) {
// Transaction failed and was automatically canceled.
}
});
RealmAsyncTask transaction = realm.executeTransactionAsync(
new Realm.Transaction() {
@Override
public void execute(Realm bgRealm) {
User user = bgRealm.createObject(User.class);
user.setName("John");
user.setEmail("john@corporation.com");
}
}, null);
Querying data
// Build the query looking at all users:
RealmQuery<User> query = realm.where(User.class);
// Add query conditions:
query.equalTo("name", "John");
query.or().equalTo("name", "Peter");
// Execute the query:
RealmResults<User> result1 = query.findAll();
// Or alternatively do the same all at once (the "Fluent interface"):
RealmResults<User> result2 = realm.where(User.class)
.equalTo("name", "John")
.or()
.equalTo("name", "Peter")
.findAll();
Query data supports
- Conditions like lessThan, greaterThan, contains, beginsWith etc
- Modifiers for ignoring Cases
- Logical Operations OR AND
- Sorting Ascending, Descending
- Chaining Queries
- Aggregations like SUM, MIN, MAX, AVG
- Synchronous, Asynchronous operations
Linked queries
public class Person extends RealmObject {
private String id;
private String name;
private RealmList<Dog> dogs;
// getters and setters
}
public class Dog extends RealmObject {
private String id;
private String name;
private String color;
// getters and setters
}
Linked queries
RealmResults<Person> r1 = realm.where(Person.class)
.equalTo("dogs.name", "Fluffy")
.findAll();
RealmResults<Person> r2 = r1.where()
.equalTo("dogs.color", "Brown")
.findAll();
Auto updating objects
Dog d1 = realm.where(Dog.class).equals("id", 123).findFirst();
// register a listener to get notified when the object is updated.
d1.registerChangeListener(new RealmChangeListener() {
@Override
public void onChange() {
// called once the query complete and on every update
// do something now that the obj is updated
}
});
// assume code below is in some other thread
// Retrieve the same dog as above
Dog d2 = realm.where(Dog.class).equals("id", 123).first();
realm.beginTransaction();
d2.setAge(12);
realm.commitTransaction();
// d1's change listener gets called after the commit.*
Migration
// Example migration adding a new class
RealmMigration MyMigration = new RealmMigration() {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
// DynamicRealm exposes an editable schema
RealmSchema schema = realm.getSchema();
if (oldVersion == 0) {
schema.create("Person")
.addField("id", long.class, FieldAttribute.PRIMARY_KEY)
.addField("name", String.class)
.addField("age", int.class);
oldVersion++;
}
}
}
// in your init
RealmConfiguration config = new RealmConfiguration.Builder(context).schemaVersion(1)
.migration(new MyMigration()) ;
More features
● Direct support for Json to Object store
● Notification for database change like CP
● Encryption support in built
● Adapters for binding data with views (Android)
● Cross Platform, same data can work across ios and android
● Robust 3rd parties addons
Limitations
● Managing memory is tricky
● Not Entirely NOSQL, need migration on schema Changes
● No support for auto incrementing primary keys
● Mutable, thread-confined objects.
● Slower write
● Increase method count and size of apk
Latest update
● Server side tech
○ Real time sync
○ Conflict resolution
○ Reactive event handling
○ Authentication
○ Access control
● Good to building offline experiences
● Not a managed service yet
Thank you!
Amrit Sanjeev
@amsanjeev
#blrdroid

More Related Content

What's hot

Full Text Search In PostgreSQL
Full Text Search In PostgreSQLFull Text Search In PostgreSQL
Full Text Search In PostgreSQL
Karwin Software Solutions LLC
 
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaSimplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with Morphia
MongoDB
 
Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudrey
Audrey Lim
 
Asp.net create delete directory folder in c# vb.net
Asp.net   create delete directory folder in c# vb.netAsp.net   create delete directory folder in c# vb.net
Asp.net create delete directory folder in c# vb.net
relekarsushant
 
Oak Lucene Indexes
Oak Lucene IndexesOak Lucene Indexes
Oak Lucene Indexes
Chetan Mehrotra
 
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
Alberto Paro
 
A Year With MongoDB: The Tips
A Year With MongoDB: The TipsA Year With MongoDB: The Tips
A Year With MongoDB: The Tips
Rizky Abdilah
 
Scala - den smarta kusinen
Scala - den smarta kusinenScala - den smarta kusinen
Scala - den smarta kusinen
Redpill Linpro
 
Under the Covers of DynamoDB
Under the Covers of DynamoDBUnder the Covers of DynamoDB
Under the Covers of DynamoDB
Amazon Web Services
 
Indexing and Query Optimisation
Indexing and Query OptimisationIndexing and Query Optimisation
Indexing and Query Optimisation
MongoDB
 
SICP_2.5 일반화된 연산시스템
SICP_2.5 일반화된 연산시스템SICP_2.5 일반화된 연산시스템
SICP_2.5 일반화된 연산시스템
HyeonSeok Choi
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDB
Behrouz Bakhtiari
 
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
CloudxLab
 
Sequelize
SequelizeSequelize
Sequelize
Tarek Raihan
 
Fun with Functional Programming in Clojure
Fun with Functional Programming in ClojureFun with Functional Programming in Clojure
Fun with Functional Programming in Clojure
Codemotion
 
Brief introduction of Slick
Brief introduction of SlickBrief introduction of Slick
Brief introduction of Slick
Knoldus Inc.
 
How to Use JSON in MySQL Wrong
How to Use JSON in MySQL WrongHow to Use JSON in MySQL Wrong
How to Use JSON in MySQL Wrong
Karwin Software Solutions LLC
 
DB2 Native XML
DB2 Native XMLDB2 Native XML
DB2 Native XML
Amol Pujari
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction
antoinegirbal
 
Let's talk about NoSQL Standard
Let's talk about NoSQL StandardLet's talk about NoSQL Standard
Let's talk about NoSQL Standard
Otavio Santana
 

What's hot (20)

Full Text Search In PostgreSQL
Full Text Search In PostgreSQLFull Text Search In PostgreSQL
Full Text Search In PostgreSQL
 
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaSimplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with Morphia
 
Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudrey
 
Asp.net create delete directory folder in c# vb.net
Asp.net   create delete directory folder in c# vb.netAsp.net   create delete directory folder in c# vb.net
Asp.net create delete directory folder in c# vb.net
 
Oak Lucene Indexes
Oak Lucene IndexesOak Lucene Indexes
Oak Lucene Indexes
 
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup ElasticSearch 5.x -  New Tricks - 2017-02-08 - Elasticsearch Meetup
ElasticSearch 5.x - New Tricks - 2017-02-08 - Elasticsearch Meetup
 
A Year With MongoDB: The Tips
A Year With MongoDB: The TipsA Year With MongoDB: The Tips
A Year With MongoDB: The Tips
 
Scala - den smarta kusinen
Scala - den smarta kusinenScala - den smarta kusinen
Scala - den smarta kusinen
 
Under the Covers of DynamoDB
Under the Covers of DynamoDBUnder the Covers of DynamoDB
Under the Covers of DynamoDB
 
Indexing and Query Optimisation
Indexing and Query OptimisationIndexing and Query Optimisation
Indexing and Query Optimisation
 
SICP_2.5 일반화된 연산시스템
SICP_2.5 일반화된 연산시스템SICP_2.5 일반화된 연산시스템
SICP_2.5 일반화된 연산시스템
 
Introduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDBIntroduction to NOSQL And MongoDB
Introduction to NOSQL And MongoDB
 
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
 
Sequelize
SequelizeSequelize
Sequelize
 
Fun with Functional Programming in Clojure
Fun with Functional Programming in ClojureFun with Functional Programming in Clojure
Fun with Functional Programming in Clojure
 
Brief introduction of Slick
Brief introduction of SlickBrief introduction of Slick
Brief introduction of Slick
 
How to Use JSON in MySQL Wrong
How to Use JSON in MySQL WrongHow to Use JSON in MySQL Wrong
How to Use JSON in MySQL Wrong
 
DB2 Native XML
DB2 Native XMLDB2 Native XML
DB2 Native XML
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction
 
Let's talk about NoSQL Standard
Let's talk about NoSQL StandardLet's talk about NoSQL Standard
Let's talk about NoSQL Standard
 

Similar to No sql databases blrdroid devfest 2016

Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
Yuval Ararat
 
MongoDB .local Houston 2019: REST-less Mobile Apps: Why Offline-first and Syn...
MongoDB .local Houston 2019: REST-less Mobile Apps: Why Offline-first and Syn...MongoDB .local Houston 2019: REST-less Mobile Apps: Why Offline-first and Syn...
MongoDB .local Houston 2019: REST-less Mobile Apps: Why Offline-first and Syn...
MongoDB
 
MongoDB World 2019: Realm: The Secret Sauce for Better Mobile Apps
MongoDB World 2019: Realm: The Secret Sauce for Better Mobile AppsMongoDB World 2019: Realm: The Secret Sauce for Better Mobile Apps
MongoDB World 2019: Realm: The Secret Sauce for Better Mobile Apps
MongoDB
 
Present realm
Present realmPresent realm
Present realm
thinhit
 
Terrastore - A document database for developers
Terrastore - A document database for developersTerrastore - A document database for developers
Terrastore - A document database for developers
Sergio Bossa
 
PostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersPostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL Superpowers
Amanda Gilmore
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
Eric Bottard
 
Persistences
PersistencesPersistences
Persistences
Training Guide
 
Android Architecure Components - introduction
Android Architecure Components - introductionAndroid Architecure Components - introduction
Android Architecure Components - introduction
Paulina Szklarska
 
Android Jetpack: Room persistence library
Android Jetpack: Room persistence libraryAndroid Jetpack: Room persistence library
Android Jetpack: Room persistence library
Thao Huynh Quang
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP
Nguyen Tuan
 
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Donny Wals
 
07 darwino rest services
07   darwino rest services07   darwino rest services
07 darwino rest services
darwinodb
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : Datastore
IMC Institute
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
Christian Melchior
 
MongoDB .local Chicago 2019: REST-less Mobile Apps: Why Offline-first & Sync ...
MongoDB .local Chicago 2019: REST-less Mobile Apps: Why Offline-first & Sync ...MongoDB .local Chicago 2019: REST-less Mobile Apps: Why Offline-first & Sync ...
MongoDB .local Chicago 2019: REST-less Mobile Apps: Why Offline-first & Sync ...
MongoDB
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDB
MongoDB
 
Infinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGMInfinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGM
JBug Italy
 
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Neo4j
 
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
Arun Gupta
 

Similar to No sql databases blrdroid devfest 2016 (20)

Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
 
MongoDB .local Houston 2019: REST-less Mobile Apps: Why Offline-first and Syn...
MongoDB .local Houston 2019: REST-less Mobile Apps: Why Offline-first and Syn...MongoDB .local Houston 2019: REST-less Mobile Apps: Why Offline-first and Syn...
MongoDB .local Houston 2019: REST-less Mobile Apps: Why Offline-first and Syn...
 
MongoDB World 2019: Realm: The Secret Sauce for Better Mobile Apps
MongoDB World 2019: Realm: The Secret Sauce for Better Mobile AppsMongoDB World 2019: Realm: The Secret Sauce for Better Mobile Apps
MongoDB World 2019: Realm: The Secret Sauce for Better Mobile Apps
 
Present realm
Present realmPresent realm
Present realm
 
Terrastore - A document database for developers
Terrastore - A document database for developersTerrastore - A document database for developers
Terrastore - A document database for developers
 
PostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL SuperpowersPostgreSQL's Secret NoSQL Superpowers
PostgreSQL's Secret NoSQL Superpowers
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
 
Persistences
PersistencesPersistences
Persistences
 
Android Architecure Components - introduction
Android Architecure Components - introductionAndroid Architecure Components - introduction
Android Architecure Components - introduction
 
Android Jetpack: Room persistence library
Android Jetpack: Room persistence libraryAndroid Jetpack: Room persistence library
Android Jetpack: Room persistence library
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP
 
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
Using Combine, SwiftUI and callAsFunction to build an experimental localizati...
 
07 darwino rest services
07   darwino rest services07   darwino rest services
07 darwino rest services
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : Datastore
 
Painless Persistence in a Disconnected World
Painless Persistence in a Disconnected WorldPainless Persistence in a Disconnected World
Painless Persistence in a Disconnected World
 
MongoDB .local Chicago 2019: REST-less Mobile Apps: Why Offline-first & Sync ...
MongoDB .local Chicago 2019: REST-less Mobile Apps: Why Offline-first & Sync ...MongoDB .local Chicago 2019: REST-less Mobile Apps: Why Offline-first & Sync ...
MongoDB .local Chicago 2019: REST-less Mobile Apps: Why Offline-first & Sync ...
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDB
 
Infinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGMInfinispan,Lucene,Hibername OGM
Infinispan,Lucene,Hibername OGM
 
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
Object Graph Mapping with Spring Data Neo4j 3 - Nicki Watt & Michael Hunger @...
 
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
 

More from amsanjeev

Introduction to Firebase on Android
Introduction to Firebase on AndroidIntroduction to Firebase on Android
Introduction to Firebase on Android
amsanjeev
 
Introduction to Android M
Introduction to Android MIntroduction to Android M
Introduction to Android M
amsanjeev
 
Io13 deep dive location api
Io13 deep dive   location api Io13 deep dive   location api
Io13 deep dive location api
amsanjeev
 
Jelly bean aka Andorid 4.1
Jelly bean aka Andorid 4.1Jelly bean aka Andorid 4.1
Jelly bean aka Andorid 4.1
amsanjeev
 
Mobile UX
Mobile UXMobile UX
Mobile UX
amsanjeev
 
Location Based Services - An Overview
Location Based Services - An Overview Location Based Services - An Overview
Location Based Services - An Overview
amsanjeev
 
NFC - quick primer
NFC - quick primerNFC - quick primer
NFC - quick primer
amsanjeev
 
Introduction to ICS
Introduction to ICSIntroduction to ICS
Introduction to ICS
amsanjeev
 

More from amsanjeev (8)

Introduction to Firebase on Android
Introduction to Firebase on AndroidIntroduction to Firebase on Android
Introduction to Firebase on Android
 
Introduction to Android M
Introduction to Android MIntroduction to Android M
Introduction to Android M
 
Io13 deep dive location api
Io13 deep dive   location api Io13 deep dive   location api
Io13 deep dive location api
 
Jelly bean aka Andorid 4.1
Jelly bean aka Andorid 4.1Jelly bean aka Andorid 4.1
Jelly bean aka Andorid 4.1
 
Mobile UX
Mobile UXMobile UX
Mobile UX
 
Location Based Services - An Overview
Location Based Services - An Overview Location Based Services - An Overview
Location Based Services - An Overview
 
NFC - quick primer
NFC - quick primerNFC - quick primer
NFC - quick primer
 
Introduction to ICS
Introduction to ICSIntroduction to ICS
Introduction to ICS
 

Recently uploaded

Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
FilipTomaszewski5
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Ukraine
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptxAI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
Sunil Jagani
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)
HarpalGohil4
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
LizaNolte
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
Fwdays
 
From Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMsFrom Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMs
Sease
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
Fwdays
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
zjhamm304
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's TipsGetting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
ScyllaDB
 

Recently uploaded (20)

Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptxAI in the Workplace Reskilling, Upskilling, and Future Work.pptx
AI in the Workplace Reskilling, Upskilling, and Future Work.pptx
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)AWS Certified Solutions Architect Associate (SAA-C03)
AWS Certified Solutions Architect Associate (SAA-C03)
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
 
From Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMsFrom Natural Language to Structured Solr Queries using LLMs
From Natural Language to Structured Solr Queries using LLMs
 
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin..."$10 thousand per minute of downtime: architecture, queues, streaming and fin...
"$10 thousand per minute of downtime: architecture, queues, streaming and fin...
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's TipsGetting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
 

No sql databases blrdroid devfest 2016

  • 1. NoSQL databases Sometimes being unstructured helps Amrit Sanjeev Organizer @ Blrdroid
  • 3. Agenda ● Type of databases available in Android ● When to use them ● How they help ? ● Some feature of popular db products
  • 4. Data trends - Amount of data stored is increasing - Data is more unstructured - Efficiency and performance are critical - Relations are more complex
  • 6. RDBMS vs NoSQL - Structured data - Transform data policy - Atomic transactions - Data model != Entity model - Scale up - Semi or unstructured data - Update schema policy - Eventual consistency - Data model ~= Entity model - Scale out
  • 7.
  • 8. Real time database - NoSQL, JSON database - Maps each piece of data to a URL - Offline support - Supports iOS , Android and Web - Pushes updates in milliseconds when things change
  • 10. Listening to data changes ● Attach an asynchronous listener to a Firebase reference. ● The listener will be triggered ○ once for the initial state of the data ○ again anytime the data changes Firebase ref = new Firebase("https://docs-examples.firebaseio.com/web/saving-data/fireblog/posts"); ref.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { System.out.println(snapshot.getValue()); } @Override public void onCancelled(FirebaseError firebaseError) { System.out.println("The read failed: " + firebaseError.getMessage()); } });
  • 11. Reading data once ● Callback will be called only once ● removed after the first trigger Firebase ref = new Firebase("https://docs-examples.firebaseio.com/web/saving-data/fireblog/posts"); ref.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { // do some stuff once } @Override public void onCancelled(FirebaseError firebaseError) { } });
  • 12. Querying data ● Selectively retrieve data based on various factors. ● Start by specifying how you want your data to be ordered ○ orderByChild() ○ orderByKey() ○ orderByValue() ○ orderByPriority() ● combine these other methods to conduct complex queries ○ limitToFirst() ○ limitToLast() ○ startAt() ○ endAt() ○ equalTo()
  • 13.
  • 14. What is Realm ? - Zero copy object store database - Easy setup - Optimized for read , not writes - Cross platform - Simple Querying interface
  • 15. Defining objects in realm public class Person extends RealmObject { @PrimaryKey private long id; private String name; private RealmList<Dog> dogs; // Declare one-to-many relationships // ... Generated getters and setters ... } @RealmClass public class Person implements RealmModel { @PrimaryKey private long id; private String name; private RealmList<Dog> dogs; // Declare one-to-many relationships // ... Generated getters and setters ... }
  • 16. Relationships public class Person extends RealmObject { private String firstName; private String lastName; private Dog dog; // ... Generated getters and setters ... } public class Person extends RealmObject { private String firstName; private String lastName; private RealmList<Dog> dogs; // ... Generated getters and setters ... } public class Person extends RealmObject { private String firstName; private String lastName; private RealmList<Person> friends; // .. getters/setters }
  • 17. Saving objects in realm // Use them like regular java objects Dog dog = new Dog(); dog.setName("Rex"); dog.setAge("1"); // Get a Realm instance Realm realm = Realm.getDefaultInstance(); // Persist your data easily realm.beginTransaction(); realm.copyToRealm(dog); realm.commitTransaction(); // Get a Realm instance Realm realm = Realm.getDefaultInstance(); // Create and persist your data easily realm.beginTransaction(); Dog dog = realm.createObject(Dog.class); dog.setName("Rex"); dog.setAge("1"); realm.commitTransaction();
  • 18. Transactions try { realm.beginTransaction(); Dog dog = realm.where(Dog.class). equalTo("name", "Fido").findFirst(); dog.setAge(15); realm.commitTransaction(); } catch (Exception ex) { // rollback realm.cancelTransaction(); } realm.executeTransaction( new Realm.Transaction() { @Override public void execute(Realm realm) { Dog dog= realm.where(Dog.class). equalTo("name", "Fido").findFirst(); dog.setAge(15); } })
  • 19. Async Transactions // Use them like regular java objects realm.executeTransactionAsync(new Realm.Transaction() { @Override public void execute(Realm bgRealm) { User user = bgRealm.createObject(User.class); user.setName("John"); } }, new Realm.Transaction.OnSuccess() { @Override public void onSuccess() { // Transaction was a success. } }, new Realm.Transaction.OnError() { @Override public void onError(Throwable error) { // Transaction failed and was automatically canceled. } }); RealmAsyncTask transaction = realm.executeTransactionAsync( new Realm.Transaction() { @Override public void execute(Realm bgRealm) { User user = bgRealm.createObject(User.class); user.setName("John"); user.setEmail("john@corporation.com"); } }, null);
  • 20. Querying data // Build the query looking at all users: RealmQuery<User> query = realm.where(User.class); // Add query conditions: query.equalTo("name", "John"); query.or().equalTo("name", "Peter"); // Execute the query: RealmResults<User> result1 = query.findAll(); // Or alternatively do the same all at once (the "Fluent interface"): RealmResults<User> result2 = realm.where(User.class) .equalTo("name", "John") .or() .equalTo("name", "Peter") .findAll();
  • 21. Query data supports - Conditions like lessThan, greaterThan, contains, beginsWith etc - Modifiers for ignoring Cases - Logical Operations OR AND - Sorting Ascending, Descending - Chaining Queries - Aggregations like SUM, MIN, MAX, AVG - Synchronous, Asynchronous operations
  • 22. Linked queries public class Person extends RealmObject { private String id; private String name; private RealmList<Dog> dogs; // getters and setters } public class Dog extends RealmObject { private String id; private String name; private String color; // getters and setters }
  • 23. Linked queries RealmResults<Person> r1 = realm.where(Person.class) .equalTo("dogs.name", "Fluffy") .findAll(); RealmResults<Person> r2 = r1.where() .equalTo("dogs.color", "Brown") .findAll();
  • 24. Auto updating objects Dog d1 = realm.where(Dog.class).equals("id", 123).findFirst(); // register a listener to get notified when the object is updated. d1.registerChangeListener(new RealmChangeListener() { @Override public void onChange() { // called once the query complete and on every update // do something now that the obj is updated } }); // assume code below is in some other thread // Retrieve the same dog as above Dog d2 = realm.where(Dog.class).equals("id", 123).first(); realm.beginTransaction(); d2.setAge(12); realm.commitTransaction(); // d1's change listener gets called after the commit.*
  • 25. Migration // Example migration adding a new class RealmMigration MyMigration = new RealmMigration() { @Override public void migrate(DynamicRealm realm, long oldVersion, long newVersion) { // DynamicRealm exposes an editable schema RealmSchema schema = realm.getSchema(); if (oldVersion == 0) { schema.create("Person") .addField("id", long.class, FieldAttribute.PRIMARY_KEY) .addField("name", String.class) .addField("age", int.class); oldVersion++; } } } // in your init RealmConfiguration config = new RealmConfiguration.Builder(context).schemaVersion(1) .migration(new MyMigration()) ;
  • 26. More features ● Direct support for Json to Object store ● Notification for database change like CP ● Encryption support in built ● Adapters for binding data with views (Android) ● Cross Platform, same data can work across ios and android ● Robust 3rd parties addons
  • 27. Limitations ● Managing memory is tricky ● Not Entirely NOSQL, need migration on schema Changes ● No support for auto incrementing primary keys ● Mutable, thread-confined objects. ● Slower write ● Increase method count and size of apk
  • 28. Latest update ● Server side tech ○ Real time sync ○ Conflict resolution ○ Reactive event handling ○ Authentication ○ Access control ● Good to building offline experiences ● Not a managed service yet