LitePal icon indicating copy to clipboard operation
LitePal copied to clipboard

建议添加对"transient"修饰的支持

Open xiexindev opened this issue 5 years ago • 1 comments

由于LitePal的便利性, 一个数据对象实际上也有部分DAO的功能. 在实际应用中, 部分逻辑代码也直接在Entity中实现了. 这样不可避免的需要一些临时变量, 而这些临时变量实际上是没必要存在于数据库中的. 虽然在LitePal中提供了注解 @Column(ignore= true)可以实现忽略字段, 但是如果存在大量临时字段的时候, 大量的注解看起来让代码显得不够简洁. eg.

    @Column(ignore = true)
    private HashMap<String, Serializable> mExtrasMap;
    @Column(ignore = true)
    private long tempSize;
    @Column(ignore = true)
    private long lastRefreshTime;
    @Column(ignore = true)
    private long speed;
    @Column(ignore = true)
    private int progress;
    @Column(ignore = true)
    private final List<Long> speedBuffer = new ArrayList<>(10);

所以我建议将字段的 transient 修饰加入到忽略中, 其一是该字段本身就有排除序列化的意思, 其二可以让代码更加简洁. 这个修饰的使用, 可能会对 Serializable 的使用造成一定困扰, 但是也是可以结合@Column注解配合使用(例如在有注解的情况下就忽略修饰). 结合目前的使用情况, 我个人认为还是利大于弊的.

xiexindev avatar Sep 28 '20 05:09 xiexindev

很好的建议,我觉得可以考虑在下个版本加入。

guolindev avatar Sep 28 '20 08:09 guolindev