1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
package de.greenrobot.daogenerator.gentest; import de.greenrobot.daogenerator.DaoGenerator; import de.greenrobot.daogenerator.Entity; import de.greenrobot.daogenerator.Property; import de.greenrobot.daogenerator.Schema; import de.greenrobot.daogenerator.ToMany; /** * * * * * */ public class ExampleDaoGenerator { public static void main(String[] throws Exception { Schema new Schema( 3 , "de.greenrobot.daoexample" ); addNote(schema); addCustomerOrder(schema); new DaoGenerator().generateAll(schema, "../DaoExample/src-gen" ); } private static void addNote(Schema { Entity "Note" ); note.addIdProperty(); note.addStringProperty( "text" ).notNull(); note.addStringProperty( "comment" ); note.addDateProperty( "date" ); } private static void addCustomerOrder(Schema { Entity "Customer" ); customer.addIdProperty(); customer.addStringProperty( "name" ).notNull(); Entity "Order" ); order.setTableName( "ORDERS" ); // order.addIdProperty(); Property "date" ).getProperty(); Property "customerId" ).notNull().getProperty(); order.addToOne(customer, ToMany customerToOrders.setName( "orders" ); customerToOrders.orderAsc(orderDate); } } |
1
|
Schema new Schema( 3 , "de.greenrobot.daoexample" ); |
1
2
3
|
addNote(schema); addCustomerOrder(schema); new DaoGenerator().generateAll(schema, "../DaoExample/src-gen" ); |
1
2
3
4
5
|
Exception "main" java.io.FileNotFoundException: "dao.ftl" not at 742 ) at 665 ) at 68 ) at 41 ) |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
greenDAO Copyright 2011 - 2013 Markus This Processing 3 ... Written Written Written Written Written Written Written Written Processed 3 entities |
1
|
Entity "Note" ); |
1
|
dao.setTableName( "NoteList" ); |
1
|
dao.addIdProperty().primaryKey().autoincrement(); |
1
2
3
|
dao.addIntProperty( "cityId" ); dao.addStringProperty( "infoType" ).notNull(); //非null字段 dao.addDoubleProperty( "Id" ); |
1
|
java.lang.ClassCastException: |
1
2
3
4
5
6
7
|
public boolean isSaved( int ID) { QueryBuilder<SaveList> qb.where(Properties.Id.eq(ID)); qb.buildCount().count(); return qb.buildCount().count() 0 ? true : false ; } |
1
2
3
4
|
public List<PhotoGalleryDB> { return photoGalleryDao.loadAll(); // } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
/** public int getTypeId( int picId) { QueryBuilder<PhotoGalleryDB> qb.where(Properties.Id.eq(picId)); if (qb.list().size() 0 ) { return qb.list().get( 0 ).getTypeId(); } else { return - 1 ; } } |
1
2
3
4
|
List .where(Properties.FirstName.eq( "Joe" )) .orderAsc(Properties.LastName) .list(); |
1
2
3
4
5
6
7
|
public List<CityInfoDB> int cityId) { QueryBuilder<CityInfoDB> qb.where(qb.and(Properties.CityId.eq(cityId),Properties.InfoType.eq(HBContant.CITYINFO_SL))); qb.orderAsc(Properties.Id); // return qb.list(); } |
1
2
3
4
5
|
QueryBuilder qb.where(Properties.FirstName.eq( "Joe" ), qb.or(Properties.YearOfBirth.gt( 1970 ), qb.and(Properties.YearOfBirth.eq( 1970 ), 10 )))); List |
1
|
picJsonDao.loadByRowId(picId); |
1
2
3
4
|
public void addToPhotoTable(Photo { photoDao.insert(p); } |
1
2
3
4
5
6
7
|
DevOpenHelper new DaoMaster.DevOpenHelper( this , "notes-db" , null ); db daoMaster new DaoMaster(db); daoSession noteDao Note new Note( null , new Date()); noteDao.insert(note); |
1
2
|
photoDao.insertOrReplace(photo); photoDao.insertInTx(photo); |
1
2
3
4
5
|
/** public void clearPhoto() { photoDao.deleteAll(); } |
1
2
3
4
5
6
|
public void deleteCityInfo( int cityId) { QueryBuilder<DBCityInfo> DeleteQuery<DBCityInfo> bd.executeDeleteWithoutDetachingEntities(); } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
private static DaoMaster private static DaoSession /** * * * * */ public static DaoMaster { if (daoMaster null ) { OpenHelper new DaoMaster.DevOpenHelper(context, null ); daoMaster new DaoMaster(helper.getWritableDatabase()); } return daoMaster; } /** * * * * */ public static DaoSession { if (daoSession null ) { if (daoMaster null ) { daoMaster } daoSession } return daoSession; } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
public class DBHelper { private static Context private static DBHelper private CityInfoDBDao private DBHelper() { } public static DBHelper { if (instance null ) { instance new DBHelper(); if (mContext null ) { mContext } // DaoSession instance.cityInfoDao } return instance; } /** public void addToCityInfoTable(CityInfo { cityInfoDao.insert(item); } /** public List<EstateLoveListJson> { QueryBuilder<CityInfo> return qb.list(); } /** public List<CityInfo> { return cityInfoDao.loadAll(); // } /** public boolean isSaved( int Id) { QueryBuilder<CityInfo> qb.where(Properties.Id.eq(Id)); qb.buildCount().count(); return qb.buildCount().count() 0 ? true : false ; // } /** public void deleteCityInfoList( int Id) { QueryBuilder<CityInfo> DeleteQuery<CityInfo> bd.executeDeleteWithoutDetachingEntities(); } /** public void clearCityInfo() { cityInfoDao.deleteAll(); } /** public int getTypeId( int cityId) { QueryBuilder<CityInfo> qb.where(Properties.Id.eq(cityId)); if (qb.list().size() 0 ) { return qb.list().get( 0 ).getTypeId(); } else { return 0 ; } } /** public List<CityInfo> int cityId) { QueryBuilder<CityInfoDB> qb.where(qb.and(Properties.CityId.eq(cityId), qb.orderAsc(Properties.Id); // return qb.list(); } } |