Java Code Examples for org.litepal.LitePal#findLast()
The following examples show how to use
org.litepal.LitePal#findLast() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddAndEditPoetryActivity.java From PoetryWeather with Apache License 2.0 | 5 votes |
/** * 初始化id */ private void checkId() { PoetryDb poetryDb = LitePal.findLast(PoetryDb.class); if (poetryDb == null) { id = 1; } else { id = poetryDb.getPoetryDb_id() + 1; } }
Example 2
Source File: QueryClusterTest.java From LitePal with Apache License 2.0 | 5 votes |
@Test public void testLimit() { List<Book> bookList = LitePal.limit(1).find(Book.class); assertEquals(1, bookList.size()); Book book = bookList.get(0); assertTrue(book.isSaved()); Book firstBook = LitePal.findFirst(Book.class); assertTrue(firstBook.isSaved()); assertEquals(firstBook.getBookName(), book.getBookName()); assertEquals(firstBook.getPages(), book.getPages()); assertEquals(firstBook.isPublished(), book.isPublished()); assertEquals(firstBook.getArea(), book.getArea()); assertEquals(firstBook.getPrice(), book.getPrice()); assertEquals(firstBook.getIsbn(), book.getIsbn()); assertEquals(firstBook.getLevel(), book.getLevel()); assertEquals(firstBook.getId(), book.getId()); bookList = LitePal.order("id desc").limit(1).find(Book.class); assertEquals(1, bookList.size()); book = bookList.get(0); assertTrue(book.isSaved()); Book lastBook = LitePal.findLast(Book.class); assertTrue(lastBook.isSaved()); assertEquals(lastBook.getBookName(), book.getBookName()); assertEquals(lastBook.getPages(), book.getPages()); assertEquals(lastBook.isPublished(), book.isPublished()); assertEquals(lastBook.getArea(), book.getArea()); assertEquals(lastBook.getPrice(), book.getPrice()); assertEquals(lastBook.getIsbn(), book.getIsbn()); assertEquals(lastBook.getLevel(), book.getLevel()); assertEquals(lastBook.getId(), book.getId()); }
Example 3
Source File: QueryBasicTest.java From LitePal with Apache License 2.0 | 5 votes |
@Test public void testFindLast() { List<Book> expectedBooks = getBooks(null, null, null, null, null, null, null); Book expectedLastBook = expectedBooks.get(expectedBooks.size() - 1); Book realLastBook = LitePal.findLast(Book.class); assertEquals(expectedLastBook.getId(), realLastBook.getId()); assertEquals(expectedLastBook.getBookName(), realLastBook.getBookName()); assertEquals(expectedLastBook.getPages(), realLastBook.getPages()); assertEquals(expectedLastBook.getPrice(), realLastBook.getPrice()); assertEquals(expectedLastBook.getArea(), realLastBook.getArea()); assertEquals(expectedLastBook.getIsbn(), realLastBook.getIsbn()); assertEquals(expectedLastBook.getLevel(), realLastBook.getLevel()); assertEquals(expectedLastBook.isPublished(), realLastBook.isPublished()); assertTrue(realLastBook.isSaved()); }
Example 4
Source File: QueryEagerTest.java From LitePal with Apache License 2.0 | 5 votes |
@Test public void testEagerFindLast() { resetData(); Teacher t1 = LitePal.findLast(Teacher.class); assertEquals(0, t1.getStudents().size()); t1 = LitePal.findLast(Teacher.class, true); assertTrue(0 < t1.getStudents().size()); }
Example 5
Source File: QueryClusterTest.java From LitePal with Apache License 2.0 | 4 votes |
@Test public void testCluster() { long[] ids = new long[3]; for (int i = 0; i < 3; i++) { Book book = new Book(); book.setPages(5555); book.setPublished(true); book.setPrice(40.99); book.save(); ids[i] = book.getId(); } List<Book> books = LitePal .select("pages", "isPublished") .where("id=? or id=? or id=?", String.valueOf(ids[0]), String.valueOf(ids[1]), String.valueOf(ids[2])).order("id").limit(2).offset(1).find(Book.class); Book firstBook = LitePal .select("pages", "isPublished") .where("id=? or id=? or id=?", String.valueOf(ids[0]), String.valueOf(ids[1]), String.valueOf(ids[2])).order("id").limit(2).offset(1).findFirst(Book.class); Book lastBook = LitePal .select("pages", "isPublished") .where("id=? or id=? or id=?", String.valueOf(ids[0]), String.valueOf(ids[1]), String.valueOf(ids[2])).order("id").limit(2).offset(1).findLast(Book.class); assertEquals(2, books.size()); assertTrue(books.get(0).getId() < books.get(1).getId()); for (int i = 0; i < 2; i++) { Book b = books.get(i); assertEquals(ids[i + 1], b.getId()); assertTrue(b.isSaved()); assertNull(b.getBookName()); assertTrue(5555 == b.getPages()); assertEquals(true, b.isPublished()); assertEquals(0f, b.getArea()); assertEquals(0.0, b.getPrice()); assertEquals(0, b.getIsbn()); assertEquals(0, b.getLevel()); if (i == 0) { assertEquals(firstBook.isSaved(), b.isSaved()); assertEquals(firstBook.getBookName(), b.getBookName()); assertEquals(firstBook.getPages(), b.getPages()); assertEquals(firstBook.isPublished(), b.isPublished()); assertEquals(firstBook.getPrice(), b.getPrice()); assertEquals(firstBook.getArea(), b.getArea()); assertEquals(firstBook.getIsbn(), b.getIsbn()); assertEquals(firstBook.getLevel(), b.getLevel()); assertEquals(firstBook.getId(), b.getId()); } if (i == books.size() - 1) { assertEquals(lastBook.isSaved(), b.isSaved()); assertEquals(lastBook.getBookName(), b.getBookName()); assertEquals(lastBook.getPages(), b.getPages()); assertEquals(lastBook.isPublished(), b.isPublished()); assertEquals(lastBook.getPrice(), b.getPrice()); assertEquals(lastBook.getArea(), b.getArea()); assertEquals(lastBook.getIsbn(), b.getIsbn()); assertEquals(lastBook.getLevel(), b.getLevel()); assertEquals(lastBook.getId(), b.getId()); } } Book first1 = LitePal.findFirst(Book.class); Book first2 = LitePal.select("id").findFirst(Book.class); assertEquals(first1.getId(), first2.getId()); Book last1 = LitePal.findLast(Book.class); Book last2 = LitePal.select("id").findLast(Book.class); assertEquals(last1.getId(), last2.getId()); List<Book> firstTwoBooks = LitePal.where("id=? or id=? or id=?", String.valueOf(ids[0]), String.valueOf(ids[1]), String.valueOf(ids[2])).order("id").limit(2).find(Book.class); firstBook = LitePal.where("id=? or id=? or id=?", String.valueOf(ids[0]), String.valueOf(ids[1]), String.valueOf(ids[2])).order("id").limit(2).findFirst(Book.class); lastBook = LitePal.where("id=? or id=? or id=?", String.valueOf(ids[0]), String.valueOf(ids[1]), String.valueOf(ids[2])).order("id").limit(2).findLast(Book.class); assertEquals(firstTwoBooks.get(0).getId(), firstBook.getId()); assertEquals(firstTwoBooks.get(1).getId(), lastBook.getId()); }