greendao

Creating more than 1 *.db file with greenDao android ORM library

喜夏-厌秋 提交于 2019-12-06 07:34:46
I'm using greenDao library ( http://greendao-orm.com/ ) for managing my android app database. Everything works fine, but I can't find a way to create many *.db files. All my tables are in the same single file i.ex. books.db. Is there a way to tell greenDao to put books related tables in books.db and authors related tables in authors.db? Thanks in advance for help. EDIT: Ok I've solved the problem. You can make many *.db files by putting them in different schemas and then use generatedAll for each schemas i.ex: try { new DaoGenerator().generateAll(schema1, _path); new DaoGenerator().generateAll

Passing correct context to greendao's OpenHelper constructor

徘徊边缘 提交于 2019-12-06 07:32:51
问题 If I understand correctly, when working with DB, I have to do as follows DaoMaster.OpenHelper helper = new DaoMaster.OpenHelper(this, "test-db", null) { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }; SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); But if I try to do this in classes that aren't extending activity or service, I simply couln't pass their context. What is

How to know all open connections of data base using green DAO..?

给你一囗甜甜゛ 提交于 2019-12-06 05:45:33
问题 Hi everyone iam new to android and using green DAO for managing database but iam frequently getting a database not closed exception as iam doing that in Application onTeriminate(),iam maintaining only single connection of database through out the Application but in some cases when my application goes to background and resumes data base connection object is becoming null, i handled the problem by checking null ness of object before using but now iam frequently getting the exception that

How to generate a content provider with GreenDao 3?

╄→гoц情女王★ 提交于 2019-12-05 18:32:28
In GreenDao 2.x., there was a method called Entity.addContentProvider() which generated a ContentProvider for an entity. How to do the same in GreenDao 3.x? With the same method Entity.addContentProvider() I am able to generate the content provider in GreenDao 3. 来源: https://stackoverflow.com/questions/38935475/how-to-generate-a-content-provider-with-greendao-3

Multiple toMany relationships to a single table

给你一囗甜甜゛ 提交于 2019-12-05 10:28:14
I'm new to greenDAO and I'm working on writing the DaoGenerator. One issue that I've run into is that I have a user table and a wallpost table. I would like to be able to have two columns in the wallpost table that are toMany relations to the user table (the wall owner and the posting user) they may or may not be the same user, but so far it doesn't look like it is possible to have two toMany relations that point to a single table in the same table. Is there a better way to do this/a way to make this possible? I'm hoping to be able to load the wall posts and fetch the wall owner and posting

DaoException: Entity is detached from DAO context

a 夏天 提交于 2019-12-05 07:56:33
I have two entities, User and Store . User has many Stores (1:M) relation. I've inserted some stores list into the store table by following code. public void saveStoresToDatabase(Context context, ArrayList<Store> storeList) { DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "notes-db", null); SQLiteDatabase db = helper.getWritableDatabase(); DaoMaster daoMaster = new DaoMaster(db); DaoSession daoSession = daoMaster.newSession(); StoreDao storeDao = daoSession.getStoreDao(); ArrayList <Store> list = SharedData.getInstance().getUser().getStoreList(); for(int i = 0; i < storeList.size(

GreenDAO support multiple relations between tables

自作多情 提交于 2019-12-05 00:08:06
I've been trying to create a DB model using GreenDAO. the problem started when I tried to create more than one relationship between a different tables. basically, I have a Message table, a Conversation table and a User table. the User has a list of messages, and the message has a parent conversation. I tried writing this code for creating the DB: private static void addUser(Schema schema) { user = schema.addEntity("User"); userId = user.addIdProperty().getProperty(); user.addStringProperty("facebookId").unique().index(); user.addStringProperty("firstName"); user.addStringProperty("lastName");

What is the best way of creating greenDAO DB connection only once for single run of application?

守給你的承諾、 提交于 2019-12-04 13:27:22
Currently I am creating the greenDAO DB connection in a class (which opens the connection in every static method) and using it wherever I need it. But I am not sure if it's the best way of doing it. Can anyone suggest a better way of doing it? My Code: import com.knowlarity.sr.db.dao.DaoMaster; import com.knowlarity.sr.db.dao.DaoMaster.DevOpenHelper; import com.knowlarity.sr.db.dao.DaoSession; import com.knowlarity.sr.db.dao.IEntity; public class DbUtils { private static Object lockCallRecord =new Object(); private DbUtils(){}; public static boolean saveEntity(Context context , IEntity entity)

greendao listview all data from Entity

孤人 提交于 2019-12-04 13:05:59
GreenDAO. Which there is a simple way to display all the records from a Entity in the ListView, and is supported with the auto-update the list. Perhaps Lazylist class? how to use it? Have a look here . I'm using an adapter like this (including a ViewHolder-Pattern to reuse the Views inside the ListView) as well and it is fast even for a lot of records. But this won't be usable if you need auto-update-functionality. Here are some information about LasyList to explain why: Get LazyList using Query.listLazy() : This will not show new inserted records (or stop deleted records from displaying)

How to integrate greenDAO with JSON Jackson and handle many to many relation mapping

泄露秘密 提交于 2019-12-04 07:45:34
Is there any best way to integrate JSON Jackson with greenDAO. Also, how to handle many to many relation mapping using greenDAO. I found that, we need to create a connecting table to have many to many mapping. Is there any example having all these features together. You can do it in dao Generator file edit entity.ftl and add necessary lines to integrate Jackson ie import com.fasterxml.jackson.annotation.JsonProperty; and @JsonProperty("Tag Name") Thus you dont have to write any extra code for this. 来源: https://stackoverflow.com/questions/18374306/how-to-integrate-greendao-with-json-jackson-and