Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhaoyufei133
litepal
提交
1dab5919
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 搜索 >>
提交
1dab5919
编写于
9月 12, 2018
作者:
guolin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add registerDatabaseListener() api to listen Database create and upgrade events.
上级
145a6a73
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
115 addition
and
92 deletion
+115
-92
litepal/src/main/java/org/litepal/LitePal.kt
litepal/src/main/java/org/litepal/LitePal.kt
+12
-0
litepal/src/main/java/org/litepal/tablemanager/LitePalOpenHelper.java
...main/java/org/litepal/tablemanager/LitePalOpenHelper.java
+0
-92
litepal/src/main/java/org/litepal/tablemanager/LitePalOpenHelper.kt
...c/main/java/org/litepal/tablemanager/LitePalOpenHelper.kt
+73
-0
litepal/src/main/java/org/litepal/tablemanager/callback/DatabaseListener.java
...a/org/litepal/tablemanager/callback/DatabaseListener.java
+30
-0
未找到文件。
litepal/src/main/java/org/litepal/LitePal.kt
浏览文件 @
1dab5919
...
...
@@ -29,6 +29,7 @@ import org.litepal.exceptions.LitePalSupportException
import
org.litepal.parser.LitePalAttr
import
org.litepal.parser.LitePalParser
import
org.litepal.tablemanager.Connector
import
org.litepal.tablemanager.callback.DatabaseListener
import
org.litepal.util.BaseUtility
import
org.litepal.util.Const
import
org.litepal.util.DBUtility
...
...
@@ -49,6 +50,8 @@ object LitePal {
private
val
handler
=
Handler
(
Looper
.
getMainLooper
())
private
var
dbListener
:
DatabaseListener
?
=
null
/**
* Initialize to make LitePal ready to work. If you didn't configure LitePalApplication
* in the AndroidManifest.xml, make sure you call this method as soon as possible. In
...
...
@@ -1451,4 +1454,13 @@ object LitePal {
return
conditions
!=
null
&&
where
(*
conditions
).
count
(
modelClass
)
>
0
}
/**
* Register a listener to listen database create and upgrade events.
*/
@JvmStatic
fun
registerDatabaseListener
(
listener
:
DatabaseListener
)
{
dbListener
=
listener
}
@JvmStatic
internal
fun
getDBListener
()
=
dbListener
}
\ No newline at end of file
litepal/src/main/java/org/litepal/tablemanager/LitePalOpenHelper.java
已删除
100644 → 0
浏览文件 @
145a6a73
/*
* 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.tablemanager
;
import
android.content.Context
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.database.sqlite.SQLiteDatabase.CursorFactory
;
import
android.database.sqlite.SQLiteOpenHelper
;
import
org.litepal.LitePalApplication
;
import
org.litepal.parser.LitePalAttr
;
import
org.litepal.util.SharedUtil
;
/**
* The database helper to generate and manage the tables. It will automate
* create or upgrade the database file depends on the parameters passed in.
*
* LitePal makes it easy for managing tables. It used the dynamic features of
* Java with reflection API to achieve that. Developers won't need to write
* their own SQL for managing tables, LitePal will do that for them. Developers
* just need to write their model classes and add right associations. LitePal
* will take all the rest job to manager tables in database.
*
* @author Tony Green
* @since 1.0
*/
class
LitePalOpenHelper
extends
SQLiteOpenHelper
{
public
static
final
String
TAG
=
"LitePalHelper"
;
/**
* The standard constructor for SQLiteOpenHelper.
*
* @param context
* To use to open or create the database.
* @param name
* The database file.
* @param factory
* To use for creating cursor objects, or null for the default
* version number of the database (starting at 1); if the
* database is older, onUpgrade.
* @param version
* (SQLiteDatabase, int, int) will be used to upgrade the
* database; if the database is newer,
* onDowngrade(SQLiteDatabase, int, int) will be used to
* downgrade the database
*/
LitePalOpenHelper
(
Context
context
,
String
name
,
CursorFactory
factory
,
int
version
)
{
super
(
context
,
name
,
factory
,
version
);
}
/**
* A simple constructor for SQLiteOpenHelper with null for CursorFactory as
* default.
*
* @param dbName
* The database file.
* @param version
* (SQLiteDatabase, int, int) will be used to upgrade the
* database; if the database is newer,
* onDowngrade(SQLiteDatabase, int, int) will be used to
* downgrade the database
*/
LitePalOpenHelper
(
String
dbName
,
int
version
)
{
this
(
LitePalApplication
.
getContext
(),
dbName
,
null
,
version
);
}
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
{
Generator
.
create
(
db
);
}
@Override
public
void
onUpgrade
(
SQLiteDatabase
db
,
int
oldVersion
,
int
newVersion
)
{
Generator
.
upgrade
(
db
);
SharedUtil
.
updateVersion
(
LitePalAttr
.
getInstance
().
getExtraKeyName
(),
newVersion
);
}
}
litepal/src/main/java/org/litepal/tablemanager/LitePalOpenHelper.kt
0 → 100644
浏览文件 @
1dab5919
package
org.litepal.tablemanager
import
android.content.Context
import
android.database.sqlite.SQLiteDatabase
import
android.database.sqlite.SQLiteOpenHelper
import
org.litepal.LitePal
import
org.litepal.LitePalApplication
import
org.litepal.parser.LitePalAttr
import
org.litepal.util.SharedUtil
/**
* The database helper to generate and manage the tables. It will automate
* create or upgrade the database file depends on the parameters passed in.
*
* LitePal makes it easy for managing tables. It used the dynamic features of
* Java with reflection API to achieve that. Developers won't need to write
* their own SQL for managing tables, LitePal will do that for them. Developers
* just need to write their model classes and add right associations. LitePal
* will take all the rest job to manager tables in database.
*
* @author Tony Green
* @since 1.0
*/
internal
class
LitePalOpenHelper
/**
* The standard constructor for SQLiteOpenHelper.
*
* @param context
* To use to open or create the database.
* @param name
* The database file.
* @param factory
* To use for creating cursor objects, or null for the default
* version number of the database (starting at 1); if the
* database is older, onUpgrade.
* @param version
* (SQLiteDatabase, int, int) will be used to upgrade the
* database; if the database is newer,
* onDowngrade(SQLiteDatabase, int, int) will be used to
* downgrade the database
*/
(
context
:
Context
,
name
:
String
,
factory
:
SQLiteDatabase
.
CursorFactory
?,
version
:
Int
)
:
SQLiteOpenHelper
(
context
,
name
,
factory
,
version
)
{
/**
* A simple constructor for SQLiteOpenHelper with null for CursorFactory as
* default.
*
* @param dbName
* The database file.
* @param version
* (SQLiteDatabase, int, int) will be used to upgrade the
* database; if the database is newer,
* onDowngrade(SQLiteDatabase, int, int) will be used to
* downgrade the database
*/
constructor
(
dbName
:
String
,
version
:
Int
)
:
this
(
LitePalApplication
.
getContext
(),
dbName
,
null
,
version
)
override
fun
onCreate
(
db
:
SQLiteDatabase
)
{
Generator
.
create
(
db
)
LitePal
.
getDBListener
()
?.
onCreate
()
}
override
fun
onUpgrade
(
db
:
SQLiteDatabase
,
oldVersion
:
Int
,
newVersion
:
Int
)
{
Generator
.
upgrade
(
db
)
SharedUtil
.
updateVersion
(
LitePalAttr
.
getInstance
().
extraKeyName
,
newVersion
)
LitePal
.
getDBListener
()
?.
onUpgrade
(
oldVersion
,
newVersion
)
}
companion
object
{
const
val
TAG
=
"LitePalHelper"
}
}
\ No newline at end of file
litepal/src/main/java/org/litepal/tablemanager/callback/DatabaseListener.java
0 → 100644
浏览文件 @
1dab5919
/*
* 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.tablemanager.callback
;
/**
* Callback for listening database create and upgrade events.
* @author Tony Green
* @since 2.0
*/
public
interface
DatabaseListener
{
void
onCreate
();
void
onUpgrade
(
int
oldVersion
,
int
newVersion
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录