5 Star 8 Fork 1

HarmonyOS-TPC / ormlite-ohos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
ISC

ormlite-ohos

This package provides the ohos specific functionality. You will also need to download the ormlite-core package as well. (ormlite-core - Core ORMLite functionality that provides a lite Java ORM in conjunction with ormlite-jdbc or ormlite-ohos)

Usage Instructions


To use the package you add the @DatabaseTable annotation to the top of each class and a @DatabaseField annotation to each of the fields in the class that are to be persisted to the database.Classes can also be configured with javax.persistence annotations (JPA), Java calls, or Spring wiring. For more details, see the on-line documentation. For example:

@DatabaseTable(tableName = "accounts")
public class Account {
    @DatabaseField(id = true)
    private String name;
    
    @DatabaseField(canBeNull = false)
    private String password;
    ...
    Account() {
    	// all persisted classes must define a no-arg constructor with at least package visibility
    }
    ...    
}

Creating Dao

 DBHelper.getInstance(context).getDao(<>.class);

Basic CRUD operations

 try {
 
 //insert
 dao.create(data);
 
 //delete
 dao.deleteById(1);
 
 //update
 dao.update(data);
 
 //query
 UserBean user = dao.queryForId(id);
    
 //List
 usrDao.queryForAll();

} catch (SQLException e) {
    e.printStackTrace();
}

Creating database using OrmLiteAbilitySlice

public class RdbSlice extends OrmLiteAbilitySlice<DBHelper>  {


    @Override
    public Class getRdbOpenHelperClass() {
        return DBHelper.class;
    }
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        view = (ComponentContainer) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_first_layout, null, false);
        setUIContent(view);
    }
    
      @Override
    public void onActive() {
        super.onActive();
        try {
            usrDao = getHelper().getDao(UserBean.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

Supported Features


  • Supports Dao by providing ohos components such as OrmLiteAbilitySlice , OrmLiteRdbOpenHelper
  1. DataBase Connection Source
  2. Dao Creation and CRUD operations
  3. Batch operation

Installation tutorial


ormlite is dependent on ormlite-core.

1.For using Ormlite module in sample app, include the dependent library (ormlite-core - Core ORMLite functionality that provides a lite Java ORM in conjunction with ormlite-jdbc or ormlite-ohos), add below dependencies and include the "ormlite-core.har" in libs folder of "entry" module to generate hap/har or add ormlite-core maven in implementation as below:

Modify entry build.gradle as below :
```
dependencies {
	implementation fileTree(dir: 'libs', include: ['*.har'])
	        implementation group: 'com.j256.ormlite', name: 'ormlite-core', version: '5.3'
	        implementation project(path: ':ormlite')
}
```
  1. For using ormlite in separate application make sure to add the ormlite.har in entry libs folder and add dependent library (ormlite-core - Core ORMLite functionality that provides a lite Java ORM in conjunction with ormlite-jdbc or ormlite-ohos) files as mentioned below

    Modify entry build.gradle as below :

    dependencies {
    	implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
    	implementation group: 'com.j256.ormlite', name: 'ormlite-core', version: '5.3'
    }
  2. For using ormlite from a remote repository in separate application, add the below dependencies and include "ormlite-core.har" in libs folder of "entry" module :

     Modify entry build.gradle as below :
     ```
     dependencies {
         implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
     	implementation group: 'com.j256.ormlite', name: 'ormlite-core', version: '5.3'
         implementation 'io.openharmony.tpc.thirdlib:ormlite-ohos:1.0.1'
     }
ISC License (https://opensource.org/licenses/ISC) Copyright 2019, Gray Watson Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

简介

This package provides the ohos specific functionality 展开 收起
Java
ISC
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/HarmonyOS-tpc/ormlite-ohos.git
git@gitee.com:HarmonyOS-tpc/ormlite-ohos.git
HarmonyOS-tpc
ormlite-ohos
ormlite-ohos
master

搜索帮助

14c37bed 8189591 565d56ea 8189591