14
14
/**
15
15
* DAO for table TWEET.
16
16
*/
17
- public class TweetDao extends AbstractDao <Tweet , String > {
17
+ public class TweetDao extends AbstractDao <Tweet , Long > {
18
18
19
19
public static final String TABLENAME = "TWEET" ;
20
20
@@ -23,12 +23,13 @@ public class TweetDao extends AbstractDao<Tweet, String> {
23
23
* Can be used for QueryBuilder and for referencing column names.
24
24
*/
25
25
public static class Properties {
26
- public final static Property Id =new Property (0 , String .class , "id" , true , "id_str" );
27
- public final static Property Retweeted =new Property (1 , Boolean .class , "retweeted" , false , "RETWEETED" );
28
- public final static Property Text =new Property (2 , String .class , "text" , false , "TEXT" );
29
- public final static Property CreatedAt =new Property (3 , java .util .Date .class , "createdAt" , false , "CREATED_AT" );
30
- public final static Property UserId =new Property (4 , String .class , "userId" , false , "USER_ID" );
31
- public final static Property Favorited =new Property (5 , Boolean .class , "favorited" , false , "FAVORITED" );
26
+ public final static Property LocalId =new Property (0 , Long .class , "localId" , true , "LOCAL_ID" );
27
+ public final static Property Id =new Property (1 , String .class , "id" , false , "id_str" );
28
+ public final static Property Retweeted =new Property (2 , Boolean .class , "retweeted" , false , "RETWEETED" );
29
+ public final static Property Text =new Property (3 , String .class , "text" , false , "TEXT" );
30
+ public final static Property CreatedAt =new Property (4 , java .util .Date .class , "createdAt" , false , "CREATED_AT" );
31
+ public final static Property UserId =new Property (5 , String .class , "userId" , false , "USER_ID" );
32
+ public final static Property Favorited =new Property (6 , Boolean .class , "favorited" , false , "FAVORITED" );
32
33
};
33
34
34
35
@@ -44,12 +45,13 @@ public TweetDao(DaoConfig config, DaoSession daoSession) {
44
45
public static void createTable (SQLiteDatabase db , boolean ifNotExists ) {
45
46
String constraint = ifNotExists ? "IF NOT EXISTS " : "" ;
46
47
db .execSQL ("CREATE TABLE " + constraint + "'TWEET' (" + //
47
- "'id_str' TEXT PRIMARY KEY NOT NULL ," + // 0: id
48
- "'RETWEETED' INTEGER," + // 1: retweeted
49
- "'TEXT' TEXT," + // 2: text
50
- "'CREATED_AT' INTEGER," + // 3: createdAt
51
- "'USER_ID' TEXT," + // 4: userId
52
- "'FAVORITED' INTEGER);" ); // 5: favorited
48
+ "'LOCAL_ID' INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: localId
49
+ "'id_str' TEXT UNIQUE ," + // 1: id
50
+ "'RETWEETED' INTEGER," + // 2: retweeted
51
+ "'TEXT' TEXT," + // 3: text
52
+ "'CREATED_AT' INTEGER," + // 4: createdAt
53
+ "'USER_ID' TEXT," + // 5: userId
54
+ "'FAVORITED' INTEGER);" ); // 6: favorited
53
55
}
54
56
55
57
/** Drops the underlying database table. */
@@ -64,86 +66,95 @@ protected void bindValues(SQLiteStatement stmt, Tweet entity) {
64
66
stmt .clearBindings ();
65
67
entity .onBeforeSave ();
66
68
69
+ Long localId = entity .getLocalId ();
70
+ if (localId != null ) {
71
+ stmt .bindLong (1 , localId );
72
+
73
+ }
74
+
67
75
String id = entity .getId ();
68
76
if (id != null ) {
69
- stmt .bindString (1 , id );
77
+ stmt .bindString (2 , id );
70
78
71
79
}
72
80
73
81
Boolean retweeted = entity .getRetweeted ();
74
82
if (retweeted != null ) {
75
- stmt .bindLong (2 , retweeted ? 1l : 0l );
83
+ stmt .bindLong (3 , retweeted ? 1l : 0l );
76
84
77
85
}
78
86
79
87
String text = entity .getText ();
80
88
if (text != null ) {
81
- stmt .bindString (3 , text );
89
+ stmt .bindString (4 , text );
82
90
83
91
}
84
92
85
93
java .util .Date createdAt = entity .getCreatedAt ();
86
94
if (createdAt != null ) {
87
- stmt .bindLong (4 , createdAt .getTime ());
95
+ stmt .bindLong (5 , createdAt .getTime ());
88
96
89
97
}
90
98
91
99
String userId = entity .getUserId ();
92
100
if (userId != null ) {
93
- stmt .bindString (5 , userId );
101
+ stmt .bindString (6 , userId );
94
102
95
103
}
96
104
97
105
Boolean favorited = entity .getFavorited ();
98
106
if (favorited != null ) {
99
- stmt .bindLong (6 , favorited ? 1l : 0l );
107
+ stmt .bindLong (7 , favorited ? 1l : 0l );
100
108
101
109
}
102
110
}
103
111
104
112
/** @inheritdoc */
105
113
@ Override
106
- public String readKey (Cursor cursor , int offset ) {
107
- return cursor .isNull (offset + 0 ) ? null : cursor .getString (offset + 0 );
114
+ public Long readKey (Cursor cursor , int offset ) {
115
+ return cursor .isNull (offset + 0 ) ? null : cursor .getLong (offset + 0 );
108
116
}
109
117
110
118
/** @inheritdoc */
111
119
@ Override
112
120
public Tweet readEntity (Cursor cursor , int offset ) {
113
121
Tweet entity = new Tweet ( //
114
122
115
- cursor .isNull (offset + 0 ) ? null : cursor .getString (offset + 0 ) , // id
116
- cursor .isNull (offset + 1 ) ? null : cursor .getShort (offset + 1 ) != 0 , // retweeted
117
- cursor .isNull (offset + 2 ) ? null : cursor .getString (offset + 2 ) , // text
118
- cursor .isNull (offset + 3 ) ? null : new java .util .Date ( cursor .getLong (offset + 3 ) ) , // createdAt
119
- cursor .isNull (offset + 4 ) ? null : cursor .getString (offset + 4 ) , // userId
120
- cursor .isNull (offset + 5 ) ? null : cursor .getShort (offset + 5 ) != 0 // favorited
123
+ cursor .isNull (offset + 0 ) ? null : cursor .getLong (offset + 0 ) , // localId
124
+ cursor .isNull (offset + 1 ) ? null : cursor .getString (offset + 1 ) , // id
125
+ cursor .isNull (offset + 2 ) ? null : cursor .getShort (offset + 2 ) != 0 , // retweeted
126
+ cursor .isNull (offset + 3 ) ? null : cursor .getString (offset + 3 ) , // text
127
+ cursor .isNull (offset + 4 ) ? null : new java .util .Date ( cursor .getLong (offset + 4 ) ) , // createdAt
128
+ cursor .isNull (offset + 5 ) ? null : cursor .getString (offset + 5 ) , // userId
129
+ cursor .isNull (offset + 6 ) ? null : cursor .getShort (offset + 6 ) != 0 // favorited
121
130
);
122
131
return entity ;
123
132
}
124
133
125
134
/** @inheritdoc */
126
135
@ Override
127
136
public void readEntity (Cursor cursor , Tweet entity , int offset ) {
128
- entity .setId (cursor .isNull (offset + 0 ) ? null : cursor .getString (offset + 0 ) );
129
- entity .setRetweeted (cursor .isNull (offset + 1 ) ? null : cursor .getShort (offset + 1 ) != 0 );
130
- entity .setText (cursor .isNull (offset + 2 ) ? null : cursor .getString (offset + 2 ) );
131
- entity .setCreatedAt (cursor .isNull (offset + 3 ) ? null : new java .util .Date ( cursor .getLong (offset + 3 ) ) );
132
- entity .setUserId (cursor .isNull (offset + 4 ) ? null : cursor .getString (offset + 4 ) );
133
- entity .setFavorited (cursor .isNull (offset + 5 ) ? null : cursor .getShort (offset + 5 ) != 0 );
137
+ entity .setLocalId (cursor .isNull (offset + 0 ) ? null : cursor .getLong (offset + 0 ) );
138
+ entity .setId (cursor .isNull (offset + 1 ) ? null : cursor .getString (offset + 1 ) );
139
+ entity .setRetweeted (cursor .isNull (offset + 2 ) ? null : cursor .getShort (offset + 2 ) != 0 );
140
+ entity .setText (cursor .isNull (offset + 3 ) ? null : cursor .getString (offset + 3 ) );
141
+ entity .setCreatedAt (cursor .isNull (offset + 4 ) ? null : new java .util .Date ( cursor .getLong (offset + 4 ) ) );
142
+ entity .setUserId (cursor .isNull (offset + 5 ) ? null : cursor .getString (offset + 5 ) );
143
+ entity .setFavorited (cursor .isNull (offset + 6 ) ? null : cursor .getShort (offset + 6 ) != 0 );
134
144
}
135
145
136
146
/** @inheritdoc */
137
147
@ Override
138
- protected String updateKeyAfterInsert (Tweet entity , long rowId ) {
139
- return entity .getId ();
148
+ protected Long updateKeyAfterInsert (Tweet entity , long rowId ) {
149
+ entity .setLocalId (rowId );
150
+ return rowId ;
140
151
}
141
152
142
153
/** @inheritdoc */
143
154
@ Override
144
- public String getKey (Tweet entity ) {
155
+ public Long getKey (Tweet entity ) {
145
156
if (entity != null ) {
146
- return entity .getId ();
157
+ return entity .getLocalId ();
147
158
} else {
148
159
return null ;
149
160
}
0 commit comments