Android ORMapping Library
I used Java annotations to implement the Android SQLite ORM library. I have written XML before. However, I feel that it is not very stable and the efficiency and robustness are not good in all aspects, it took me one afternoon to complete all the annotations and comments, generate javadoc, write the sample program, and publish it to Github: duplicate copy code 1 // entity class 2 @ Table (name = "dog") 3 public class Dog {4 private boolean alive; 5 private int id; 6 private String name; 7 8 public Dog () {9 10} 11 12 public Dog (boolean alive, String name) {13 this. alive = alive; 14 this. name = name; 15} 16 17 @ Id (name = "id") 18 @ Column (name = "id", type = DataType. integer) 19 public int getId () {20 return id; 21} 22 23 @ Column (name = "name", type = DataType. varchar, length = 20) 24 public String getName () {25 return name; 26} 27 28 @ Column (name = "alive", type = DataType. boolean) 29 public boolean isAlive () {30 return alive; 31} 32 33 public void setAlive (boolean alive) {34 this. alive = alive; 35} 36 37 public void setId (int id) {38 this. id = id; 39} 40 41 public void setName (String name) {42 this. name = name; 43} 44} 45 46 // Add 47 AnnotationDao = new AnnotationDao (this, Dog. class); 48 49 String name = "dog1"; 50 boolean alive = true; 51 52 Dog dog = new Dog (alive, name); 53 dao. insert (dog); 54 55 // search 56 // List all objects 57 list = dao. list (); 58 // query 59 dao by ID. query (3); 60 61 // Delete 62 dao. delete (dog); 63 64 // update. When updating, ensure that the id field corresponds to the value in the database, that is, the 65 dog obtained by calling list or query. setName ("dog2"); 66 dao. update (dog );