Skip to content

Commit

Permalink
🐛 修复 2.0.1 的一些bug
Browse files Browse the repository at this point in the history
  • Loading branch information
CCweixiao committed Sep 12, 2020
1 parent 84523e3 commit 9e27ecc
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 73 deletions.
2 changes: 1 addition & 1 deletion hbase-manager-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hbase-manager</artifactId>
<groupId>com.leo</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSON;
import com.github.CCweixiao.exception.HBaseOperationsException;
import com.github.CCweixiao.util.StrUtil;
import com.leo.hbase.manager.adaptor.service.IHBaseAdminService;
import com.leo.hbase.manager.adaptor.service.IHBaseService;
Expand All @@ -17,6 +18,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -54,11 +56,14 @@ public String data(ModelMap mmap) {
List<CxSelect> cxTableInfoList = new ArrayList<>(allTableNames.size());

for (String tableName : allTableNames) {
if (ihBaseAdminService.isTableDisabled(tableName)) {
continue;
}
HTableDescriptor tableDescriptor = ihBaseAdminService.getTableDescriptor(tableName);
CxSelect cxSelectTable = new CxSelect();
cxSelectTable.setN(tableName);
cxSelectTable.setV(tableName);

HTableDescriptor tableDescriptor = ihBaseAdminService.getTableDescriptor(tableName);
List<String> families = tableDescriptor.getFamilies().stream().map(HColumnDescriptor::getNameAsString).collect(Collectors.toList());
List<CxSelect> tempFamilyList = new ArrayList<>();
for (String family : families) {
Expand All @@ -83,12 +88,18 @@ public String data(ModelMap mmap) {
@ResponseBody
public TableDataInfo list(SysHbaseTableData sysHbaseTableData) {
List<SysHbaseTableData> list = new ArrayList<>();


if (StrUtil.isBlank(sysHbaseTableData.getTableName())) {
return getDataTable(list);
}

if (ihBaseAdminService.isTableDisabled(sysHbaseTableData.getTableName())) {
throw new HBaseOperationsException("表[" + sysHbaseTableData.getTableName() + "]处于禁用状态,无法被查询!");
}

if (StrUtil.isNotBlank(sysHbaseTableData.getRowKey())) {
//TODO 可以指定列簇
final List<Map<String, Object>> dataMapList = ihBaseService.get(sysHbaseTableData.getTableName(), sysHbaseTableData.getRowKey());
final List<Map<String, Object>> dataMapList = ihBaseService.get(sysHbaseTableData.getTableName(), sysHbaseTableData.getRowKey(), sysHbaseTableData.getFamilyName());
if (dataMapList.isEmpty()) {
return getDataTable(list);
}
Expand All @@ -99,18 +110,13 @@ public TableDataInfo list(SysHbaseTableData sysHbaseTableData) {

return getDataTable(list);
}
int limit = 10;
if (sysHbaseTableData.getLimit() != null && sysHbaseTableData.getLimit() > 0) {
limit = sysHbaseTableData.getLimit();
}
List<List<Map<String, Object>>> dataMaps = ihBaseService.find(sysHbaseTableData.getTableName(), sysHbaseTableData.getFamilyName(), sysHbaseTableData.getStartKey(), limit);
List<List<Map<String, Object>>> dataMaps = ihBaseService.find(sysHbaseTableData.getTableName(), sysHbaseTableData.getFamilyName(), sysHbaseTableData.getStartKey(), sysHbaseTableData.getLimit());
if (dataMaps == null || dataMaps.isEmpty()) {
return getDataTable(list);
}

list = dataMaps.stream().flatMap(Collection::stream).map(dd -> mapToHBaseTableData(sysHbaseTableData.getTableName(), dd)).collect(Collectors.toList());

//startPage();
return getDataTable(list);
}

Expand Down Expand Up @@ -143,8 +149,13 @@ public String add() {
@Log(title = "HBase数据", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(SysHbaseTableData sysHbaseTableData) {
return error("暂不支持新增数据");
public AjaxResult addSave(@Validated SysHbaseTableData sysHbaseTableData) {
String tableName = sysHbaseTableData.getTableName();
if (ihBaseAdminService.isTableDisabled(tableName)) {
throw new HBaseOperationsException("表[" + tableName + "]处于禁用状态!");
}
ihBaseService.saveOrUpdate(tableName, sysHbaseTableData.getRowKey(), sysHbaseTableData.getFamilyName(), sysHbaseTableData.getValue());
return success("数据新增成功!");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
</div>

<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:data:add">
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:data:add" disabled>
<i class="fa fa-plus"></i> 添加
</a>
<a class="btn btn-primary single disabled" onclick="$.operate.edit()"
shiro:hasPermission="system:data:edit">
shiro:hasPermission="system:data:edit" disabled>
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
shiro:hasPermission="system:data:remove">
shiro:hasPermission="system:data:remove" disabled>
<i class="fa fa-remove"></i> 删除
</a>
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:data:export">
Expand Down Expand Up @@ -96,6 +96,7 @@
removeUrl: prefix + "/remove",
exportUrl: prefix + "/export",
modalName: "HBase表数据",
sidePagination: 'client',
columns: [{
checkbox: true
},
Expand All @@ -118,14 +119,21 @@
},
{
field: 'value',
title: '数据值'
title: '数据值',
formatter: function(value, row, index){
if(value.length>20){
return value.substr(0, 20)+"..."
}else{
return value;
}
}
},
{
title: '操作',
align: 'center',
formatter: function (value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.rowKey + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.rowKey + '\') disabled"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.tableName + ',' + row.familyName + "," + row.rowKey + '\')"><i class="fa fa-remove"></i>删除</a>');
return actions.join('');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@
</div>

<div class="btn-group-sm" id="toolbar" role="group">
<!-- <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:family:add">
<i class="fa fa-plus"></i> 添加
</a>-->
<a class="btn btn-primary single disabled" onclick="$.operate.edit()"
shiro:hasPermission="system:family:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
shiro:hasPermission="system:family:remove">
<i class="fa fa-remove"></i> 删除
</a>
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:family:export">
<i class="fa fa-download"></i> 导出
</a>
Expand Down
2 changes: 1 addition & 1 deletion hbase-manager-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hbase-manager</artifactId>
<groupId>com.leo</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hbase-manager-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hbase-manager</artifactId>
<groupId>com.leo</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hbase-manager-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hbase-manager</artifactId>
<groupId>com.leo</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion hbase-manager-hbase/hbase-manager-hbase-1.x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hbase-manager</artifactId>
<groupId>com.leo</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ public interface IHBaseService {
/**
* 根据row key查找数据
*
* @param tableName 表名
* @param rowKey row key
* @param tableName 表名
* @param rowKey row key
* @param familyName 列簇名
* @return 查询数据
*/
List<Map<String, Object>> get(String tableName, String rowKey);
List<Map<String, Object>> get(String tableName, String rowKey, String familyName);


/**
Expand All @@ -38,4 +39,13 @@ public interface IHBaseService {
*/
void delete(String tableName, String rowKey, String familyName, String qualifier);

/**
* 保存数据
* @param tableName 表名
* @param rowKey rowKey
* @param familyAndQualifierName 列簇名
* @param value 值
*/
void saveOrUpdate(String tableName, String rowKey, String familyAndQualifierName, String value);

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.leo.hbase.manager.adaptor.service.impl;

import com.github.CCweixiao.HBaseAdminTemplate;
import com.github.CCweixiao.HBaseTemplate;
import com.github.CCweixiao.RowMapper;
import com.github.CCweixiao.exception.HBaseOperationsException;
import com.github.CCweixiao.util.HBytesUtil;
import com.github.CCweixiao.util.StrUtil;
import com.leo.hbase.manager.adaptor.service.IHBaseService;
Expand All @@ -27,21 +29,19 @@ public class HBaseServiceImpl implements IHBaseService {
private HBaseTemplate hBaseTemplate;

@Override
public List<Map<String, Object>> get(String tableName, String rowKey) {
return hBaseTemplate.get(tableName, rowKey, (result, rowNum) -> {
List<Cell> cs = result.listCells();
List<Map<String, Object>> dataMaps = new ArrayList<>(cs.size());

for (Cell cell : cs) {
Map<String, Object> resultMap = resultToMap(result, cell);
dataMaps.add(resultMap);
}
return dataMaps;
});
public List<Map<String, Object>> get(String tableName, String rowKey, String familyName) {
if (StrUtil.isNotBlank(familyName)) {
return hBaseTemplate.get(tableName, rowKey, familyName, (result, rowNum) -> getToResultMap(result));
}
return hBaseTemplate.get(tableName, rowKey, (result, rowNum) -> getToResultMap(result));
}

@Override
public List<List<Map<String, Object>>> find(String tableName, String familyName, String startKey, Integer limit) {
if (limit == null || limit < 1) {
limit = 1000;
}

Scan scan = new Scan();
if (StrUtil.isNotBlank(familyName)) {
scan.addFamily(Bytes.toBytes(familyName));
Expand All @@ -66,6 +66,13 @@ public void delete(String tableName, String rowKey, String familyName, String qu
hBaseTemplate.delete(tableName, rowKey, familyName, qualifier);
}

@Override
public void saveOrUpdate(String tableName, String rowKey, String familyAndQualifierName, String value) {
Map<String, Object> data = new HashMap<>(1);
data.put(familyAndQualifierName, value);
hBaseTemplate.save(tableName, rowKey, data);
}

private Map<String, Object> resultToMap(Result result, Cell cell) {
Map<String, Object> resultMap = new HashMap<>(4);
String fieldName = Bytes.toString(CellUtil.cloneFamily(cell)) + ":" + Bytes.toString(CellUtil.cloneQualifier(cell));
Expand All @@ -76,4 +83,15 @@ private Map<String, Object> resultToMap(Result result, Cell cell) {
resultMap.put("value", HBytesUtil.toObject(value, Object.class));
return resultMap;
}

private List<Map<String, Object>> getToResultMap(Result result) {
List<Cell> cs = result.listCells();
List<Map<String, Object>> dataMaps = new ArrayList<>(cs.size());

for (Cell cell : cs) {
Map<String, Object> resultMap = resultToMap(result, cell);
dataMaps.add(resultMap);
}
return dataMaps;
}
}
2 changes: 1 addition & 1 deletion hbase-manager-hbase/hbase-manager-hbase-2.x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>hbase-manager</artifactId>
<groupId>com.leo</groupId>
<version>2.0.1</version>
<version>2.0.2</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ public interface IHBaseService {
/**
* 根据row key查找数据
*
* @param tableName 表名
* @param rowKey row key
* @param tableName 表名
* @param rowKey row key
* @param familyName 列簇名
* @return 查询数据
*/
List<Map<String, Object>> get(String tableName, String rowKey);
List<Map<String, Object>> get(String tableName, String rowKey, String familyName);


/**
Expand All @@ -37,4 +38,13 @@ public interface IHBaseService {
* @param qualifier 字段名
*/
void delete(String tableName, String rowKey, String familyName, String qualifier);

/**
* 保存数据
* @param tableName 表名
* @param rowKey rowKey
* @param familyAndQualifierName 列簇名
* @param value 值
*/
void saveOrUpdate(String tableName, String rowKey, String familyAndQualifierName, String value);
}
Loading

0 comments on commit 9e27ecc

Please sign in to comment.