Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task 40: FBbatis:Fisco bcos 预编译合约 + Springboot 的数据库 ORM 框架示例 #3072

Open
wants to merge 1,141 commits into
base: dev-2.0
Choose a base branch
from

Conversation

idefa
Copy link

@idefa idefa commented Nov 2, 2022

fbbatis

FBbatis 是一款针对 Fisco bcos 预编译合约 + Springboot 的数据库 ORM 框架。借鉴于 MyBatis plus 的使用习惯进行开发。

Fisco内置两种表合约说明

FISCO BCOS 2.0受以太坊内置合约启发,实现了一套预编译合约框架,FISCO BCOS平台目前内置两类预编译合约接口,KVTable合约的读写接口和Table合约的CRUD接口。

  • Table的CRUD接口一个key下可以有多条记录,使用时会进行数据批量操作,包括批量写入和范围查询。对应此特性,推荐使用关系型数据库MySQL作为后端数据库。
  • KVTtable的get/set接口时,推荐使用RocksDB作为后端数据库,因RocksDB是Key-Value存储的非关系型数据库,使用KVTable接口时单key操作效率更高

fbbatis操作类说明

fbbatis也提供两种对应的操作,模拟关系型的Table和非关系型的KVTable操作,

  • DataTable类对应Table的CRUD接口,当选择Table类型时候,key就是table的名称,支持增删改查。
  • DataSet类对应KVTtable的get/set接口,当选择KVTable的时候,模拟非关系型数据库操作

sdk配置说明

server:
  servlet:
    context-path: /api/bcos
  port: 8023

sdk:
  corePoolSize: 50
  maxPoolSize: 100
  queueCapacity: 100
  ip: 127.0.0.1 # 节点IP
  channelPort: 20200 # 节点端口
  certPath: conf  # 证书地址

实体映射

@TableName(name = "tb_config",title = "配置表")
@PrimaryKey(name = "name")
@Data
public class ConfigInfo {

    @Column(name = "name",title = "配置名")
    private String name;

    @Column(name = "value",title = "配置值")
    private String value;

    @Column(name = "category",title = "分组")
    private String category;
}

DataTable相关Api

//关系型操作类
public class DataTable<T> {
    // 创建表
    public Object create(int groupId, String fromAddress);
    // 增
    public Object insert(int groupId, String fromAddress,T entity);
    // 改
    public Object update(int groupId,String fromAddress,QueryWrapper<T> queryWrapper,Map<String, Object> columnMap);
    // 删
    public Object remove(int groupId, String fromAddress,QueryWrapper<T> queryWrapper);
    // 查
    public Object select(int groupId,QueryWrapper<T> queryWrapper);
}

DataSet相关Api

//非关系型操作类
public class DataSet<T> {
    // 创建表
    public Object create(int groupId, String fromAddress);
    // 保存实体
    public Object save(int groupId, String fromAddress,T entity)
    // 根据key更新
    public Object updateByKey(int groupId, String fromAddress, String key,Map<String, Object> columnMap);
    // 根据key删除
    public Object removeByKey(int groupId, String fromAddress,String key);
    // 根据key获取
    public Object getByKey(int groupId,String key);
}

测试示例

DataTable测试示例

// 自定义Service
public class PatientService extends DataTable<Patient> {}
//初始化表
paientService.create(1,null);
//新增
Patient patient=new Patient();
//patient.setPhone("")
paientService.insert(1,null,patient);
//查询
QueryWrapper<Patient> patientQuery=new QueryWrapper<Patient>();
patientQuery.eq("patient_name",name);
paientService.select(1,patientQuery);
//删除
QueryWrapper<Patient> patientQuery=new QueryWrapper<Patient>();
patientQuery.eq("patient_name",name);
paientService.remove(1,null,patientQuery);
//修改
QueryWrapper<Patient> patientQuery=new QueryWrapper<Patient>();
patientQuery.eq("patient_name",name);
JSONObject  jsonObject = JSONObject.parseObject("修改的Json体");
Map<String,Object> map = (Map<String,Object>)jsonObject;
paientService.update(1,null,patientQuery,map);

DataSet测试示例

// 自定义Service
public class ConfigService extends DataSet<ConfigInfo>{}
//初始化表
configService.create(1,null);
//保存
ConfigInfo config=new ConfigInfo();
configService.save(1,null,config);
//查询
configService.getByKey(1,key);
//删除
configService.removeByKey(1,null,key);
//更新
JSONObject jsonObject = JSONObject.parseObject(value);
Map<String,Object> map = (Map<String,Object>)jsonObject;
configService.updateByKey(1,null,key,map);

相关资料

