RushOrm replaces the need for SQL by mapping java classes to SQL tables.
方式一:
通过library生成har包,添加har包到libs文件夹内
在entry的gradle内添加如下代码
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
方式二:
allprojects{
repositories{
mavenCentral()
}
}
implementation 'io.openharmony.tpc.thirdlib:RushOrm_rushohos:1.0.6'
通过DevEco studio,并下载SDK 将项目中的build.gradle文件中dependencies→classpath版本改为对应的版本(即你的IDE新建项目中所用的版本)
1.
public class Car extends RushObject {
public String color;
public Engine engine;
public String anotherField;
@RushList(classType = Wheel.class)
public List<Wheel> wheels;
public Car(){
/* Empty constructor required */
}
public Car(String color, Engine engine){
this.color = color;
this.engine = engine;
}
}
public class MainAbility extends Ability {
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setMainRoute(MainAbilitySlice.class.getName());
List<Class<? extends Rush>> classes = new ArrayList<>();
classes.add(Car.class);
classes.add(Engine.class);
classes.add(Wheel.class);
OhosInitializeConfig ohosInitializeConfig = new OhosInitializeConfig(getApplicationContext(), classes);
RushOhos.initialize(ohosInitializeConfig);
}
}
2.
Button btnSave = (Button) findComponentById(ResourceTable.Id_btn_save);
Button btnSelect = (Button) findComponentById(ResourceTable.Id_btn_select);
Button btnDel = (Button) findComponentById(ResourceTable.Id_btn_del);
Text tvShow = (Text) findComponentById(ResourceTable.Id_text_show);
//保存
btnSave.setClickedListener(component -> {
final long startTime = System.currentTimeMillis();
final int numberToSave = 100;
List<Car> cars = new ArrayList<>(numberToSave);
for (int i = 0; i < numberToSave; i++) {
Car car = new Car("Red", new Engine());
car.wheels = new ArrayList<>();
for (int j = 0; j < 4; j++) {
car.wheels.add(new Wheel("Michelin"));
}
cars.add(car);
}
RushCore.getInstance().save(cars, () -> {
long endTime = System.currentTimeMillis();
final double saveTime = (endTime - startTime) / 1000.0;
getAbility().getContext().getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
tvShow.setText("保存成功!总耗时:"+String.format("%1$,.2f s", saveTime));
}
});
});
});
//查询
btnSelect.setClickedListener(component -> {
new Thread(() -> {
List<Car> cars = new RushSearch().find(Car.class);
getAbility().getContext().getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
LogUtil.error("test", "Rush main select complete====");
tvShow.setText("查询成功:"+JSON.toJSONString(cars));
}
});
}).start();
});
//删除
btnDel.setClickedListener(component -> new Thread(() -> {
RushCore.getInstance().deleteAll(Car.class);
RushCore.getInstance().deleteAll(Engine.class);
RushCore.getInstance().deleteAll(Wheel.class);
getAbility().getContext().getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
tvShow.setText("删除成功");
}
});
}).start());
Copyright (C) 2015 Stuart Campbell 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.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型