Skip to content

build(deps): bump h2 from 2.1.210 to 2.2.220 in /codes/javadb/h2 #33

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codes/javadb/h2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.210</version>
<version>2.2.220</version>
</dependency>
<!-- db end -->
</dependencies>
Expand Down
34 changes: 5 additions & 29 deletions codes/javadb/hbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>${hbase.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
Expand All @@ -40,36 +41,11 @@
<version>1.18.22</version>
</dependency>

<!-- test begin -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.6.3</version>
<scope>test</scope>
</dependency>
<!-- test end -->
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>${hbase.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.github.dunwu</groupId>-->
<!-- <artifactId>dunwu-tool-core</artifactId>-->
<!-- <version>${dunwu.version}</version>-->
<!-- </dependency>-->


<!-- test begin -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- test end -->
</dependencies>
</dependencyManagement>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ public Configuration getConfiguration() {
* @param namespace 命名空间
*/
public void createNamespace(String namespace) throws IOException {
NamespaceDescriptor nd = NamespaceDescriptor.create(namespace).build();
Admin admin = getAdmin();
admin.createNamespace(nd);
admin.close();
Admin admin = null;
try {
admin = getAdmin();
NamespaceDescriptor nd = NamespaceDescriptor.create(namespace).build();
admin.createNamespace(nd);
} finally {
recycle(admin);
}
}

/**
Expand All @@ -113,16 +117,33 @@ public void dropNamespace(String namespace) throws IOException {
* @param force 是否强制删除
*/
public void dropNamespace(String namespace, boolean force) throws IOException {
Admin admin = getAdmin();
if (force) {
TableName[] tableNames = getAdmin().listTableNamesByNamespace(namespace);
for (TableName name : tableNames) {
admin.disableTable(name);
admin.deleteTable(name);
Admin admin = null;
try {
admin = getAdmin();
if (force) {
TableName[] tableNames = admin.listTableNamesByNamespace(namespace);
for (TableName name : tableNames) {
admin.disableTable(name);
admin.deleteTable(name);
}
}
admin.deleteNamespace(namespace);
} finally {
recycle(admin);
}
}

/**
* 获取所有命名空间
*/
public String[] listNamespaces() throws IOException {
Admin admin = null;
try {
admin = getAdmin();
return admin.listNamespaces();
} finally {
recycle(admin);
}
admin.deleteNamespace(namespace);
admin.close();
}

/**
Expand Down Expand Up @@ -212,6 +233,32 @@ public void enableTable(TableName tableName) throws IOException {
admin.close();
}

/**
* 获取所有表
*/
public TableName[] listTableNames() throws IOException {
Admin admin = null;
try {
admin = getAdmin();
return admin.listTableNames();
} finally {
recycle(admin);
}
}

/**
* 获取指定命名空间下的所有表
*/
public TableName[] listTableNamesByNamespace(String namespace) throws IOException {
Admin admin = null;
try {
admin = getAdmin();
return admin.listTableNamesByNamespace(namespace);
} finally {
recycle(admin);
}
}

/**
* 获取 {@link Table} 实例
*
Expand All @@ -231,4 +278,11 @@ public Admin getAdmin() throws IOException {
return getConnection().getAdmin();
}

private void recycle(Admin admin) {
if (null == admin) {
return;
}
IoUtil.close(admin);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,25 @@ protected HBaseHelper(Configuration configuration) throws IOException {
this.connection = ConnectionFactory.createConnection(configuration);
}

protected HBaseHelper(Connection connection) {
this.configuration = connection.getConfiguration();
this.connection = connection;
}

public static synchronized HBaseHelper newInstance(Configuration configuration) throws IOException {
if (configuration == null) {
throw new IllegalArgumentException("configuration can not be null!");
}
return new HBaseHelper(configuration);
}

public synchronized static HBaseHelper newInstance(Connection connection) throws IOException {
if (connection == null) {
throw new IllegalArgumentException("connection can not be null!");
}
return new HBaseHelper(connection);
}

/**
* 关闭内部持有的 HBase Connection 实例
*/
Expand Down Expand Up @@ -555,8 +567,7 @@ public Map<String, Map<String, String>> scanFamilyMap(TableName tableName, Strin
* @return 一级 Map 的 key 是 Row Key;二级 Map 的 key 是列,value 是列值
*/
public Map<String, Map<String, String>> scanFamilyMap(TableName tableName, String family,
Collection<String> columns)
throws Exception {
Collection<String> columns) throws Exception {
HBaseFamilyRequest request = new HBaseFamilyRequest();
request.setFamily(family)
.setColumns(columns)
Expand Down Expand Up @@ -597,8 +608,7 @@ public Map<String, Map<String, String>> scanFamilyMap(TableName tableName, Strin
* @return 一级 Map 的 key 是 Row Key;二级 Map 的 key 是列,value 是列值
*/
public Map<String, Map<String, String>> scanFamilyMap(TableName tableName, String family,
Collection<String> columns,
Filter filter) throws Exception {
Collection<String> columns, Filter filter) throws Exception {
HBaseFamilyRequest request = new HBaseFamilyRequest();
request.setFamily(family)
.setColumns(columns)
Expand Down Expand Up @@ -646,8 +656,7 @@ public Map<String, Map<String, String>> scanFamilyMap(TableName tableName, Strin
* @return 一级 Map 的 key 是 Row Key;二级 Map 的 key 是列,value 是列值
*/
public Map<String, Map<String, String>> scanFamilyMap(TableName tableName, String family,
Collection<String> columns,
long minStamp, long maxStamp, Filter filter) throws Exception {
Collection<String> columns, long minStamp, long maxStamp, Filter filter) throws Exception {
HBaseFamilyRequest request = new HBaseFamilyRequest();
request.setFamily(family)
.setColumns(columns)
Expand Down Expand Up @@ -829,8 +838,8 @@ public PageData<HBaseRowData> pageRowData(HBaseMultiFamilyRequest request) throw
request.getPageNo(), request.getPageSize(), request.toScan());
}

public PageData<HBaseRowData> pageRowData(TableName tableName,
Map<String, Collection<String>> familyColumns, Integer pageNo, Integer pageSize, Scan scan) throws Exception {
public PageData<HBaseRowData> pageRowData(TableName tableName, Map<String, Collection<String>> familyColumns,
Integer pageNo, Integer pageSize, Scan scan) throws Exception {

Table table = getTable(tableName);
Map<String, Map<String, Map<String, String>>> rowMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package io.github.dunwu.javadb.hbase;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ArrayUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.stream.Stream;

/**
* HBase {@link Admin} API 测试例
* <p>
* HBaseAdminHelper 是针对 {@link Admin} 常用 API 的封装工具类
*/
public class HBaseAdminHelperTests {

private static HBaseAdminHelper hbaseAdminHelper = null;

@BeforeAll
public static void init() throws IOException {
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "localhost");
conf.set("hbase.zookeeper.port", "2181");
hbaseAdminHelper = HBaseAdminHelper.newInstance(conf);
}

@AfterAll
public static void destroy() {
IoUtil.close(hbaseAdminHelper);
}

@Test
@DisplayName("创建、删除、查看命名空间")
public void testNamespace() throws IOException {
// 创建命名空间
hbaseAdminHelper.createNamespace("temp");
dumpNamespaces();
// 删除命名空间
hbaseAdminHelper.dropNamespace("temp", true);
dumpNamespaces();
}

private void dumpNamespaces() throws IOException {
String[] namespaces = hbaseAdminHelper.listNamespaces();
System.out.println("命名空间:");
if (ArrayUtil.isNotEmpty(namespaces)) {
Stream.of(namespaces).forEach(System.out::println);
}
}

@Test
@DisplayName("创建、删除、启用、禁用查看表")
public void testTable() throws IOException {
// 创建命名空间
hbaseAdminHelper.createNamespace("temp");
// 创建名为 test 的表,并含有两个列族 d 和 b
hbaseAdminHelper.createTable(TableName.valueOf("temp:test"), "d", "b");
// 查看表
dumpTablesInNamespace("temp");
// 禁用表
hbaseAdminHelper.disableTable(TableName.valueOf("temp:test"));
// 启用表
hbaseAdminHelper.enableTable(TableName.valueOf("temp:test"));
// 删除表
hbaseAdminHelper.dropTable(TableName.valueOf("temp:test"));
// 查看表
dumpTablesInNamespace("temp");
// 删除命名空间
hbaseAdminHelper.dropNamespace("temp", true);
}

private void dumpTablesInNamespace(String namespace) throws IOException {
TableName[] tableNames = hbaseAdminHelper.listTableNamesByNamespace(namespace);
System.out.println("表:");
if (ArrayUtil.isNotEmpty(tableNames)) {
Stream.of(tableNames).forEach(System.out::println);
}
}

}
Loading