morebtcg and others added 30 commits July 31, 2022 00:00
<perf>(shceduler,preconpiled,ledger): perf log, add block number macro log definition.
…xy (FISCO-BCOS#2670)

* add stop for scheduler (FISCO-BCOS#2636)

* modify tars proxy and add tars servant proxy callback

* add _without_tars_framework and tars sevice support create client proxy by endpoints

* update build_chain.py support build tars install package without tars framework

Co-authored-by: XingQiang Bai <bxq2011hust@qq.com>
* remove pbft depends to scheduler

* recover group-signature/ring-signature precompiled

* fix ut for bcos-pbft
<fix&perf>(scheduler,sync,executor): fix smallbank use cachestorage bug, perf scheduler and sync log.
JimmyShi22 and others added 28 commits September 9, 2022 18:04
* Add check-commit && update CI name

* update scripts
…& call return blockNumber (FISCO-BCOS#2834)

Co-authored-by: cyjseagull <yujiechen_hust@163.com>
* only recoverState when the node enableAsMasterNode

* remove build cache from ci
…SCO-BCOS#2854)

* fix every pbftCache owns a timer caused too-many-file opens error

* use fastSM2Crypto
…g logic (FISCO-BCOS#2857)

* Add executor waiting logic

* Update check and clear cache logic

* update shell message

* update executor waiting logic
…-BCOS#2863)

* Bugfix: Clear block cache

* update execute stop logic

* free lock
…SCO-BCOS#2869)

* update log and ci

* fix m_blocks is null bug

* update workflow

* fix dir

* setup jdk
* fix m_blocks empty bug

* tikv off

* update ci check

* use cache file

* add uuid runtime and java

* add distribution

* jdk
* reject message from the outside-group && not access db when txs-missed

* not request the checkPoint far-higher than the committedIndex
* modify timeout for front

* modify thread for tars

* modify install jdk
* only reset masterState to be true when init success

* fix nodeInfo not updated bug
Release 3.0.1 sync code
	deleted:    fbbatis/fbbatis/fbbatis/target/maven-archiver/pom.properties
	deleted:    fbbatis/fbbatis/fbbatis/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
	deleted:    fbbatis/fbbatis/fbbatis/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
	deleted:    fbbatis/fbbatis/fbbatis/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
@idefa idefa changed the title FBbatis:Fisco bcos 预编译合约 + Springboot 的数据库 ORM 框架示例 Task 40: FBbatis:Fisco bcos 预编译合约 + Springboot 的数据库 ORM 框架示例 Nov 2, 2022
QI3PmO2RQ+Te90jWrWv4dOdh5bccSgWISXofwcOTm+aDjUjFd+EEzpdk7TcXZy7Z
/LQEdCH4g9BPR/0Cytf4DK3fLMw3iscxD+5hQWoyfL7I01RVA47hckNU1wsR57bS
6UjIoITMiMTZU9Wn34mz8bQO9rV6lirKCm7W7+7nCDdaCowJWBDG+9hLaDWVxodq
Thn/Zxj3jZcu47DQgpeGs5Ob0gDWFkzr3N4NAgMBAAGjUzBRMB0GA1UdDgQWBBT9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Misspell] "Thn" is a misspelling of "Then" (view)

Rule Correct Incorrect
Then Then Thn

You can close this issue if no need to fix it. Learn more.

auto currentBlockNumber = getCurrentBlockNumber();
if (currentBlockNumber + 1 != requestBlockNumber)
{
// happens in some multi-thread scenario, the block has been commited
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Misspell] "commited" is a misspelling of "committed" (view)

Rule Correct Incorrect
committed committed commited

You can close this issue if no need to fix it. Learn more.


#pragma once

char originBinary[] = "@CMAKE_CURRENT_SOURCE_DIR@/../wasm/infinit_loop.wasm";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Misspell] "infinit" is a misspelling of "infinite" (view)

Rule Correct Incorrect
infinite infinite infinit

You can close this issue if no need to fix it. Learn more.

#pragma once

char originBinary[] = "@CMAKE_CURRENT_SOURCE_DIR@/../wasm/infinit_loop.wasm";
char useGasBinary[] = "@CMAKE_CURRENT_SOURCE_DIR@/../wasm/metric_infinit_loop_useGas.wasm";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Misspell] "infinit" is a misspelling of "infinite" (view)

Rule Correct Incorrect
infinite infinite infinit

You can close this issue if no need to fix it. Learn more.


char originBinary[] = "@CMAKE_CURRENT_SOURCE_DIR@/../wasm/infinit_loop.wasm";
char useGasBinary[] = "@CMAKE_CURRENT_SOURCE_DIR@/../wasm/metric_infinit_loop_useGas.wasm";
char globalGasBinary[] = "@CMAKE_CURRENT_SOURCE_DIR@/../wasm/metric_infinit_loop_global_gas.wasm";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Misspell] "infinit" is a misspelling of "infinite" (view)

Rule Correct Incorrect
infinite infinite infinit

You can close this issue if no need to fix it. Learn more.

@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Secret Scan] It may be dangerous to commit the SSH private key. (view)

Rule Severity
sider.secrets.ssh.private_key warning

You can close this issue if no need to fix it. Learn more.

utilities.log_info("* output dir: " + output_dir)

if os.path.exists(output_dir):
utilities.log_info( output_dir + " already exists, please switch directory or remove it after confirm the directory is no longer in use")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Flake8] whitespace after '(' (view)

Rule
E201

You can close this issue if no need to fix it. Learn more.

from common.utilities import ServiceInfo
import toml
import os
import uuid
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Flake8] 'uuid' imported but unused (view)

Rule
F401

You can close this issue if no need to fix it. Learn more.

from command.node_command_impl import NodeCommandImpl
from command.monitor_command_impl import MonitorCommandImpl
from networkmgr.network_manager import NetworkManager
from controller.node_controller import NodeController
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Flake8] 'controller.node_controller.NodeController' imported but unused (view)

Rule
F401

You can close this issue if no need to fix it. Learn more.

@@ -0,0 +1,394 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import json
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Flake8] 'json' imported but unused (view)

Rule
F401

You can close this issue if no need to fix it. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants