提交 f40237df 编写于 作者: G guolindev

Merge remote-tracking branch 'origin/master'

...@@ -22,7 +22,7 @@ Edit your **build.gradle** file and add below dependency. ...@@ -22,7 +22,7 @@ Edit your **build.gradle** file and add below dependency.
``` groovy ``` groovy
dependencies { dependencies {
implementation 'org.litepal.guolindev:core:3.2.1' implementation 'org.litepal.guolindev:core:3.2.2'
} }
``` ```
...@@ -451,9 +451,10 @@ If you find any bug when using LitePal, please report **[here](https://github.co ...@@ -451,9 +451,10 @@ If you find any bug when using LitePal, please report **[here](https://github.co
## Change logs ## Change logs
### 3.2.1 ### 3.2.2
* Support database index by adding @Column(index = true) on field. * Support database index by adding @Column(index = true) on field.
* Adding return value for **runInTransaction()** function for Kotlin. * Adding return value for **runInTransaction()** function for Kotlin.
* Fix known bugs.
### 3.1.1 ### 3.1.1
* Support transaction. * Support transaction.
......
...@@ -28,29 +28,29 @@ dependencies { ...@@ -28,29 +28,29 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
} }
apply plugin: 'com.novoda.bintray-release' //apply plugin: 'com.novoda.bintray-release'
//
allprojects { //allprojects {
tasks.withType(Javadoc) { // tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet') // options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8') // options.addStringOption('encoding', 'UTF-8')
} // }
} //}
//
buildscript { //buildscript {
repositories { // repositories {
jcenter() // jcenter()
} // }
dependencies { // dependencies {
classpath 'com.novoda:bintray-release:0.9.2' // classpath 'com.novoda:bintray-release:0.9.2'
} // }
} //}
//
publish { //publish {
userOrg = 'sinyu890807' // userOrg = 'sinyu890807'
groupId = 'org.litepal.guolindev' // groupId = 'org.litepal.guolindev'
artifactId = 'core' // artifactId = 'core'
publishVersion = '3.2.1' // publishVersion = '3.2.2'
desc = 'An Android library that allows developers to use SQLite database extremely easy' // desc = 'An Android library that allows developers to use SQLite database extremely easy'
website = 'https://github.com/LitePalFramework/LitePal' // website = 'https://github.com/LitePalFramework/LitePal'
} //}
\ No newline at end of file \ No newline at end of file
...@@ -1320,6 +1320,7 @@ abstract class DataHandler extends LitePalBase { ...@@ -1320,6 +1320,7 @@ abstract class DataHandler extends LitePalBase {
private void setToModelByReflection(Object modelInstance, Field field, int columnIndex, String getMethodName, Cursor cursor) private void setToModelByReflection(Object modelInstance, Field field, int columnIndex, String getMethodName, Cursor cursor)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Class<?> cursorClass = cursor.getClass(); Class<?> cursorClass = cursor.getClass();
if (cursor.isNull(columnIndex)) return;
Method method = cursorClass.getMethod(getMethodName, int.class); Method method = cursorClass.getMethod(getMethodName, int.class);
Object value = method.invoke(cursor, columnIndex); Object value = method.invoke(cursor, columnIndex);
if (field.getType() == boolean.class || field.getType() == Boolean.class) { if (field.getType() == boolean.class || field.getType() == Boolean.class) {
......
...@@ -135,7 +135,10 @@ public class LitePalTestCase { ...@@ -135,7 +135,10 @@ public class LitePalTestCase {
do { do {
long id = cursor.getLong(cursor.getColumnIndexOrThrow("id")); long id = cursor.getLong(cursor.getColumnIndexOrThrow("id"));
String bookName = cursor.getString(cursor.getColumnIndexOrThrow("bookname")); String bookName = cursor.getString(cursor.getColumnIndexOrThrow("bookname"));
int pages = cursor.getInt(cursor.getColumnIndexOrThrow("pages")); Integer pages = null;
if (!cursor.isNull(cursor.getColumnIndexOrThrow("pages"))) {
pages = cursor.getInt(cursor.getColumnIndexOrThrow("pages"));
}
double price = cursor.getDouble(cursor.getColumnIndexOrThrow("price")); double price = cursor.getDouble(cursor.getColumnIndexOrThrow("price"));
char level = cursor.getString(cursor.getColumnIndexOrThrow("level")).charAt(0); char level = cursor.getString(cursor.getColumnIndexOrThrow("level")).charAt(0);
short isbn = cursor.getShort(cursor.getColumnIndexOrThrow("isbn")); short isbn = cursor.getShort(cursor.getColumnIndexOrThrow("isbn"));
......
...@@ -96,7 +96,7 @@ class QueryBasicKotlinTest : LitePalTestCase() { ...@@ -96,7 +96,7 @@ class QueryBasicKotlinTest : LitePalTestCase() {
val realBook = realBooks[i] val realBook = realBooks[i]
assertEquals(expectBook.id, realBook.id) assertEquals(expectBook.id, realBook.id)
assertEquals(expectBook.bookName, realBook.bookName) assertEquals(expectBook.bookName, realBook.bookName)
assertEquals(expectBook.pages, realBook.pages) assertEquals(expectBook.pages as Int?, realBook.pages as Int?)
assertEquals(expectBook.price, realBook.price) assertEquals(expectBook.price, realBook.price)
assertEquals(expectBook.area, realBook.area) assertEquals(expectBook.area, realBook.area)
assertEquals(expectBook.isbn, realBook.isbn) assertEquals(expectBook.isbn, realBook.isbn)
...@@ -113,7 +113,7 @@ class QueryBasicKotlinTest : LitePalTestCase() { ...@@ -113,7 +113,7 @@ class QueryBasicKotlinTest : LitePalTestCase() {
val realFirstBook = LitePal.findFirst<Book>() val realFirstBook = LitePal.findFirst<Book>()
assertEquals(expectedFirstBook.id, realFirstBook!!.id) assertEquals(expectedFirstBook.id, realFirstBook!!.id)
assertEquals(expectedFirstBook.bookName, realFirstBook.bookName) assertEquals(expectedFirstBook.bookName, realFirstBook.bookName)
assertEquals(expectedFirstBook.pages, realFirstBook.pages) assertEquals(expectedFirstBook.pages as Int?, realFirstBook.pages as Int?)
assertEquals(expectedFirstBook.price, realFirstBook.price) assertEquals(expectedFirstBook.price, realFirstBook.price)
assertEquals(expectedFirstBook.area, realFirstBook.area) assertEquals(expectedFirstBook.area, realFirstBook.area)
assertEquals(expectedFirstBook.isbn, realFirstBook.isbn) assertEquals(expectedFirstBook.isbn, realFirstBook.isbn)
......
...@@ -114,7 +114,7 @@ class QueryClusterKotlinTest : LitePalTestCase() { ...@@ -114,7 +114,7 @@ class QueryClusterKotlinTest : LitePalTestCase() {
if (i == 0) { if (i == 0) {
assertEquals(firstBook!!.isSaved, book.isSaved) assertEquals(firstBook!!.isSaved, book.isSaved)
assertEquals(firstBook.bookName, book.bookName) assertEquals(firstBook.bookName, book.bookName)
assertEquals(firstBook.pages, book.pages) assertEquals(firstBook.pages as Int?, book.pages as Int?)
assertEquals(firstBook.isPublished, book.isPublished) assertEquals(firstBook.isPublished, book.isPublished)
assertEquals(firstBook.price, book.price) assertEquals(firstBook.price, book.price)
assertEquals(firstBook.area, book.area) assertEquals(firstBook.area, book.area)
...@@ -125,7 +125,7 @@ class QueryClusterKotlinTest : LitePalTestCase() { ...@@ -125,7 +125,7 @@ class QueryClusterKotlinTest : LitePalTestCase() {
if (i == books.size - 1) { if (i == books.size - 1) {
assertEquals(lastBook!!.isSaved, book.isSaved) assertEquals(lastBook!!.isSaved, book.isSaved)
assertEquals(lastBook.bookName, book.bookName) assertEquals(lastBook.bookName, book.bookName)
assertEquals(lastBook.pages, book.pages) assertEquals(lastBook.pages as Int?, book.pages as Int?)
assertEquals(lastBook.isPublished, book.isPublished) assertEquals(lastBook.isPublished, book.isPublished)
assertEquals(lastBook.price, book.price) assertEquals(lastBook.price, book.price)
assertEquals(lastBook.area, book.area) assertEquals(lastBook.area, book.area)
...@@ -148,7 +148,7 @@ class QueryClusterKotlinTest : LitePalTestCase() { ...@@ -148,7 +148,7 @@ class QueryClusterKotlinTest : LitePalTestCase() {
if (i == 0) { if (i == 0) {
assertEquals(inverseFirstBook!!.isSaved, book.isSaved) assertEquals(inverseFirstBook!!.isSaved, book.isSaved)
assertEquals(inverseFirstBook.bookName, book.bookName) assertEquals(inverseFirstBook.bookName, book.bookName)
assertEquals(inverseFirstBook.pages, book.pages) assertEquals(inverseFirstBook.pages as Int?, book.pages as Int?)
assertEquals(inverseFirstBook.isPublished, book.isPublished) assertEquals(inverseFirstBook.isPublished, book.isPublished)
assertEquals(inverseFirstBook.price, book.price) assertEquals(inverseFirstBook.price, book.price)
assertEquals(inverseFirstBook.area, book.area) assertEquals(inverseFirstBook.area, book.area)
...@@ -159,7 +159,7 @@ class QueryClusterKotlinTest : LitePalTestCase() { ...@@ -159,7 +159,7 @@ class QueryClusterKotlinTest : LitePalTestCase() {
if (i == books.size - 1) { if (i == books.size - 1) {
assertEquals(inverseLastBook!!.isSaved, book.isSaved) assertEquals(inverseLastBook!!.isSaved, book.isSaved)
assertEquals(inverseLastBook.bookName, book.bookName) assertEquals(inverseLastBook.bookName, book.bookName)
assertEquals(inverseLastBook.pages, book.pages) assertEquals(inverseLastBook.pages as Int?, book.pages as Int?)
assertEquals(inverseLastBook.isPublished, book.isPublished) assertEquals(inverseLastBook.isPublished, book.isPublished)
assertEquals(inverseLastBook.price, book.price) assertEquals(inverseLastBook.price, book.price)
assertEquals(inverseLastBook.area, book.area) assertEquals(inverseLastBook.area, book.area)
...@@ -179,7 +179,7 @@ class QueryClusterKotlinTest : LitePalTestCase() { ...@@ -179,7 +179,7 @@ class QueryClusterKotlinTest : LitePalTestCase() {
val firstBook = LitePal.findFirst<Book>() val firstBook = LitePal.findFirst<Book>()
assertTrue(firstBook!!.isSaved) assertTrue(firstBook!!.isSaved)
assertEquals(firstBook.bookName, book.bookName) assertEquals(firstBook.bookName, book.bookName)
assertEquals(firstBook.pages, book.pages) assertEquals(firstBook.pages as Int?, book.pages as Int?)
assertEquals(firstBook.isPublished, book.isPublished) assertEquals(firstBook.isPublished, book.isPublished)
assertEquals(firstBook.area, book.area) assertEquals(firstBook.area, book.area)
assertEquals(firstBook.price, book.price) assertEquals(firstBook.price, book.price)
...@@ -193,7 +193,7 @@ class QueryClusterKotlinTest : LitePalTestCase() { ...@@ -193,7 +193,7 @@ class QueryClusterKotlinTest : LitePalTestCase() {
val lastBook = LitePal.findLast(Book::class.java) val lastBook = LitePal.findLast(Book::class.java)
assertTrue(lastBook!!.isSaved) assertTrue(lastBook!!.isSaved)
assertEquals(lastBook.bookName, book.bookName) assertEquals(lastBook.bookName, book.bookName)
assertEquals(lastBook.pages, book.pages) assertEquals(lastBook.pages as Int?, book.pages as Int?)
assertEquals(lastBook.isPublished, book.isPublished) assertEquals(lastBook.isPublished, book.isPublished)
assertEquals(lastBook.area, book.area) assertEquals(lastBook.area, book.area)
assertEquals(lastBook.price, book.price) assertEquals(lastBook.price, book.price)
...@@ -213,7 +213,7 @@ class QueryClusterKotlinTest : LitePalTestCase() { ...@@ -213,7 +213,7 @@ class QueryClusterKotlinTest : LitePalTestCase() {
val expectedBooks = getBooks(null, null, null, null, null, null, null) val expectedBooks = getBooks(null, null, null, null, null, null, null)
val expectedBook = expectedBooks[1] val expectedBook = expectedBooks[1]
assertEquals(expectedBook.bookName, book.bookName) assertEquals(expectedBook.bookName, book.bookName)
assertEquals(expectedBook.pages, book.pages) assertEquals(expectedBook.pages as Int?, book.pages as Int?)
assertEquals(expectedBook.isPublished, book.isPublished) assertEquals(expectedBook.isPublished, book.isPublished)
assertEquals(expectedBook.area, book.area) assertEquals(expectedBook.area, book.area)
assertEquals(expectedBook.price, book.price) assertEquals(expectedBook.price, book.price)
......
...@@ -2,6 +2,7 @@ package com.litepaltest.test.crud.save; ...@@ -2,6 +2,7 @@ package com.litepaltest.test.crud.save;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import com.litepaltest.model.Book;
import com.litepaltest.model.Cellphone; import com.litepaltest.model.Cellphone;
import com.litepaltest.model.Classroom; import com.litepaltest.model.Classroom;
import com.litepaltest.model.Computer; import com.litepaltest.model.Computer;
...@@ -20,6 +21,7 @@ import java.util.ArrayList; ...@@ -20,6 +21,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse; import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNull; import static junit.framework.TestCase.assertNull;
...@@ -245,4 +247,21 @@ public class SaveTest extends LitePalTestCase { ...@@ -245,4 +247,21 @@ public class SaveTest extends LitePalTestCase {
assertEquals(Long.MAX_VALUE, idCardFromDB.getSerial()); assertEquals(Long.MAX_VALUE, idCardFromDB.getSerial());
} }
@Test
public void testNullValue() {
Book book = new Book();
book.setBookName("First Line of Android");
assertTrue(book.save());
Book bookFromDB = LitePal.find(Book.class, book.getId());
assertNotNull(bookFromDB);
assertNull(bookFromDB.getPages()); // pages should be null cause it's Integer type and assign no value.
book.setPages(123); // assign pages
assertTrue(book.save());
bookFromDB = LitePal.find(Book.class, book.getId());
assertNotNull(bookFromDB);
assertNotNull(bookFromDB.getPages()); // now we should be pages value.
assertEquals(Integer.valueOf(123), book.getPages());
}
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册