greendao的扩展

来源:互联网 发布:c语言 生成时间戳 编辑:程序博客网 时间:2024/06/07 16:39

greendao是一个orm框架,在数据库操作方面有很多优势,本人使用中进行了扩展,如下:

1数据库表字段的默认值

Entity entity = schema.addEntity("C");
entity.addStringProperty("user_name").defValue("123");
defValue参数为字符串2唯一性冲突置换策略
entity.addIntProperty("user_id").unique().replaceOnConflict();
replaceOnConflict目前只支持ON CONFLICT REPLACE3支持propertyName即为表字段名原先greendao生成数据库代码时,表名是通过
propertyName转换的
entity.addIntProperty("user_id"),类似
user_id就是表字段名字4支持表直接的继承关系A表是B表子集
Entity entity = schema.addEntity("B");entity.setTableName("B");entity.setSuperclass("A");entity.useExtendsEntity();5支持数据库所对应表的类的私有变量名字修改
entity.addIntProperty("user_id").variableName("mUserId");如果不修改就是user_id
6支持数据库所对应表的类的私有变量
entity.addIntProperty("user_id").initMembersVar("123");
7支持数据库所对应表类set,get后缀名修改,boolean返回值时get可转为is
entity.addStringProperty("user_name").suffixMethodName("UserName");
8支持数据库直接查询的cursor转为对应表的实例

本文扩展主要针对greendao-generator扩展,里面用到freemarker.jar,freemarker模板语法参见如下:

http://www.cnblogs.com/linjiqin/p/3388298.html


greendao基本使用来自https://github.com/greenrobot/greenDAO
http://greendao-orm.com/documentation/

原先忘记上传修改的源码,现在上传,大家可以参考,这个后面也有其他人修改







1 0
原创粉丝点击