SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler offline
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, …, …));

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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彥彬 洪
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

Unlocking AI: Navigating Open Source vs. Commercial Frontiers
Unlocking AI:Navigating Open Source vs. Commercial FrontiersUnlocking AI:Navigating Open Source vs. Commercial Frontiers
Unlocking AI: Navigating Open Source vs. Commercial FrontiersRaphaël Semeteys
 
Leveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDevLeveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDevpmgdscunsri
 
openEuler Community Overview - a presentation showing the current scale
openEuler Community Overview - a presentation showing the current scaleopenEuler Community Overview - a presentation showing the current scale
openEuler Community Overview - a presentation showing the current scaleShane Coughlan
 
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptxCYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptxBarakaMuyengi
 
Unlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insightsUnlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insightsconfluent
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfICS
 
8 Steps to Build a LangChain RAG Chatbot.
8 Steps to Build a LangChain RAG Chatbot.8 Steps to Build a LangChain RAG Chatbot.
8 Steps to Build a LangChain RAG Chatbot.Ritesh Kanjee
 
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
BusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptxBusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptx
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptxAGATSoftware
 
User Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller ResumeUser Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller ResumeKaylee Miller
 
Building Generative AI-infused apps: what's possible and how to start
Building Generative AI-infused apps: what's possible and how to startBuilding Generative AI-infused apps: what's possible and how to start
Building Generative AI-infused apps: what's possible and how to startMaxim Salnikov
 
Boost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made EasyBoost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made Easymichealwillson701
 
8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdfOffsiteNOC
 
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfFlutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfMind IT Systems
 
Enterprise Content Managements Solutions
Enterprise Content Managements SolutionsEnterprise Content Managements Solutions
Enterprise Content Managements SolutionsIQBG inc
 
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...telebusocialmarketin
 
MinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young EntrepreneurMinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young EntrepreneurPriyadarshini T
 
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...Splashtop Inc
 
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...jackiepotts6
 
Revolutionize Your Field Service Management with FSM Grid
Revolutionize Your Field Service Management with FSM GridRevolutionize Your Field Service Management with FSM Grid
Revolutionize Your Field Service Management with FSM GridMathew Thomas
 

Último (20)

Unlocking AI: Navigating Open Source vs. Commercial Frontiers
Unlocking AI:Navigating Open Source vs. Commercial FrontiersUnlocking AI:Navigating Open Source vs. Commercial Frontiers
Unlocking AI: Navigating Open Source vs. Commercial Frontiers
 
Leveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDevLeveling Up your Branding and Mastering MERN: Fullstack WebDev
Leveling Up your Branding and Mastering MERN: Fullstack WebDev
 
openEuler Community Overview - a presentation showing the current scale
openEuler Community Overview - a presentation showing the current scaleopenEuler Community Overview - a presentation showing the current scale
openEuler Community Overview - a presentation showing the current scale
 
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptxCYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
 
Unlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insightsUnlocking the Power of IoT: A comprehensive approach to real-time insights
Unlocking the Power of IoT: A comprehensive approach to real-time insights
 
20140812 - OBD2 Solution
20140812 - OBD2 Solution20140812 - OBD2 Solution
20140812 - OBD2 Solution
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
 
8 Steps to Build a LangChain RAG Chatbot.
8 Steps to Build a LangChain RAG Chatbot.8 Steps to Build a LangChain RAG Chatbot.
8 Steps to Build a LangChain RAG Chatbot.
 
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
BusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptxBusinessGPT  - SECURITY AND GOVERNANCE  FOR GENERATIVE AI.pptx
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
 
User Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller ResumeUser Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller Resume
 
Building Generative AI-infused apps: what's possible and how to start
Building Generative AI-infused apps: what's possible and how to startBuilding Generative AI-infused apps: what's possible and how to start
Building Generative AI-infused apps: what's possible and how to start
 
Boost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made EasyBoost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made Easy
 
8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf
 
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdfFlutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
 
Enterprise Content Managements Solutions
Enterprise Content Managements SolutionsEnterprise Content Managements Solutions
Enterprise Content Managements Solutions
 
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
Telebu Social -Whatsapp Business API : Mastering Omnichannel Business Communi...
 
MinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young EntrepreneurMinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
MinionLabs_Mr. Gokul Srinivas_Young Entrepreneur
 
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
 
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
03.2024_North America VMUG Optimizing RevOps using the power of ChatGPT in Ma...
 
Revolutionize Your Field Service Management with FSM Grid
Revolutionize Your Field Service Management with FSM GridRevolutionize Your Field Service Management with FSM Grid
Revolutionize Your Field Service Management with FSM Grid
 

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, …, …));

Notas do Editor

  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