Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhaoyufei133
litepal
提交
2012918d
L
litepal
项目概览
zhaoyufei133
/
litepal
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
litepal
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2012918d
编写于
5月 20, 2020
作者:
G
guolindev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge java and kotlin extension into core module.
上级
4eba868f
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
1996 addition
and
37 deletion
+1996
-37
.gitignore
.gitignore
+2
-0
build.gradle
build.gradle
+0
-4
core/build.gradle
core/build.gradle
+32
-3
core/src/main/java/org/litepal/LitePal.kt
core/src/main/java/org/litepal/LitePal.kt
+1108
-0
core/src/main/java/org/litepal/extension/FluentQuery.kt
core/src/main/java/org/litepal/extension/FluentQuery.kt
+269
-0
core/src/main/java/org/litepal/extension/LitePal.kt
core/src/main/java/org/litepal/extension/LitePal.kt
+579
-0
core/src/main/java/org/litepal/tablemanager/Connector.java
core/src/main/java/org/litepal/tablemanager/Connector.java
+0
-9
sample/build.gradle
sample/build.gradle
+5
-1
sample/src/androidTest/java/com/litepaltest/test/crud/save/SaveTest.java
...oidTest/java/com/litepaltest/test/crud/save/SaveTest.java
+0
-19
settings.gradle
settings.gradle
+1
-1
未找到文件。
.gitignore
浏览文件 @
2012918d
...
...
@@ -34,3 +34,5 @@ local.properties
*.classpath
*.project
README.md~
/releaseToBintray.txt
build.gradle
浏览文件 @
2012918d
...
...
@@ -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}"
}
}
...
...
core/build.gradle
浏览文件 @
2012918d
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
core/src/main/java/org/litepal/LitePal.kt
0 → 100644
浏览文件 @
2012918d
此差异已折叠。
点击以展开。
core/src/main/java/org/litepal/extension/FluentQuery.kt
0 → 100644
浏览文件 @
2012918d
/*
* 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("name").where("age > ?", "14").order("age").limit(10).offset(2).findFirst<Person>()
*
* 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("name").where("age > ?", "14").order("age").limit(10).offset(2).findLast<Person>()
*
* 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<Person>()
*
* This will count all rows in person table.
*
* You can also specify a where clause when counting.
*
* LitePal.where("age > ?", "15").count<Person>()
*
* @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<Person>("age")
*
* You can also specify a where clause when calculating.
*
* LitePal.where("age > ?", "15").average<Person>("age")
*
* @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<Person, Int>("age")
*
* You can also specify a where clause when calculating.
*
* LitePal.where("age > ?", "15").max<Person, Int>("age")
*
* @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<Int>("person", "age")
*
* You can also specify a where clause when calculating.
*
* LitePal.where("age > ?", "15").max<Int>("person", "age")
*
* @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<Person, Int>("age")
*
* You can also specify a where clause when calculating.
*
* LitePal.where("age > ?", "15").min<Person, Int>("age")
*
* @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<Int>("person", "age")
*
* You can also specify a where clause when calculating.
*
* LitePal.where("age > ?", "15").min<Int>("person", "age")
*
* @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<Person, Int>("age")
*
* You can also specify a where clause when calculating.
*
* LitePal.where("age > ?", "15").sum<Person, Int>("age")
*
* @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<Int>("person", "age")
*
* You can also specify a where clause when calculating.
*
* LitePal.where("age > ?", "15").sum<Int>("person", "age")
*
* @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
core/src/main/java/org/litepal/extension/LitePal.kt
0 → 100644
浏览文件 @
2012918d
此差异已折叠。
点击以展开。
core/src/main/java/org/litepal/tablemanager/Connector.java
浏览文件 @
2012918d
...
...
@@ -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
();
...
...
sample/build.gradle
浏览文件 @
2012918d
...
...
@@ -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'
...
...
sample/src/androidTest/java/com/litepaltest/test/crud/save/SaveTest.java
浏览文件 @
2012918d
...
...
@@ -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
();
...
...
settings.gradle
浏览文件 @
2012918d
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录