提交 2012918d 编写于 作者: G guolindev

Merge java and kotlin extension into core module.

上级 4eba868f
......@@ -34,3 +34,5 @@ local.properties
*.classpath
*.project
README.md~
/releaseToBintray.txt
......@@ -2,7 +2,6 @@
buildscript {
ext.kotlin_version = '1.3.72'
ext.dokka_version = '0.9.15'
repositories {
google()
jcenter()
......@@ -10,9 +9,6 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:${dokka_version}"
}
}
......
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
......@@ -8,6 +10,7 @@ android {
targetSdkVersion 28
versionCode 1
versionName "1.0"
archivesBaseName = "core"
}
buildTypes {
release {
......@@ -15,13 +18,39 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api 'com.android.support:appcompat-v7:28.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
apply plugin: 'com.novoda.bintray-release'
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.novoda:bintray-release:0.9.1'
}
}
if (hasProperty("BINTRAY_KEY")) {
apply from: 'bintray.gradle'
publish {
userOrg = 'sinyu890807'
groupId = 'org.litepal.guolindev'
artifactId = 'core'
publishVersion = '3.0.1'
desc = 'An Android library that allows developers to use SQLite database extremely easy'
website = 'https://github.com/LitePalFramework/LitePal'
}
\ No newline at end of file
此差异已折叠。
/*
* Copyright (C) Tony Green, LitePal Framework Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.litepal.extension
import org.litepal.FluentQuery
import org.litepal.crud.async.FindExecutor
/**
* Extension of FluentQuery class for Kotlin api.
* @author Tony Green
* @since 2.1
*/
/**
* Finds multiple records by the cluster parameters. You can use the below
* way to finish a complicated query:
*
* LitePal.select("name").where("age > ?", "14").order("age").limit(1).offset(2).find<Person>()
*
* You can also do the same job with SQLiteDatabase like this:
*
* getSQLiteDatabase().query("Person", "name", "age > ?", new String[] { "14" }, null, null, "age",
* "2,1")
*
* Obviously, the first way is much more semantic.<br>
* Note that the associated models won't be loaded by default considering
* the efficiency, but you can do that by using
* {@link FluentQuery#find(Class, boolean)}.
*
* @return An object list with founded data from database, or an empty list.
*/
inline fun <reified T> FluentQuery.find(): List<T> = find(T::class.java)
/**
* Basically same as {@link #find(Class)} but pending to a new thread for executing.
*
* @return A FindMultiExecutor instance.
*/
inline fun <reified T> FluentQuery.findAsync() = findAsync(T::class.java)
/**
* It is mostly same as {@link FluentQuery#find(Class)} but an isEager
* parameter. If set true the associated models will be loaded as well.
*
* Note that isEager will only work for one deep level relation, considering the query efficiency.
* You have to implement on your own if you need to load multiple deepness of relation at once.
*
* @param isEager
* True to load the associated models, false not.
* @return An object list with founded data from database, or an empty list.
*/
inline fun <reified T> FluentQuery.find(isEager: Boolean): List<T> = find(T::class.java, isEager)
/**
* Basically same as {@link #find(Class, boolean)} but pending to a new thread for executing.
*
* @param isEager
* True to load the associated models, false not.
* @return A FindMultiExecutor instance.
*/
inline fun <reified T> FluentQuery.findAsync(isEager: Boolean) = findAsync(T::class.java, isEager)
/**
* Finds the first record by the cluster parameters. You can use the below
* way to finish a complicated query:
*
* LitePal.select(&quot;name&quot;).where(&quot;age &gt; ?&quot;, &quot;14&quot;).order(&quot;age&quot;).limit(10).offset(2).findFirst&lt;Person&gt;()
*
* Note that the associated models won't be loaded by default considering
* the efficiency, but you can do that by using
* {@link FluentQuery#findFirst(Class, boolean)}.
*
* @return An object with founded data from database, or null.
*/
inline fun <reified T> FluentQuery.findFirst(): T? = findFirst(T::class.java)
/**
* Basically same as {@link #findFirst(Class)} but pending to a new thread for executing.
*
* @return A FindExecutor instance.
*/
inline fun <reified T> FluentQuery.findFirstAsync(): FindExecutor<T> = findFirstAsync(T::class.java)
/**
* It is mostly same as {@link FluentQuery#findFirst(Class)} but an isEager
* parameter. If set true the associated models will be loaded as well.
*
* Note that isEager will only work for one deep level relation, considering the query efficiency.
* You have to implement on your own if you need to load multiple deepness of relation at once.
*
* @param isEager
* True to load the associated models, false not.
* @return An object with founded data from database, or null.
*/
inline fun <reified T> FluentQuery.findFirst(isEager: Boolean): T? = findFirst(T::class.java, isEager)
/**
* Finds the last record by the cluster parameters. You can use the below
* way to finish a complicated query:
*
* LitePal.select(&quot;name&quot;).where(&quot;age &gt; ?&quot;, &quot;14&quot;).order(&quot;age&quot;).limit(10).offset(2).findLast&lt;Person&gt;()
*
* Note that the associated models won't be loaded by default considering
* the efficiency, but you can do that by using
* {@link FluentQuery#findLast(Class, boolean)}.
*
* @return An object with founded data from database, or null.
*/
inline fun <reified T> FluentQuery.findLast(): T? = findLast(T::class.java)
/**
* It is mostly same as {@link FluentQuery#findLast(Class)} but an isEager
* parameter. If set true the associated models will be loaded as well.
*
* Note that isEager will only work for one deep level relation, considering the query efficiency.
* You have to implement on your own if you need to load multiple deepness of relation at once.
*
* @param isEager
* True to load the associated models, false not.
* @return An object with founded data from database, or null.
*/
inline fun <reified T> FluentQuery.findLast(isEager: Boolean): T? = findLast(T::class.java, isEager)
/**
* Count the records.
*
* LitePal.count&lt;Person&gt;()
*
* This will count all rows in person table.
*
* You can also specify a where clause when counting.
*
* LitePal.where(&quot;age &gt; ?&quot;, &quot;15&quot;).count&lt;Person&gt;()
*
* @return Count of the specified table.
*/
inline fun <reified T> FluentQuery.count() = count(T::class.java)
/**
* Calculates the average value on a given column.
*
* LitePal.average&lt;Person&gt;(&quot;age&quot;)
*
* You can also specify a where clause when calculating.
*
* LitePal.where(&quot;age &gt; ?&quot;, &quot;15&quot;).average&lt;Person&gt;(&quot;age&quot;)
*
* @param column
* The based on column to calculate.
* @return The average value on a given column.
*/
inline fun <reified T> FluentQuery.average(column: String) = average(T::class.java, column)
/**
* Calculates the maximum value on a given column. The value is returned
* with the same data type of the column.
*
* LitePal.max&lt;Person, Int&gt;(&quot;age&quot;)
*
* You can also specify a where clause when calculating.
*
* LitePal.where(&quot;age &gt; ?&quot;, &quot;15&quot;).max&lt;Person, Int&gt;(&quot;age&quot;)
*
* @param columnName
* The based on column to calculate.
*
* @return The maximum value on a given column.
*/
inline fun <reified T, reified R> FluentQuery.max(columnName: String): R = max(T::class.java, columnName, R::class.java)
/**
* Calculates the maximum value on a given column. The value is returned
* with the same data type of the column.
*
* LitePal.max&lt;Int&gt;(&quot;person&quot;, &quot;age&quot;)
*
* You can also specify a where clause when calculating.
*
* LitePal.where(&quot;age &gt; ?&quot;, &quot;15&quot;).max&lt;Int&gt;(&quot;person&quot;, &quot;age&quot;)
*
* @param tableName
* Which table to query from.
* @param columnName
* The based on column to calculate.
* @return The maximum value on a given column.
*/
inline fun <reified R> FluentQuery.max(tableName: String, columnName: String): R = max(tableName, columnName, R::class.java)
/**
* Calculates the minimum value on a given column. The value is returned
* with the same data type of the column.
*
* LitePal.min&lt;Person, Int&gt;(&quot;age&quot;)
*
* You can also specify a where clause when calculating.
*
* LitePal.where(&quot;age &gt; ?&quot;, &quot;15&quot;).min&lt;Person, Int&gt;(&quot;age&quot;)
*
* @param columnName
* The based on column to calculate.
* @return The minimum value on a given column.
*/
inline fun <reified T, reified R> FluentQuery.min(columnName: String): R = min(T::class.java, columnName, R::class.java)
/**
* Calculates the minimum value on a given column. The value is returned
* with the same data type of the column.
*
* LitePal.min&lt;Int&gt;(&quot;person&quot;, &quot;age&quot;)
*
* You can also specify a where clause when calculating.
*
* LitePal.where(&quot;age &gt; ?&quot;, &quot;15&quot;).min&lt;Int&gt;(&quot;person&quot;, &quot;age&quot;)
*
* @param tableName
* Which table to query from.
* @param columnName
* The based on column to calculate.
* @return The minimum value on a given column.
*/
inline fun <reified R> FluentQuery.min(tableName: String, columnName: String): R = min(tableName, columnName, R::class.java)
/**
* Calculates the sum of values on a given column. The value is returned
* with the same data type of the column.
*
* LitePal.sum&lt;Person, Int&gt;(&quot;age&quot;)
*
* You can also specify a where clause when calculating.
*
* LitePal.where(&quot;age &gt; ?&quot;, &quot;15&quot;).sum&lt;Person, Int&gt;(&quot;age&quot;)
*
* @param columnName
* The based on column to calculate.
* @return The sum value on a given column.
*/
inline fun <reified T, reified R> FluentQuery.sum(columnName: String): R = sum(T::class.java, columnName, R::class.java)
/**
* Calculates the sum of values on a given column. The value is returned
* with the same data type of the column.
*
* LitePal.sum&lt;Int&gt;(&quot;person&quot;, &quot;age&quot;)
*
* You can also specify a where clause when calculating.
*
* LitePal.where(&quot;age &gt; ?&quot;, &quot;15&quot;).sum&lt;Int&gt;(&quot;person&quot;, &quot;age&quot;)
*
* @param tableName
* Which table to query from.
* @param columnName
* The based on column to calculate.
* @return The sum value on a given column.
*/
inline fun <reified R> FluentQuery.sum(tableName: String, columnName: String): R = sum(tableName, columnName, R::class.java)
\ No newline at end of file
此差异已折叠。
......@@ -16,17 +16,12 @@
package org.litepal.tablemanager;
import android.Manifest;
import android.content.pm.PackageManager;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import org.litepal.LitePalApplication;
import org.litepal.exceptions.DatabaseGenerateException;
import org.litepal.parser.LitePalAttr;
import org.litepal.util.BaseUtility;
import java.io.File;
......@@ -99,10 +94,6 @@ public class Connector {
// internal or empty means internal storage, neither or them means sdcard storage
String dbPath = Environment.getExternalStorageDirectory().getPath() + "/" + litePalAttr.getStorage();
dbPath = dbPath.replace("//", "/");
if (BaseUtility.isClassAndMethodExist("android.support.v4.content.ContextCompat", "checkSelfPermission") &&
ContextCompat.checkSelfPermission(LitePalApplication.getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
throw new DatabaseGenerateException(String.format(DatabaseGenerateException.EXTERNAL_STORAGE_PERMISSION_DENIED, dbPath));
}
File path = new File(dbPath);
if (!path.exists()) {
path.mkdirs();
......
......@@ -19,12 +19,16 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':kotlin')
implementation project(':core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
......
......@@ -161,25 +161,6 @@ public class SaveTest extends LitePalTestCase {
}
}
@Test
public void testSaveIfExists() {
String serial = UUID.randomUUID().toString();
Cellphone cell = new Cellphone();
cell.setBrand("iPhone");
cell.setPrice(4998.01);
cell.setInStock('Y');
cell.setSerial(serial);
assertTrue(cell.saveIfNotExist("serial = ?", serial));
Cellphone cell2 = new Cellphone();
cell2.setBrand("Android");
cell2.setPrice(1998.01);
cell2.setInStock('Y');
cell2.setSerial(serial);
assertFalse(cell.saveIfNotExist("serial = ?", serial));
List<Cellphone> cellphoneList = LitePal.where("serial = ?", serial).find(Cellphone.class);
assertEquals(1, cellphoneList.size());
}
@Test
public void testSaveInheritModels() {
WeChatMessage weChatMessage = new WeChatMessage();
......
include 'sample', 'core', 'java', 'kotlin'
\ No newline at end of file
include 'sample', 'core'
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册