Search in sources :

Example 6 with Tag

use of ru.freeit.notes.data.db.entity.Tag in project LearningApps by evitwilly.

the class NoteDao_Impl method notesByTitle.

@Override
public Object notesByTitle(final Continuation<? super List<NoteWithTags>> continuation) {
    final String _sql = "select * from notes order by title";
    final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
    final CancellationSignal _cancellationSignal = DBUtil.createCancellationSignal();
    return CoroutinesRoom.execute(__db, true, _cancellationSignal, new Callable<List<NoteWithTags>>() {

        @Override
        public List<NoteWithTags> call() throws Exception {
            __db.beginTransaction();
            try {
                final Cursor _cursor = DBUtil.query(__db, _statement, true, null);
                try {
                    final int _cursorIndexOfTitle = CursorUtil.getColumnIndexOrThrow(_cursor, "title");
                    final int _cursorIndexOfCreatedDate = CursorUtil.getColumnIndexOrThrow(_cursor, "created_date");
                    final int _cursorIndexOfEditedDate = CursorUtil.getColumnIndexOrThrow(_cursor, "edited_date");
                    final int _cursorIndexOfId = CursorUtil.getColumnIndexOrThrow(_cursor, "id");
                    final LongSparseArray<ArrayList<Tag>> _collectionTags = new LongSparseArray<ArrayList<Tag>>();
                    while (_cursor.moveToNext()) {
                        final long _tmpKey = _cursor.getLong(_cursorIndexOfId);
                        ArrayList<Tag> _tmpTagsCollection = _collectionTags.get(_tmpKey);
                        if (_tmpTagsCollection == null) {
                            _tmpTagsCollection = new ArrayList<Tag>();
                            _collectionTags.put(_tmpKey, _tmpTagsCollection);
                        }
                    }
                    _cursor.moveToPosition(-1);
                    __fetchRelationshiptagsAsruFreeitNotesDataDbEntityTag(_collectionTags);
                    final List<NoteWithTags> _result = new ArrayList<NoteWithTags>(_cursor.getCount());
                    while (_cursor.moveToNext()) {
                        final NoteWithTags _item;
                        final Note _tmpNote;
                        if (!(_cursor.isNull(_cursorIndexOfTitle) && _cursor.isNull(_cursorIndexOfCreatedDate) && _cursor.isNull(_cursorIndexOfEditedDate) && _cursor.isNull(_cursorIndexOfId))) {
                            final String _tmpTitle;
                            if (_cursor.isNull(_cursorIndexOfTitle)) {
                                _tmpTitle = null;
                            } else {
                                _tmpTitle = _cursor.getString(_cursorIndexOfTitle);
                            }
                            final long _tmpCreatedDate;
                            _tmpCreatedDate = _cursor.getLong(_cursorIndexOfCreatedDate);
                            final long _tmpEditedDate;
                            _tmpEditedDate = _cursor.getLong(_cursorIndexOfEditedDate);
                            final long _tmpId;
                            _tmpId = _cursor.getLong(_cursorIndexOfId);
                            _tmpNote = new Note(_tmpTitle, _tmpCreatedDate, _tmpEditedDate, _tmpId);
                        } else {
                            _tmpNote = null;
                        }
                        ArrayList<Tag> _tmpTagsCollection_1 = null;
                        final long _tmpKey_1 = _cursor.getLong(_cursorIndexOfId);
                        _tmpTagsCollection_1 = _collectionTags.get(_tmpKey_1);
                        if (_tmpTagsCollection_1 == null) {
                            _tmpTagsCollection_1 = new ArrayList<Tag>();
                        }
                        _item = new NoteWithTags(_tmpNote, _tmpTagsCollection_1);
                        _result.add(_item);
                    }
                    __db.setTransactionSuccessful();
                    return _result;
                } finally {
                    _cursor.close();
                    _statement.release();
                }
            } finally {
                __db.endTransaction();
            }
        }
    }, continuation);
}
Also used : LongSparseArray(androidx.collection.LongSparseArray) ArrayList(java.util.ArrayList) NoteWithTags(ru.freeit.notes.data.db.entity.NoteWithTags) String(java.lang.String) RoomSQLiteQuery(androidx.room.RoomSQLiteQuery) Cursor(android.database.Cursor) Exception(java.lang.Exception) Note(ru.freeit.notes.data.db.entity.Note) ArrayList(java.util.ArrayList) List(java.util.List) Tag(ru.freeit.notes.data.db.entity.Tag) CancellationSignal(android.os.CancellationSignal) Override(java.lang.Override) Override(java.lang.Override)

Aggregations

Cursor (android.database.Cursor)6 LongSparseArray (androidx.collection.LongSparseArray)6 RoomSQLiteQuery (androidx.room.RoomSQLiteQuery)6 String (java.lang.String)6 ArrayList (java.util.ArrayList)6 Tag (ru.freeit.notes.data.db.entity.Tag)6 CancellationSignal (android.os.CancellationSignal)5 Exception (java.lang.Exception)5 Override (java.lang.Override)5 Note (ru.freeit.notes.data.db.entity.Note)5 NoteWithTags (ru.freeit.notes.data.db.entity.NoteWithTags)5 List (java.util.List)4 StringBuilder (java.lang.StringBuilder)1