Skip to content

Commit aaf2a61

Browse files
committed
tweet with local id
1 parent 9c64aef commit aaf2a61

File tree

4 files changed

+72
-46
lines changed

4 files changed

+72
-46
lines changed

app/src/main/java/com/birbit/android/livecode/twitter/vo/DaoMaster.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
1515
/**
16-
* Master of DAO (schema version 2): knows all DAOs.
16+
* Master of DAO (schema version 3): knows all DAOs.
1717
*/
1818
public class DaoMaster extends AbstractDaoMaster {
19-
public static final int SCHEMA_VERSION = 2;
19+
public static final int SCHEMA_VERSION = 3;
2020

2121
/** Creates underlying database table using DAOs. */
2222
public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {

app/src/main/java/com/birbit/android/livecode/twitter/vo/Tweet.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public class Tweet extends TweetBase implements com.birbit.android.livecode.twi
3131
public Tweet() {
3232
}
3333

34-
public Tweet(String id) {
35-
super(id);
34+
public Tweet(Long localId) {
35+
super(localId);
3636
}
3737

38-
public Tweet(String id, Boolean retweeted, String text, java.util.Date createdAt, String userId, Boolean favorited) {
39-
super(id, retweeted, text, createdAt, userId, favorited);
38+
public Tweet(Long localId, String id, Boolean retweeted, String text, java.util.Date createdAt, String userId, Boolean favorited) {
39+
super(localId, id, retweeted, text, createdAt, userId, favorited);
4040
}
4141

4242
// KEEP METHODS - put your custom methods here

app/src/main/java/com/birbit/android/livecode/twitter/vo/TweetBase.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
abstract public class TweetBase implements com.birbit.android.livecode.twitter.vo.CachesUIData {
1616

17+
protected Long localId;
1718
@com.google.gson.annotations.SerializedName( "id_str" )
1819
protected String id;
1920
@com.google.gson.annotations.SerializedName( "retweeted" )
@@ -32,11 +33,12 @@ abstract public class TweetBase implements com.birbit.android.livecode.twitter.v
3233
public TweetBase() {
3334
}
3435

35-
public TweetBase(String id) {
36-
this.id = id;
36+
public TweetBase(Long localId) {
37+
this.localId = localId;
3738
}
3839

39-
public TweetBase(String id, Boolean retweeted, String text, java.util.Date createdAt, String userId, Boolean favorited) {
40+
public TweetBase(Long localId, String id, Boolean retweeted, String text, java.util.Date createdAt, String userId, Boolean favorited) {
41+
this.localId = localId;
4042
this.id = id;
4143
this.retweeted = retweeted;
4244
this.text = text;
@@ -45,6 +47,14 @@ public TweetBase(String id, Boolean retweeted, String text, java.util.Date creat
4547
this.favorited = favorited;
4648
}
4749

50+
public Long getLocalId() {
51+
return localId;
52+
}
53+
54+
public void setLocalId(Long localId) {
55+
this.localId = localId;
56+
}
57+
4858
public String getId() {
4959
return id;
5060
}
@@ -98,6 +108,11 @@ public void updateNotNull(Tweet other) {
98108
return;//both came from db, no need to run this.
99109
}
100110

111+
if(other.localId != null) {
112+
this.localId = other.localId;
113+
}
114+
115+
101116
if(other.id != null) {
102117
this.id = other.id;
103118
}

app/src/main/java/com/birbit/android/livecode/twitter/vo/TweetDao.java

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* DAO for table TWEET.
1616
*/
17-
public class TweetDao extends AbstractDao<Tweet, String> {
17+
public class TweetDao extends AbstractDao<Tweet, Long> {
1818

1919
public static final String TABLENAME = "TWEET";
2020

@@ -23,12 +23,13 @@ public class TweetDao extends AbstractDao<Tweet, String> {
2323
* Can be used for QueryBuilder and for referencing column names.
2424
*/
2525
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");
3233
};
3334

3435

@@ -44,12 +45,13 @@ public TweetDao(DaoConfig config, DaoSession daoSession) {
4445
public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
4546
String constraint = ifNotExists? "IF NOT EXISTS ": "";
4647
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
5355
}
5456

5557
/** Drops the underlying database table. */
@@ -64,86 +66,95 @@ protected void bindValues(SQLiteStatement stmt, Tweet entity) {
6466
stmt.clearBindings();
6567
entity.onBeforeSave();
6668

69+
Long localId = entity.getLocalId();
70+
if (localId != null) {
71+
stmt.bindLong(1, localId);
72+
73+
}
74+
6775
String id = entity.getId();
6876
if (id != null) {
69-
stmt.bindString(1, id);
77+
stmt.bindString(2, id);
7078

7179
}
7280

7381
Boolean retweeted = entity.getRetweeted();
7482
if (retweeted != null) {
75-
stmt.bindLong(2, retweeted ? 1l: 0l);
83+
stmt.bindLong(3, retweeted ? 1l: 0l);
7684

7785
}
7886

7987
String text = entity.getText();
8088
if (text != null) {
81-
stmt.bindString(3, text);
89+
stmt.bindString(4, text);
8290

8391
}
8492

8593
java.util.Date createdAt = entity.getCreatedAt();
8694
if (createdAt != null) {
87-
stmt.bindLong(4, createdAt.getTime());
95+
stmt.bindLong(5, createdAt.getTime());
8896

8997
}
9098

9199
String userId = entity.getUserId();
92100
if (userId != null) {
93-
stmt.bindString(5, userId);
101+
stmt.bindString(6, userId);
94102

95103
}
96104

97105
Boolean favorited = entity.getFavorited();
98106
if (favorited != null) {
99-
stmt.bindLong(6, favorited ? 1l: 0l);
107+
stmt.bindLong(7, favorited ? 1l: 0l);
100108

101109
}
102110
}
103111

104112
/** @inheritdoc */
105113
@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);
108116
}
109117

110118
/** @inheritdoc */
111119
@Override
112120
public Tweet readEntity(Cursor cursor, int offset) {
113121
Tweet entity = new Tweet( //
114122

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
121130
);
122131
return entity;
123132
}
124133

125134
/** @inheritdoc */
126135
@Override
127136
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 );
134144
}
135145

136146
/** @inheritdoc */
137147
@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;
140151
}
141152

142153
/** @inheritdoc */
143154
@Override
144-
public String getKey(Tweet entity) {
155+
public Long getKey(Tweet entity) {
145156
if(entity != null) {
146-
return entity.getId();
157+
return entity.getLocalId();
147158
} else {
148159
return null;
149160
}

0 commit comments

Comments
 (0)