FreeRDP
Loading...
Searching...
No Matches
ManualBookmarkGateway.java
1/*
2 Manual bookmarks database gateway
3
4 Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9*/
10
11package com.freerdp.freerdpcore.services;
12
13import androidx.lifecycle.LiveData;
14
15import com.freerdp.freerdpcore.data.BookmarkConverter;
16import com.freerdp.freerdpcore.data.BookmarkDao;
17import com.freerdp.freerdpcore.data.BookmarkEntity;
18import com.freerdp.freerdpcore.domain.BookmarkBase;
19
20import java.util.ArrayList;
21import java.util.List;
22
24{
25 private final BookmarkDao dao;
26
27 public ManualBookmarkGateway(BookmarkDao dao)
28 {
29 this.dao = dao;
30 }
31
32 public LiveData<List<BookmarkEntity>> getAllLiveData()
33 {
34 return dao.getAllLiveData();
35 }
36
37 public ArrayList<BookmarkBase> findAll()
38 {
39 List<BookmarkEntity> entities = dao.getAll();
40 ArrayList<BookmarkBase> result = new ArrayList<>(entities.size());
41 for (BookmarkEntity e : entities)
42 result.add(BookmarkConverter.toBookmark(e));
43 return result;
44 }
45
46 public BookmarkBase findById(long id)
47 {
48 BookmarkEntity e = dao.getById(id);
49 return (e != null) ? BookmarkConverter.toBookmark(e) : null;
50 }
51
52 public long insert(BookmarkBase bookmark)
53 {
54 long newId = dao.insert(BookmarkConverter.toEntity(bookmark));
55 bookmark.setId(newId);
56 return newId;
57 }
58
59 public boolean update(BookmarkBase bookmark)
60 {
61 dao.update(BookmarkConverter.toEntity(bookmark));
62 return true;
63 }
64
65 public boolean delete(long id)
66 {
67 dao.deleteById(id);
68 return true;
69 }
70
71 public ArrayList<BookmarkBase> findByLabelOrHostnameLike(String pattern)
72 {
73 List<BookmarkEntity> entities = dao.search("%" + pattern + "%");
74 ArrayList<BookmarkBase> result = new ArrayList<>(entities.size());
75 for (BookmarkEntity e : entities)
76 result.add(BookmarkConverter.toBookmark(e));
77 return result;
78 }
79}