Https://github.com/greenrobot/greenDAO
An example of downloading the Xia Guan Network is a complete package version, but self-encapsulation is a problem.
Many of the methods in Greendao's master and session are completely hidden and belong to this class only.
A lot of information is also hidden.
Can only be implemented on the basis of inheriting these two classes (like the official website example)
To achieve the most basic of a demo through the public method also encountered a lot of pits.
This is an example
Master.devopenhelper dbhelp=New master.devopenhelper (This, "dbname",null); Sqlitedatabase db=dbhelp.getwritabledatabase (); Daoconfig DC=new daoconfig (Db,baiduuserdao. Class); Baiduuserdao DAO=new Baiduuserdao (DC); Baiduuser Baiduuser=new baiduuser (null, "tel", "name1", "pwd", "Mail"); Dao.insert (baiduuser);
There are two pits
One:
Baiduuserdao class must set tablename static property
public static final String TABLENAME = "Baiduuser";
Or you'll get an error.
Java.lang.NoSuchFieldException:TABLENAME
Two must be set properties static inner class
public static class Properties {
Public final static Property Id = new Property (0, Long.class, "Id", True, "_id");
Public final static Property Tel = new Property (1, String.class, "Telphone", False, "tel");
Public final static Property UserName = new Property (2, String.class, "UserName", False, "UserName");
Public final static Property e-mail = new Property (3, String.class, "password", false, "email");
Public final static Property PassWord = new Property (4, String.class, "email", False, "PassWord");
};
Or you'll get an error.
Java.lang.classnotfoundexception:com.mac.cdp.androidbaidusign.dao.baiduuserdao$properties
Fortunately, there is an abnormal information hint, otherwise there is no restrictions within the class, there is no obvious explanation.
But it can also be understood that it is too wasteful to restrict to constructs, while static methods are more field-saving.
......
I still follow the example of Git in the test code, by inheriting the session and master.
I really don't have to worry about anything.
Want to not according to the path of the official website to encapsulate a few tool classes, found that there is no way to go, only according to his path
Master 's Registerdaoclass method
Can only be called in a subclass. The public method is not provided and can only be called in a subclass implementation, or a layer of public methods.
The external package of Android Greendao is not very friendly.