SlideShare a Scribd company logo
1 of 32
GreenDao
綠道
Heaton
Outline
• Why GreenDao
• Feature
• Performance
• How to getting start
• How to use.
Why GreenDao
• First . Some problem with DB Development.
– No object orientation.
– Data access sentence is low levely.
– Always make same code to write SQL script.
– Do you know SQL without 『||』.
– I am stupid on SQL tuning
• Second , it is faster than other ORM Lib.
It is popular?
Features
• High Performance
– CRD test.
• ORM (Object relation mapping)
– Code Generation
– Read and write objects
– CREATE TABLE done for you
– Expressing Queries
• Session cache
• Setter ; getter
• Create table “table_name”
• Return List<Common>
Performance
• Test case :
– insert 10000 row
– delete 10000 row
– query 20000 row
Test 1 Dao Content Provider
Insert 1467 87268 (no transcation)
Load 1608 9797
Delete 108 121
Test 2
Insert 662 87766
Load 1837 12282
delete 137 127
Benchmark
• https://github.com/daj/android-orm-
benchmark
• Write 10000
• Read 10000
ORM
Object/relation mapping (ORM)
A example for presentation
• Implement a social data collector
• “Leftpage” as table name for database
“leftpageProvider.db”
• Every row data as “CommonData”
• Column has
– ”DataID” as primary key
– “Category”
– “Provider”
– “DisplayOrder”
Expressing Queries: What difference
• SQL Query all
– Cursor c =
mContext.getContentResolver().query(uriLPagePr
ovider , projection , selection, selection args, sort
order ) ;
• GreenDao Load all
List<commonData> datas =
CommonDataDao.loadAll();
Sqlite review
• SQL Query
– Provider equal facebook
– Order by display order
– Limit data count100
• Cursor c = getContentResolver() . query
(uriLPageProvider , projection , selection,
selection args, sort order ) ;
(String ) selection :
StorageField.Provider. + "=?" =
(String[])selection args: {“facebook”}
Sort order
• SQL Query
– Provider equal facebook
– Order by display order
– Limit data count100
• Cursor c = getContentResolver() . query
(uriLPageProvider , projection , selection,
selection args, sort order ) ;
(String ) Sort order: StorageField.Displayorder
More detail
• SQL Query
– Provider equal facebook
– Order by display order
– Limit data count100
• Cursor c = getContentResolver() . query
(uriLPageProvider , projection , selection,
selection args, sort order ) ;
(String ) Sort order:
“ ASC ” + StorageField.Displayorder
+ “ LIMIT ” + request
If you are sqlite master
• SQL Query
– Provider equal facebook
– Order by display order
– Limit data count100
• Select * from leftpage where Provider =
‘facebook’ order asc ‘displayorder’ limit
‘100’
• Then you also load cusor and save to data
list
But in GreenDao
• SQL Query
– Provider equal facebook
– Order by display order
– Limit data count100
mCommonDataDao.queryBuilder()
.where(Properties.Provider.eq(Provider.Facebook))
.orderAsc(Properties.DisplayOrder)
.limit(100)
.list();
HOW TO GETTING START
Create module
How to getting start?
First time is terrible
Create a module to gen greendao code
• In module gradle
– Add Gradle script
– compile 'de.greenrobot:greendao-generator:1.3.1
Create main() in our case.
public class GreenDao {
public static void main(String[] args){
Schema schema = new Schema
(1, "com.acer.android.leftpage.provider");
Entity commonData = schema.addEntity("commonData");
commonData.setTableName("LeftPage");
commonData.addLongProperty("DataID").primaryKey();
commonData.addStringProperty("Category");
commonData.addStringProperty("Provider");
commonData.addLongProperty(“DisplayOrder”);
commonData.addContentProvider();
DaoGenerator generator = new DaoGenerator();
generator.generateAll
(schema, "../AcerHome/LeftPage/src/main/java/");}
Compile and run to Auto gen Core
classes
DaoMaster
DaoSeesion
CommonDataDao
CommonData
In CommonDataDao
public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "'LeftPage' (" + //
"'DataID' INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0:
DataID
"'Category' TEXT," + // 1: Category
"'Provider' TEXT," + // 2: Provider
"'DisplayOrder' INTEGER DEFAULT -1," + // 3: DisplayOrder
"'Bookmarked' INTEGER DEFAULT 0," + // 4: Bookmarked
"'Deleted' INTEGER DEFAULT 0," + // 5: Deleted
"'Score' REAL DEFAULT -1," + // 6: Score
"'Keywords' TEXT DEFAULT NULL," + // 7: Keywords
CommonData content
public Long getDataID() { return DataID; }
public void setDataID(Long DataID) {
this.DataID = DataID; }
……
……
……
Add it and start to use
• In Used Project gradle
– compile 'de.greenrobot:greendao:1.3.7'
HOW TO USE
INSERT , DELETE , UPDATE,
Initial
• DaoMaster.DevOpenHelper helper = new
DaoMaster.DevOpenHelper(context,”leftpage
provider.db”);
• DaoMaster master = new DaoMaster
(helper.getDataBase());
• DaoSession session = master.newSession();
• CommonDataDao CommonDataDao=
session.getCommonDataDao();
Query
• Query with syntax
– eq , notEq
– ge , le , gt , lt
– in , between
– like
• List<commonData> dataList =
CommonDataDao.queryBuilder()
.where(Properties.Provider.eq(Provider.Social))
.orderAsc(mCommonDataDao.Properties.DisplayOrder)
.list();
Raw query
SQLiteDatabase db =
daoSession.getDatabase();
Cursor cursor = db.rawQuery("SELECT *FROM
leftpage WHERE .....", null);
Insert
• Insert:
– CommonDataDao .insert(new CommonData(DATA_ID,
arg1, arg2,x……));
• Bulk Insert
– CommonDataDao .insertln(CommonDataList);
– CommonDataDao.insertln(CommonData[]);
• InsetOrReplace
– CommonDataDao.insertOrReplaceln(CommonDataList)
Note: DATA_ID usually is null .
Delete
• Delete sentence
– CommonDataDao.QueryBuilder()
.where(Properties.Provider.eq(facebook))
.buildDelete()
.executeDeleteWithoutDetachingEntities();
• Delete all
– CommonDataDao.deleteAll();
Update
• Update sentence
– CommonDataDao.update(new
CommonData(Data_ID , arg1 , arg2 , …….));
• Bulk Update
– CommonDataDao.updateln(CommonDataList);
– CommonDataDao.updateln(CommonData[]);
Note: DATA_ID must assign what
the row you want to update.
Thanks
Reference:
http://greendao-orm.com/features/
http://bng86.gitbooks.io/android-third-party-
/content/greendao.html
http://www.slideshare.net/SmileeYang/greendao-
43892958?qid=b95e0f35-a323-4930-8e8a-
d0e298a1eb10&v=qf1&b=&from_search=1
http://www.slideshare.net/ssuser8674c1/green-dao-
50914708?qid=b95e0f35-a323-4930-8e8a-
d0e298a1eb10&v=qf1&b=&from_search=5
Something here
AsyncSession asyncSession =
DBHelper.getInstance(this).getAsyncSession();
asyncSession.insert(
new CommonData(null, …, …));

More Related Content

What's hot

Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query OptimizationMongoDB
 
Indexing and Query Optimization
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query OptimizationMongoDB
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETTomas Jansson
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring DataOliver Gierke
 
Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDBJeff Yemin
 
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 MorphiaMongoDB
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329Douglas Duncan
 
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legione-Legion
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196Mahmoud Samir Fayed
 
Brief introduction of Slick
Brief introduction of SlickBrief introduction of Slick
Brief introduction of SlickKnoldus Inc.
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLMongoDB
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDBantoinegirbal
 
Webinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationWebinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationMongoDB
 
ObjectBox - The new Mobile Database
ObjectBox - The new Mobile DatabaseObjectBox - The new Mobile Database
ObjectBox - The new Mobile Databasegreenrobot
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Oliver Gierke
 
Webinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and MorphiaWebinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and MorphiaMongoDB
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Scott Leberknight
 

What's hot (20)

Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query Optimization
 
Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0
 
Indexing and Query Optimization
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query Optimization
 
MongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() OutputMongoDB World 2016: Deciphering .explain() Output
MongoDB World 2016: Deciphering .explain() Output
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDB
 
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 and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
 
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
 
Brief introduction of Slick
Brief introduction of SlickBrief introduction of Slick
Brief introduction of Slick
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQL
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB
 
Webinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationWebinar: Index Tuning and Evaluation
Webinar: Index Tuning and Evaluation
 
ObjectBox - The new Mobile Database
ObjectBox - The new Mobile DatabaseObjectBox - The new Mobile Database
ObjectBox - The new Mobile Database
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Php forum2015 tomas_final
Php forum2015 tomas_finalPhp forum2015 tomas_final
Php forum2015 tomas_final
 
Webinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and MorphiaWebinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and Morphia
 
Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0Cloudera Impala, updated for v1.0
Cloudera Impala, updated for v1.0
 

Viewers also liked

Camera2 introdction
Camera2 introdctionCamera2 introdction
Camera2 introdctionBooch Lin
 
How to create a camera2
How to create a camera2How to create a camera2
How to create a camera2Booch Lin
 
Camera2 API, SHIM, and HAL 3.2 in Android 5.1
Camera2 API, SHIM, and HAL 3.2 in Android 5.1Camera2 API, SHIM, and HAL 3.2 in Android 5.1
Camera2 API, SHIM, and HAL 3.2 in Android 5.1Cheng Hsien Chen
 
Android 5.0 Camera2 APIs
Android 5.0 Camera2 APIsAndroid 5.0 Camera2 APIs
Android 5.0 Camera2 APIsBalwinder Kaur
 
Hidden Camera 3 APIs in Android 4.4 (KitKat)
Hidden Camera 3 APIs in Android 4.4 (KitKat)Hidden Camera 3 APIs in Android 4.4 (KitKat)
Hidden Camera 3 APIs in Android 4.4 (KitKat)Balwinder Kaur
 
Android Camera Architecture
Android Camera ArchitectureAndroid Camera Architecture
Android Camera ArchitecturePicker Weng
 
Camera 2.0 in Android 4.2
Camera 2.0 in Android 4.2 Camera 2.0 in Android 4.2
Camera 2.0 in Android 4.2 Balwinder Kaur
 
Mvp in practice
Mvp in practiceMvp in practice
Mvp in practice彥彬 洪
 

Viewers also liked (10)

Green dao 3.0
Green dao 3.0Green dao 3.0
Green dao 3.0
 
Camera2 introdction
Camera2 introdctionCamera2 introdction
Camera2 introdction
 
How to create a camera2
How to create a camera2How to create a camera2
How to create a camera2
 
Camera2 API, SHIM, and HAL 3.2 in Android 5.1
Camera2 API, SHIM, and HAL 3.2 in Android 5.1Camera2 API, SHIM, and HAL 3.2 in Android 5.1
Camera2 API, SHIM, and HAL 3.2 in Android 5.1
 
Camera2
Camera2Camera2
Camera2
 
Android 5.0 Camera2 APIs
Android 5.0 Camera2 APIsAndroid 5.0 Camera2 APIs
Android 5.0 Camera2 APIs
 
Hidden Camera 3 APIs in Android 4.4 (KitKat)
Hidden Camera 3 APIs in Android 4.4 (KitKat)Hidden Camera 3 APIs in Android 4.4 (KitKat)
Hidden Camera 3 APIs in Android 4.4 (KitKat)
 
Android Camera Architecture
Android Camera ArchitectureAndroid Camera Architecture
Android Camera Architecture
 
Camera 2.0 in Android 4.2
Camera 2.0 in Android 4.2 Camera 2.0 in Android 4.2
Camera 2.0 in Android 4.2
 
Mvp in practice
Mvp in practiceMvp in practice
Mvp in practice
 

Similar to GreenDao Introduction

The Pushdown of Everything by Stephan Kessler and Santiago Mola
The Pushdown of Everything by Stephan Kessler and Santiago MolaThe Pushdown of Everything by Stephan Kessler and Santiago Mola
The Pushdown of Everything by Stephan Kessler and Santiago MolaSpark Summit
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!Daniel Cousineau
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeWim Godden
 
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...Ontico
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformationLars Marius Garshol
 
Data Exploration with Apache Drill: Day 1
Data Exploration with Apache Drill:  Day 1Data Exploration with Apache Drill:  Day 1
Data Exploration with Apache Drill: Day 1Charles Givre
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database JonesJohn David Duncan
 
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxMYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxPythian
 
Beyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesBeyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesDatabricks
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 
managing big data
managing big datamanaging big data
managing big dataSuveeksha
 
Portfolio Oversight With eazyBI
Portfolio Oversight With eazyBIPortfolio Oversight With eazyBI
Portfolio Oversight With eazyBIeazyBI
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programmingchhaichivon
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/HibernateSunghyouk Bae
 

Similar to GreenDao Introduction (20)

The Pushdown of Everything by Stephan Kessler and Santiago Mola
The Pushdown of Everything by Stephan Kessler and Santiago MolaThe Pushdown of Everything by Stephan Kessler and Santiago Mola
The Pushdown of Everything by Stephan Kessler and Santiago Mola
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 
Python with MySql.pptx
Python with MySql.pptxPython with MySql.pptx
Python with MySql.pptx
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
CREATE INDEX … USING VODKA. VODKA CONNECTING INDEXES, Олег Бартунов, Александ...
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Linq
LinqLinq
Linq
 
Relate
RelateRelate
Relate
 
SQL Injection Defense in Python
SQL Injection Defense in PythonSQL Injection Defense in Python
SQL Injection Defense in Python
 
Data Exploration with Apache Drill: Day 1
Data Exploration with Apache Drill:  Day 1Data Exploration with Apache Drill:  Day 1
Data Exploration with Apache Drill: Day 1
 
Building node.js applications with Database Jones
Building node.js applications with Database JonesBuilding node.js applications with Database Jones
Building node.js applications with Database Jones
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxMYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
 
Beyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesBeyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFrames
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
managing big data
managing big datamanaging big data
managing big data
 
Portfolio Oversight With eazyBI
Portfolio Oversight With eazyBIPortfolio Oversight With eazyBI
Portfolio Oversight With eazyBI
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/Hibernate
 

Recently uploaded

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 

Recently uploaded (20)

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 

GreenDao Introduction

  • 2. Outline • Why GreenDao • Feature • Performance • How to getting start • How to use.
  • 3. Why GreenDao • First . Some problem with DB Development. – No object orientation. – Data access sentence is low levely. – Always make same code to write SQL script. – Do you know SQL without 『||』. – I am stupid on SQL tuning • Second , it is faster than other ORM Lib.
  • 5. Features • High Performance – CRD test. • ORM (Object relation mapping) – Code Generation – Read and write objects – CREATE TABLE done for you – Expressing Queries • Session cache • Setter ; getter • Create table “table_name” • Return List<Common>
  • 6. Performance • Test case : – insert 10000 row – delete 10000 row – query 20000 row Test 1 Dao Content Provider Insert 1467 87268 (no transcation) Load 1608 9797 Delete 108 121 Test 2 Insert 662 87766 Load 1837 12282 delete 137 127
  • 9. A example for presentation • Implement a social data collector • “Leftpage” as table name for database “leftpageProvider.db” • Every row data as “CommonData” • Column has – ”DataID” as primary key – “Category” – “Provider” – “DisplayOrder”
  • 10. Expressing Queries: What difference • SQL Query all – Cursor c = mContext.getContentResolver().query(uriLPagePr ovider , projection , selection, selection args, sort order ) ; • GreenDao Load all List<commonData> datas = CommonDataDao.loadAll();
  • 11. Sqlite review • SQL Query – Provider equal facebook – Order by display order – Limit data count100 • Cursor c = getContentResolver() . query (uriLPageProvider , projection , selection, selection args, sort order ) ; (String ) selection : StorageField.Provider. + "=?" = (String[])selection args: {“facebook”}
  • 12. Sort order • SQL Query – Provider equal facebook – Order by display order – Limit data count100 • Cursor c = getContentResolver() . query (uriLPageProvider , projection , selection, selection args, sort order ) ; (String ) Sort order: StorageField.Displayorder
  • 13. More detail • SQL Query – Provider equal facebook – Order by display order – Limit data count100 • Cursor c = getContentResolver() . query (uriLPageProvider , projection , selection, selection args, sort order ) ; (String ) Sort order: “ ASC ” + StorageField.Displayorder + “ LIMIT ” + request
  • 14. If you are sqlite master • SQL Query – Provider equal facebook – Order by display order – Limit data count100 • Select * from leftpage where Provider = ‘facebook’ order asc ‘displayorder’ limit ‘100’ • Then you also load cusor and save to data list
  • 15. But in GreenDao • SQL Query – Provider equal facebook – Order by display order – Limit data count100 mCommonDataDao.queryBuilder() .where(Properties.Provider.eq(Provider.Facebook)) .orderAsc(Properties.DisplayOrder) .limit(100) .list();
  • 16. HOW TO GETTING START Create module
  • 17. How to getting start? First time is terrible
  • 18. Create a module to gen greendao code • In module gradle – Add Gradle script – compile 'de.greenrobot:greendao-generator:1.3.1
  • 19. Create main() in our case. public class GreenDao { public static void main(String[] args){ Schema schema = new Schema (1, "com.acer.android.leftpage.provider"); Entity commonData = schema.addEntity("commonData"); commonData.setTableName("LeftPage"); commonData.addLongProperty("DataID").primaryKey(); commonData.addStringProperty("Category"); commonData.addStringProperty("Provider"); commonData.addLongProperty(“DisplayOrder”); commonData.addContentProvider(); DaoGenerator generator = new DaoGenerator(); generator.generateAll (schema, "../AcerHome/LeftPage/src/main/java/");}
  • 20. Compile and run to Auto gen Core classes DaoMaster DaoSeesion CommonDataDao CommonData
  • 21. In CommonDataDao public static void createTable(SQLiteDatabase db, boolean ifNotExists) { String constraint = ifNotExists? "IF NOT EXISTS ": ""; db.execSQL("CREATE TABLE " + constraint + "'LeftPage' (" + // "'DataID' INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: DataID "'Category' TEXT," + // 1: Category "'Provider' TEXT," + // 2: Provider "'DisplayOrder' INTEGER DEFAULT -1," + // 3: DisplayOrder "'Bookmarked' INTEGER DEFAULT 0," + // 4: Bookmarked "'Deleted' INTEGER DEFAULT 0," + // 5: Deleted "'Score' REAL DEFAULT -1," + // 6: Score "'Keywords' TEXT DEFAULT NULL," + // 7: Keywords
  • 22. CommonData content public Long getDataID() { return DataID; } public void setDataID(Long DataID) { this.DataID = DataID; } …… …… ……
  • 23. Add it and start to use • In Used Project gradle – compile 'de.greenrobot:greendao:1.3.7'
  • 24. HOW TO USE INSERT , DELETE , UPDATE,
  • 25. Initial • DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context,”leftpage provider.db”); • DaoMaster master = new DaoMaster (helper.getDataBase()); • DaoSession session = master.newSession(); • CommonDataDao CommonDataDao= session.getCommonDataDao();
  • 26. Query • Query with syntax – eq , notEq – ge , le , gt , lt – in , between – like • List<commonData> dataList = CommonDataDao.queryBuilder() .where(Properties.Provider.eq(Provider.Social)) .orderAsc(mCommonDataDao.Properties.DisplayOrder) .list();
  • 27. Raw query SQLiteDatabase db = daoSession.getDatabase(); Cursor cursor = db.rawQuery("SELECT *FROM leftpage WHERE .....", null);
  • 28. Insert • Insert: – CommonDataDao .insert(new CommonData(DATA_ID, arg1, arg2,x……)); • Bulk Insert – CommonDataDao .insertln(CommonDataList); – CommonDataDao.insertln(CommonData[]); • InsetOrReplace – CommonDataDao.insertOrReplaceln(CommonDataList) Note: DATA_ID usually is null .
  • 29. Delete • Delete sentence – CommonDataDao.QueryBuilder() .where(Properties.Provider.eq(facebook)) .buildDelete() .executeDeleteWithoutDetachingEntities(); • Delete all – CommonDataDao.deleteAll();
  • 30. Update • Update sentence – CommonDataDao.update(new CommonData(Data_ID , arg1 , arg2 , …….)); • Bulk Update – CommonDataDao.updateln(CommonDataList); – CommonDataDao.updateln(CommonData[]); Note: DATA_ID must assign what the row you want to update.
  • 32. Something here AsyncSession asyncSession = DBHelper.getInstance(this).getAsyncSession(); asyncSession.insert( new CommonData(null, …, …));

Editor's Notes

  1. 接下來投影片重點在於兩點 Feature Performance
  2. High performance 比起其他 ormlite ,快了四倍 也比cp 快了不少
  3. Content provider 也是一種 半成品 orm Sqlite 是一種 關聯式資料結構 OO 式一種開發概念 如何Mapping 簡單來說就是最後你希望你crud輸入和輸出的資料都是物件
  4. 拿load all 來比 不太對吧
  5. 作掉很多dirty job
  6. 前置作業完成
  7. Why use helper Master -> session -> commondataDao
  8. Lazy list Id scope
  9. 1. For not block MainThread 2. Data consistency