Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RssItemDao.java « model « database « owncloudnewsreader « luhmer « de « java « main « src « News-Android-App - github.com/nextcloud/news-android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 078decd10a3318ab24991da95a4203a16c30ecfd (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
package de.luhmer.owncloudnewsreader.database.model;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

import java.util.ArrayList;
import java.util.List;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;
import de.greenrobot.dao.internal.SqlUtils;
import de.greenrobot.dao.query.Query;
import de.greenrobot.dao.query.QueryBuilder;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
 * DAO for table "RSS_ITEM".
 */
public class RssItemDao extends AbstractDao<RssItem, Long> {

    public static final String TABLENAME = "RSS_ITEM";

    /** @inheritdoc */
    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.getLong(offset + 0);
    }

    private DaoSession daoSession;

    private Query<RssItem> feed_RssItemListQuery;

    public RssItemDao(DaoConfig config) {
        super(config);
    }

    public RssItemDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"RSS_ITEM\" (" + //
                "\"_id\" INTEGER PRIMARY KEY NOT NULL ," + // 0: id
                "\"FEED_ID\" INTEGER NOT NULL ," + // 1: feedId
                "\"LINK\" TEXT," + // 2: link
                "\"TITLE\" TEXT," + // 3: title
                "\"BODY\" TEXT," + // 4: body
                "\"READ\" INTEGER," + // 5: read
                "\"STARRED\" INTEGER," + // 6: starred
                "\"AUTHOR\" TEXT NOT NULL ," + // 7: author
                "\"GUID\" TEXT NOT NULL ," + // 8: guid
                "\"GUID_HASH\" TEXT NOT NULL ," + // 9: guidHash
                "\"FINGERPRINT\" TEXT NOT NULL ," + // 10: fingerprint
                "\"READ_TEMP\" INTEGER," + // 11: read_temp
                "\"STARRED_TEMP\" INTEGER," + // 12: starred_temp
                "\"LAST_MODIFIED\" INTEGER," + // 13: lastModified
                "\"PUB_DATE\" INTEGER," + // 14: pubDate
                "\"ENCLOSURE_LINK\" TEXT," + // 15: enclosureLink
                "\"ENCLOSURE_MIME\" TEXT," + // 16: enclosureMime
                "\"MEDIA_THUMBNAIL\" TEXT," + // 17: mediaThumbnail
                "\"MEDIA_DESCRIPTION\" TEXT," + // 18: mediaDescription
                "\"RTL\" INTEGER);"); // 19: rtl
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "IDX_RSS_ITEM_FEED_ID ON RSS_ITEM" +
                " (\"FEED_ID\");");
    }

    /** Drops the underlying database table. */
    public static void dropTable(SQLiteDatabase db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"RSS_ITEM\"";
        db.execSQL(sql);
    }

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, RssItem entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
        stmt.bindLong(2, entity.getFeedId());
 
        String link = entity.getLink();
        if (link != null) {
            stmt.bindString(3, link);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(4, title);
        }
 
        String body = entity.getBody();
        if (body != null) {
            stmt.bindString(5, body);
        }
 
        Boolean read = entity.getRead();
        if (read != null) {
            stmt.bindLong(6, read ? 1L: 0L);
        }
 
        Boolean starred = entity.getStarred();
        if (starred != null) {
            stmt.bindLong(7, starred ? 1L: 0L);
        }
        stmt.bindString(8, entity.getAuthor());
        stmt.bindString(9, entity.getGuid());
        stmt.bindString(10, entity.getGuidHash());
        stmt.bindString(11, entity.getFingerprint());
 
        Boolean read_temp = entity.getRead_temp();
        if (read_temp != null) {
            stmt.bindLong(12, read_temp ? 1L: 0L);
        }
 
        Boolean starred_temp = entity.getStarred_temp();
        if (starred_temp != null) {
            stmt.bindLong(13, starred_temp ? 1L: 0L);
        }
 
        java.util.Date lastModified = entity.getLastModified();
        if (lastModified != null) {
            stmt.bindLong(14, lastModified.getTime());
        }
 
        java.util.Date pubDate = entity.getPubDate();
        if (pubDate != null) {
            stmt.bindLong(15, pubDate.getTime());
        }
 
        String enclosureLink = entity.getEnclosureLink();
        if (enclosureLink != null) {
            stmt.bindString(16, enclosureLink);
        }
 
        String enclosureMime = entity.getEnclosureMime();
        if (enclosureMime != null) {
            stmt.bindString(17, enclosureMime);
        }
 
        String mediaThumbnail = entity.getMediaThumbnail();
        if (mediaThumbnail != null) {
            stmt.bindString(18, mediaThumbnail);
        }
 
        String mediaDescription = entity.getMediaDescription();
        if (mediaDescription != null) {
            stmt.bindString(19, mediaDescription);
        }
 
        Boolean rtl = entity.getRtl();
        if (rtl != null) {
            stmt.bindLong(20, rtl ? 1L: 0L);
        }
    }

    @Override
    protected void attachEntity(RssItem entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    /** @inheritdoc */
    @Override
    public RssItem readEntity(Cursor cursor, int offset) {
        RssItem entity = new RssItem( //
                cursor.getLong(offset + 0), // id
                cursor.getLong(offset + 1), // feedId
                cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // link
                cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title
                cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // body
                cursor.isNull(offset + 5) ? null : cursor.getShort(offset + 5) != 0, // read
                cursor.isNull(offset + 6) ? null : cursor.getShort(offset + 6) != 0, // starred
                cursor.getString(offset + 7), // author
                cursor.getString(offset + 8), // guid
                cursor.getString(offset + 9), // guidHash
                cursor.getString(offset + 10), // fingerprint
                cursor.isNull(offset + 11) ? null : cursor.getShort(offset + 11) != 0, // read_temp
                cursor.isNull(offset + 12) ? null : cursor.getShort(offset + 12) != 0, // starred_temp
                cursor.isNull(offset + 13) ? null : new java.util.Date(cursor.getLong(offset + 13)), // lastModified
                cursor.isNull(offset + 14) ? null : new java.util.Date(cursor.getLong(offset + 14)), // pubDate
                cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // enclosureLink
                cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // enclosureMime
                cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // mediaThumbnail
                cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // mediaDescription
                cursor.isNull(offset + 19) ? null : cursor.getShort(offset + 19) != 0 // rtl
        );
        return entity;
    }

    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, RssItem entity, int offset) {
        entity.setId(cursor.getLong(offset + 0));
        entity.setFeedId(cursor.getLong(offset + 1));
        entity.setLink(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setBody(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setRead(cursor.isNull(offset + 5) ? null : cursor.getShort(offset + 5) != 0);
        entity.setStarred(cursor.isNull(offset + 6) ? null : cursor.getShort(offset + 6) != 0);
        entity.setAuthor(cursor.getString(offset + 7));
        entity.setGuid(cursor.getString(offset + 8));
        entity.setGuidHash(cursor.getString(offset + 9));
        entity.setFingerprint(cursor.getString(offset + 10));
        entity.setRead_temp(cursor.isNull(offset + 11) ? null : cursor.getShort(offset + 11) != 0);
        entity.setStarred_temp(cursor.isNull(offset + 12) ? null : cursor.getShort(offset + 12) != 0);
        entity.setLastModified(cursor.isNull(offset + 13) ? null : new java.util.Date(cursor.getLong(offset + 13)));
        entity.setPubDate(cursor.isNull(offset + 14) ? null : new java.util.Date(cursor.getLong(offset + 14)));
        entity.setEnclosureLink(cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15));
        entity.setEnclosureMime(cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16));
        entity.setMediaThumbnail(cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17));
        entity.setMediaDescription(cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18));
        entity.setRtl(cursor.isNull(offset + 19) ? null : cursor.getShort(offset + 19) != 0);
    }

    /**
     * @inheritdoc
     */
    @Override
    protected Long updateKeyAfterInsert(RssItem entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }

    /**
     * @inheritdoc
     */
    @Override
    public Long getKey(RssItem entity) {
        if (entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    protected RssItem loadCurrentDeep(Cursor cursor, boolean lock) {
        RssItem entity = loadCurrent(cursor, 0, lock);
        int offset = getAllColumns().length;

        Feed feed = loadCurrentOther(daoSession.getFeedDao(), cursor, offset);
        if (feed != null) {
            entity.setFeed(feed);
        }

        return entity;
    }

    /**
     * @inheritdoc
     */
    @Override
    protected boolean isEntityUpdateable() {
        return true;
    }

    /**
     * Internal query to resolve the "rssItemList" to-many relationship of Feed.
     */
    public List<RssItem> _queryFeed_RssItemList(long feedId) {
        synchronized (this) {
            if (feed_RssItemListQuery == null) {
                QueryBuilder<RssItem> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.FeedId.eq(null));
                feed_RssItemListQuery = queryBuilder.build();
            }
        }
        Query<RssItem> query = feed_RssItemListQuery.forCurrentThread();
        query.setParameter(0, feedId);
        return query.list();
    }

    private String selectDeep;

    protected String getSelectDeep() {
        if (selectDeep == null) {
            StringBuilder builder = new StringBuilder("SELECT ");
            SqlUtils.appendColumns(builder, "T", getAllColumns());
            builder.append(',');
            SqlUtils.appendColumns(builder, "T0", daoSession.getFeedDao().getAllColumns());
            builder.append(" FROM RSS_ITEM T");
            builder.append(" LEFT JOIN FEED T0 ON T.\"FEED_ID\"=T0.\"_id\"");
            builder.append(' ');
            selectDeep = builder.toString();
        }
        return selectDeep;
    }

    public RssItem loadDeep(Long key) {
        assertSinglePk();
        if (key == null) {
            return null;
        }

        StringBuilder builder = new StringBuilder(getSelectDeep());
        builder.append("WHERE ");
        SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
        String sql = builder.toString();

        String[] keyArray = new String[]{key.toString()};
        Cursor cursor = db.rawQuery(sql, keyArray);

        try {
            boolean available = cursor.moveToFirst();
            if (!available) {
                return null;
            } else if (!cursor.isLast()) {
                throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
            }
            return loadCurrentDeep(cursor, true);
        } finally {
            cursor.close();
        }
    }

    /**
     * Reads all available rows from the given cursor and returns a list of new ImageTO objects.
     */
    public List<RssItem> loadAllDeepFromCursor(Cursor cursor) {
        int count = cursor.getCount();
        List<RssItem> list = new ArrayList<RssItem>(count);

        if (cursor.moveToFirst()) {
            if (identityScope != null) {
                identityScope.lock();
                identityScope.reserveRoom(count);
            }
            try {
                do {
                    list.add(loadCurrentDeep(cursor, false));
                } while (cursor.moveToNext());
            } finally {
                if (identityScope != null) {
                    identityScope.unlock();
                }
            }
        }
        return list;
    }

    /**
     * Properties of entity RssItem.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, long.class, "id", true, "_id");
        public final static Property FeedId = new Property(1, long.class, "feedId", false, "FEED_ID");
        public final static Property Link = new Property(2, String.class, "link", false, "LINK");
        public final static Property Title = new Property(3, String.class, "title", false, "TITLE");
        public final static Property Body = new Property(4, String.class, "body", false, "BODY");
        public final static Property Read = new Property(5, Boolean.class, "read", false, "READ");
        public final static Property Starred = new Property(6, Boolean.class, "starred", false, "STARRED");
        public final static Property Author = new Property(7, String.class, "author", false, "AUTHOR");
        public final static Property Guid = new Property(8, String.class, "guid", false, "GUID");
        public final static Property GuidHash = new Property(9, String.class, "guidHash", false, "GUID_HASH");
        public final static Property Fingerprint = new Property(10, String.class, "fingerprint", false, "FINGERPRINT");
        public final static Property Read_temp = new Property(11, Boolean.class, "read_temp", false, "READ_TEMP");
        public final static Property Starred_temp = new Property(12, Boolean.class, "starred_temp", false, "STARRED_TEMP");
        public final static Property LastModified = new Property(13, java.util.Date.class, "lastModified", false, "LAST_MODIFIED");
        public final static Property PubDate = new Property(14, java.util.Date.class, "pubDate", false, "PUB_DATE");
        public final static Property EnclosureLink = new Property(15, String.class, "enclosureLink", false, "ENCLOSURE_LINK");
        public final static Property EnclosureMime = new Property(16, String.class, "enclosureMime", false, "ENCLOSURE_MIME");
        public final static Property MediaThumbnail = new Property(17, String.class, "mediaThumbnail", false, "MEDIA_THUMBNAIL");
        public final static Property MediaDescription = new Property(18, String.class, "mediaDescription", false, "MEDIA_DESCRIPTION");
        public final static Property Rtl = new Property(19, Boolean.class, "rtl", false, "RTL");
    }
    
    protected List<RssItem> loadDeepAllAndCloseCursor(Cursor cursor) {
        try {
            return loadAllDeepFromCursor(cursor);
        } finally {
            cursor.close();
        }
    }
    

    /** A raw-style query where you can pass any WHERE clause and arguments. */
    public List<RssItem> queryDeep(String where, String... selectionArg) {
        Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
        return loadDeepAllAndCloseCursor(cursor);
    }
 
}