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

FeedDao.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: dc6348beaf49efa8674bcfefb93eacac65c0f807 (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
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 "FEED".
 */
public class FeedDao extends AbstractDao<Feed, Long> {

    public static final String TABLENAME = "FEED";

    private DaoSession daoSession;
    private Query<Feed> folder_FeedListQuery;

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

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

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

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists ? "IF NOT EXISTS " : "";
        db.execSQL("CREATE TABLE " + constraint + "\"FEED\" (" + //
                "\"_id\" INTEGER PRIMARY KEY NOT NULL ," + // 0: id
                "\"FOLDER_ID\" INTEGER," + // 1: folderId
                "\"FEED_TITLE\" TEXT NOT NULL ," + // 2: feedTitle
                "\"FAVICON_URL\" TEXT," + // 3: faviconUrl
                "\"LINK\" TEXT," + // 4: link
                "\"AVG_COLOUR\" TEXT," + // 5: avgColour
                "\"NOTIFICATION_CHANNEL\" TEXT);"); // 6: notificationChannel
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "IDX_FEED_FOLDER_ID ON FEED" +
                " (\"FOLDER_ID\");");
    }

    /**
     * @inheritdoc
     */
    @Override
    protected void bindValues(SQLiteStatement stmt, Feed entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());

        Long folderId = entity.getFolderId();
        if (folderId != null) {
            stmt.bindLong(2, folderId);
        }
        stmt.bindString(3, entity.getFeedTitle());

        String faviconUrl = entity.getFaviconUrl();
        if (faviconUrl != null) {
            stmt.bindString(4, faviconUrl);
        }

        String link = entity.getLink();
        if (link != null) {
            stmt.bindString(5, link);
        }

        String avgColour = entity.getAvgColour();
        if (avgColour != null) {
            stmt.bindString(6, avgColour);
        }

        String notificationChannel = entity.getNotificationChannel();
        if (notificationChannel != null) {
            stmt.bindString(7, notificationChannel);
        }
    }

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

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

    /** @inheritdoc */
    @Override
    public Feed readEntity(Cursor cursor, int offset) {
        Feed entity = new Feed( //
                cursor.getLong(offset + 0), // id
                cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // folderId
                cursor.getString(offset + 2), // feedTitle
                cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // faviconUrl
                cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // link
                cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // avgColour
                cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6) // notificationChannel
        );
        return entity;
    }

    /**
     * @inheritdoc
     */
    @Override
    public void readEntity(Cursor cursor, Feed entity, int offset) {
        entity.setId(cursor.getLong(offset + 0));
        entity.setFolderId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
        entity.setFeedTitle(cursor.getString(offset + 2));
        entity.setFaviconUrl(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setLink(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setAvgColour(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setNotificationChannel(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
    }

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

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

        Folder folder = loadCurrentOther(daoSession.getFolderDao(), cursor, offset);
        entity.setFolder(folder);

        return entity;
    }

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

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "feedList" to-many relationship of Folder. */
    public List<Feed> _queryFolder_FeedList(Long folderId) {
        synchronized (this) {
            if (folder_FeedListQuery == null) {
                QueryBuilder<Feed> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.FolderId.eq(null));
                folder_FeedListQuery = queryBuilder.build();
            }
        }
        Query<Feed> query = folder_FeedListQuery.forCurrentThread();
        query.setParameter(0, folderId);
        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.getFolderDao().getAllColumns());
            builder.append(" FROM FEED T");
            builder.append(" LEFT JOIN FOLDER T0 ON T.\"FOLDER_ID\"=T0.\"_id\"");
            builder.append(' ');
            selectDeep = builder.toString();
        }
        return selectDeep;
    }

    public Feed 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<Feed> loadAllDeepFromCursor(Cursor cursor) {
        int count = cursor.getCount();
        List<Feed> list = new ArrayList<Feed>(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 Feed.<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 FolderId = new Property(1, Long.class, "folderId", false, "FOLDER_ID");
        public final static Property FeedTitle = new Property(2, String.class, "feedTitle", false, "FEED_TITLE");
        public final static Property FaviconUrl = new Property(3, String.class, "faviconUrl", false, "FAVICON_URL");
        public final static Property Link = new Property(4, String.class, "link", false, "LINK");
        public final static Property AvgColour = new Property(5, String.class, "avgColour", false, "AVG_COLOUR");
        public final static Property NotificationChannel = new Property(6, String.class, "notificationChannel", false, "NOTIFICATION_CHANNEL");
    }

    protected List<Feed> 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<Feed> queryDeep(String where, String... selectionArg) {
        Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
        return loadDeepAllAndCloseCursor(cursor);
    }
 
}