Comments (12)
To everyone interested in this: please state what's your use case for this. Maybe we can offer better alternatives in the future.
from greendao.
I would like to see that. Another possibility would be to generate an EntityDaoBase and have an EntityDao that extends EntityDaoBase - or would that break some private API?
from greendao.
UseCase 1#: If you want to sync from a Webservice you want something like a updateOrInsert
UseCase 2#: I could imagine some nice scope methods for predefined QueryBuilders
from greendao.
I expected those use cases and think that there may be better solutions to those:
Use case 1: insertOrReplace does not work for you? Please also check issue #32.
Use case 2: How about generating those queries (in a future version)? Check issue #33.
What do you think?
from greendao.
#1 insertOrReplace looks great!
#2 The generation looks cool, but if you want to do really complex stuff it will be hard to create a good DSL for that (currently no use case on hand). I guess going for keep sections is easier to implement.
from greendao.
Yes, I agree. we should probably go for both.
from greendao.
#1 When I have to obtain objects from a webservice and create the entities in the model, I think the parse+insertOrReplace method should be something encapsulated in the DAO.
#2 Complex queries should also be encapsulated in the DAO. I don't need them be automatically generated, but I would like to have them in the DAO rather than someplace else.
Keep sections would both solve this scenarios.
How do you guys currently implement these kind of scenarios?
from greendao.
i actually disagree for #1. that responsibility belongs to business logic. imho, some other code should handle the request, parse it, validate it and than add to DB. (at least this is how we do it). Parsing objects requires having annotation support in our case which we added to greenDAO and I'm still hoping to keep my promise to send a patch to Markus.
for #2, we've encapsulated all DAO operations inside custom models which can be backed by different data structures (for now we have greendao and lruCache) this helps us depend as minimum as possible on green dao. so generating all complex queries, caching them etc. is a responsibility of these model classes.
We've also changed code generator a little bit to produce two classes, Entity and EntityBase. Entitiy extends EntityBase and EntityBase is an abstract class. Entity is an empty class and only has constructors matching EntityBase. This way, we write all of the custom code to Entity classes and are able to extend basic setters and getters, which comes handy in may situations like parsing server request.
this is how we do it, not necessarily the best way but been working nice so far for us. (https://github.com/path/greenDAO)
from greendao.
There are definitely other ways to do it, but under some architectures, it would be simpler to be able to embed frequent queries into the DAO rather than repeat them in multiple places.
Given we can do this for entities is there a good reason not to have this for DAOs? It would at least be consistent...
from greendao.
If we ever support annotation processing, this might be an issue.
from greendao.
@Keep
annotation have no effect on generated dao class
from greendao.
@pzhangleo Please file a separate issue with more details (example) about your problem! Note: @Keep
annotations can only be used in entity classes, not the generated DAO classes. -ut
from greendao.
Related Issues (20)
- Is there any plan for supporting gradle 7.0? HOT 2
- open software HOT 1
- incompatible gradle-6.5-bin.zip HOT 1
- Blocker issue in Sonarqube HOT 2
- Openharmony application HOT 1
- 一对多的关系表映射问题 HOT 3
- disk image is malformed (Sqlite code 11 SQLITE_CORRUPT) HOT 1
- How to do data filling, such as populating data from a database in assets into an app HOT 1
- Read this first! Check out our new database
- kotlin version problem HOT 1
- Can I use greenDao in multiple libraries? ------ Look forward to your reply HOT 1
- 什么时候支持协程 HOT 1
- Will a new version be released in the future when a bug occurs in the project? HOT 1
- DaoGenerator.getConfiguration Exception HOT 2
- Lambda 表达式报错 HOT 2
- The project encountered errors after updating Gradle Version 7.6.1 to Gradle Version 8.0+ HOT 40
- when use ’group by‘ ,the result is not expected HOT 1
- Unable to load class 'org.greenrobot.greendao.codemodifier.FormattingOptions'.
- DaoMaster class error HOT 1
- error: cannot find symbol db.execSQL("CREATE TABLE " + constraint + "\ symbol: method makeConcatWithConstants(Lookup,String,MethodType,String) location: interface StringConcatFactory HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from greendao.