Skip to content

Commit 25d9f5c

Browse files
committed
format codes
1 parent dbf1cd4 commit 25d9f5c

49 files changed

Lines changed: 11116 additions & 10699 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

codes/javadb/javadb-h2/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
2-
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3-
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.github.dunwu</groupId>
66
<artifactId>javadb-h2</artifactId>
Lines changed: 78 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,94 @@
11
package io.github.dunwu.javadb;
22

3-
import java.sql.*;
4-
import java.util.UUID;
53
import org.junit.AfterClass;
64
import org.junit.Assert;
75
import org.junit.BeforeClass;
86
import org.junit.Test;
97

8+
import java.util.UUID;
9+
1010
@SuppressWarnings("all")
1111
public class H2JdbcTest01 {
1212

13-
// 数据库连接 URL,当前连接的是 C:\Users\Administrator 目录下的 test 数据库(连用户目录下的 test 数据库)
14-
private static final String JDBC_URL = "jdbc:h2:~/test";
15-
// 数据库连接 URL,当前连接的是 D:\Tools\h2-2018-03-18\data 目录下的 test 数据库
16-
private static final String JDBC_URL2 = "jdbc:h2:D:\\Tools\\h2-2018-03-18\\data\\test";
17-
// TCP 连接方式和其他数据库类似,是基于服务的形式进行连接,因此允许多个客户端同时连接到 H2 数据库
18-
private static final String JDBC_URL3 = "jdbc:h2:tcp://localhost/~/test";
13+
// 数据库连接 URL,当前连接的是 C:\Users\Administrator 目录下的 test 数据库(连用户目录下的 test 数据库)
14+
private static final String JDBC_URL = "jdbc:h2:~/test";
15+
16+
// 数据库连接 URL,当前连接的是 D:\Tools\h2-2018-03-18\data 目录下的 test 数据库
17+
private static final String JDBC_URL2 = "jdbc:h2:D:\\Tools\\h2-2018-03-18\\data\\test";
18+
19+
// TCP 连接方式和其他数据库类似,是基于服务的形式进行连接,因此允许多个客户端同时连接到 H2 数据库
20+
private static final String JDBC_URL3 = "jdbc:h2:tcp://localhost/~/test";
21+
22+
// 连接数据库时使用的用户名
23+
private static final String USER = "sa";
24+
25+
// 连接数据库时使用的密码
26+
private static final String PASSWORD = "";
27+
28+
// 连接H2数据库时使用的驱动类,org.h2.Driver 这个类是由 H2 数据库自己提供的,在 H2 数据库的 jar 包中可以找到
29+
private static final String DRIVER_CLASS = "org.h2.Driver";
30+
31+
private static Connection CONNECTION = null;
1932

20-
// 连接数据库时使用的用户名
21-
private static final String USER = "sa";
22-
// 连接数据库时使用的密码
23-
private static final String PASSWORD = "";
24-
// 连接H2数据库时使用的驱动类,org.h2.Driver 这个类是由 H2 数据库自己提供的,在 H2 数据库的 jar 包中可以找到
25-
private static final String DRIVER_CLASS = "org.h2.Driver";
33+
private static Statement STATEMENT = null;
2634

27-
private static Connection CONNECTION = null;
28-
private static Statement STATEMENT = null;
35+
@BeforeClass
36+
public static void beforeClass() {
37+
try {
38+
// 加载H2数据库驱动
39+
Class.forName(DRIVER_CLASS);
40+
// 根据连接URL,用户名,密码获取数据库连接(体会下不同 URL 连接的不同之处)
41+
// CONNECTION = DriverManager.getConnection(JDBC_URL, USER, PASSWORD);
42+
// CONNECTION = DriverManager.getConnection(JDBC_URL2, USER, PASSWORD);
43+
CONNECTION = DriverManager.getConnection(JDBC_URL3, USER, PASSWORD);
44+
// 创建sql声明
45+
STATEMENT = CONNECTION.createStatement();
46+
}
47+
catch (ClassNotFoundException | SQLException e) {
48+
e.printStackTrace();
49+
}
50+
}
2951

30-
@BeforeClass
31-
public static void beforeClass() {
32-
try {
33-
// 加载H2数据库驱动
34-
Class.forName(DRIVER_CLASS);
35-
// 根据连接URL,用户名,密码获取数据库连接(体会下不同 URL 连接的不同之处)
36-
// CONNECTION = DriverManager.getConnection(JDBC_URL, USER, PASSWORD);
37-
// CONNECTION = DriverManager.getConnection(JDBC_URL2, USER, PASSWORD);
38-
CONNECTION = DriverManager.getConnection(JDBC_URL3, USER, PASSWORD);
39-
// 创建sql声明
40-
STATEMENT = CONNECTION.createStatement();
41-
} catch (ClassNotFoundException | SQLException e) {
42-
e.printStackTrace();
43-
}
44-
}
52+
@AfterClass
53+
public static void afterClass() {
54+
try {
55+
// 释放资源
56+
STATEMENT.close();
57+
// 关闭连接
58+
CONNECTION.close();
59+
}
60+
catch (SQLException e) {
61+
e.printStackTrace();
62+
}
63+
}
4564

46-
@AfterClass
47-
public static void afterClass() {
48-
try {
49-
// 释放资源
50-
STATEMENT.close();
51-
// 关闭连接
52-
CONNECTION.close();
53-
} catch (SQLException e) {
54-
e.printStackTrace();
55-
}
56-
}
65+
@Test
66+
public void test() {
67+
try {
68+
// 如果存在USER_INFO表就先删除USER_INFO表
69+
STATEMENT.execute("DROP TABLE IF EXISTS USER_INFO");
70+
// 创建USER_INFO表
71+
STATEMENT.execute("CREATE TABLE USER_INFO(id VARCHAR(36) PRIMARY KEY,name VARCHAR(100),sex VARCHAR(4))");
72+
// 新增
73+
STATEMENT.executeUpdate("INSERT INTO USER_INFO VALUES('" + UUID.randomUUID() + "','带头大哥','男')");
74+
STATEMENT.executeUpdate("INSERT INTO USER_INFO VALUES('" + UUID.randomUUID() + "','萧峰','男')");
75+
STATEMENT.executeUpdate("INSERT INTO USER_INFO VALUES('" + UUID.randomUUID() + "','段誉','男')");
76+
STATEMENT.executeUpdate("INSERT INTO USER_INFO VALUES('" + UUID.randomUUID() + "','虚竹','男')");
77+
STATEMENT.executeUpdate("INSERT INTO USER_INFO VALUES('" + UUID.randomUUID() + "','王语嫣','女')");
78+
// 删除
79+
STATEMENT.executeUpdate("DELETE FROM USER_INFO WHERE name='带头大哥'");
80+
// 修改
81+
STATEMENT.executeUpdate("UPDATE USER_INFO SET name='大轮明王' WHERE name='鸠摩智'");
82+
// 查询
83+
ResultSet rs = STATEMENT.executeQuery("SELECT * FROM USER_INFO");
84+
// 遍历结果集
85+
while (rs.next()) {
86+
System.out.println(rs.getString("id") + "," + rs.getString("name") + "," + rs.getString("sex"));
87+
}
88+
}
89+
catch (SQLException e) {
90+
Assert.assertTrue(e.getMessage(), true);
91+
}
92+
}
5793

58-
@Test
59-
public void test() {
60-
try {
61-
// 如果存在USER_INFO表就先删除USER_INFO表
62-
STATEMENT.execute("DROP TABLE IF EXISTS USER_INFO");
63-
// 创建USER_INFO表
64-
STATEMENT.execute(
65-
"CREATE TABLE USER_INFO(id VARCHAR(36) PRIMARY KEY,name VARCHAR(100),sex VARCHAR(4))");
66-
// 新增
67-
STATEMENT.executeUpdate(
68-
"INSERT INTO USER_INFO VALUES('" + UUID.randomUUID() + "','带头大哥','男')");
69-
STATEMENT.executeUpdate(
70-
"INSERT INTO USER_INFO VALUES('" + UUID.randomUUID() + "','萧峰','男')");
71-
STATEMENT.executeUpdate(
72-
"INSERT INTO USER_INFO VALUES('" + UUID.randomUUID() + "','段誉','男')");
73-
STATEMENT.executeUpdate(
74-
"INSERT INTO USER_INFO VALUES('" + UUID.randomUUID() + "','虚竹','男')");
75-
STATEMENT.executeUpdate(
76-
"INSERT INTO USER_INFO VALUES('" + UUID.randomUUID() + "','王语嫣','女')");
77-
// 删除
78-
STATEMENT.executeUpdate("DELETE FROM USER_INFO WHERE name='带头大哥'");
79-
// 修改
80-
STATEMENT.executeUpdate("UPDATE USER_INFO SET name='大轮明王' WHERE name='鸠摩智'");
81-
// 查询
82-
ResultSet rs = STATEMENT.executeQuery("SELECT * FROM USER_INFO");
83-
// 遍历结果集
84-
while (rs.next()) {
85-
System.out.println(rs.getString("id") + "," + rs.getString("name") + ","
86-
+ rs.getString("sex"));
87-
}
88-
} catch (SQLException e) {
89-
Assert.assertTrue(e.getMessage(), true);
90-
}
91-
}
9294
}

codes/javadb/javadb-hbase/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
2-
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3-
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.github.dunwu</groupId>
66
<artifactId>javadb-hbase</artifactId>
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
package io.github.dunwu.javadb;
22

33
public enum HBaseConstant {
4-
HBASE_ZOOKEEPER_QUORUM("hbase.zookeeper.quorum"),
5-
HBASE_ENABLE("hbase.enable"),
6-
HBASE_MASTER("hbase.master"),
7-
HBASE_ZOOKEEPER_PROPERTY_CLIENTPORT("hbase.zookeeper.property.clientPort"),
8-
HBASE_HCONNECTION_THREADS_MAX("hbase.hconnection.threads.max"),
9-
HBASE_HCONNECTION_THREADS_CORE("hbase.hconnection.threads.core"),
10-
ZOOKEEPER_ZNODE_PARENT("zookeeper.znode.parent"),
11-
HBASE_COLUMN_FAMILY("hbase.column.family"),
12-
HBASE_EXECUTOR_NUM("hbase.executor.num"),
13-
HBASE_IPC_POOL_SIZE("hbase.client.ipc.pool.size");
144

15-
private String key;
5+
HBASE_ZOOKEEPER_QUORUM("hbase.zookeeper.quorum"), HBASE_ENABLE("hbase.enable"), HBASE_MASTER(
6+
"hbase.master"), HBASE_ZOOKEEPER_PROPERTY_CLIENTPORT(
7+
"hbase.zookeeper.property.clientPort"), HBASE_HCONNECTION_THREADS_MAX(
8+
"hbase.hconnection.threads.max"), HBASE_HCONNECTION_THREADS_CORE(
9+
"hbase.hconnection.threads.core"), ZOOKEEPER_ZNODE_PARENT(
10+
"zookeeper.znode.parent"), HBASE_COLUMN_FAMILY(
11+
"hbase.column.family"), HBASE_EXECUTOR_NUM(
12+
"hbase.executor.num"), HBASE_IPC_POOL_SIZE(
13+
"hbase.client.ipc.pool.size");
1614

17-
HBaseConstant(String key) {
18-
this.key = key;
19-
}
15+
private String key;
16+
17+
HBaseConstant(String key) {
18+
this.key = key;
19+
}
20+
21+
public String key() {
22+
return key;
23+
}
2024

21-
public String key() {
22-
return key;
23-
}
2425
}

codes/javadb/javadb-hbase/src/main/java/io/github/dunwu/javadb/HbaseCellEntity.java

Lines changed: 75 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,79 @@
77
* @date 2019-03-04
88
*/
99
public class HbaseCellEntity {
10-
private String table;
11-
private String row;
12-
private String colFamily;
13-
private String col;
14-
private String val;
15-
16-
public HbaseCellEntity() {}
17-
18-
public HbaseCellEntity(String row, String colFamily, String col, String val) {
19-
this.row = row;
20-
this.colFamily = colFamily;
21-
this.col = col;
22-
this.val = val;
23-
}
24-
25-
public HbaseCellEntity(String table, String row, String colFamily, String col, String val) {
26-
this.table = table;
27-
this.row = row;
28-
this.colFamily = colFamily;
29-
this.col = col;
30-
this.val = val;
31-
}
32-
33-
public String getTable() {
34-
return table;
35-
}
36-
37-
public void setTable(String table) {
38-
this.table = table;
39-
}
40-
41-
public String getRow() {
42-
return row;
43-
}
44-
45-
public void setRow(String row) {
46-
this.row = row;
47-
}
48-
49-
public String getColFamily() {
50-
return colFamily;
51-
}
52-
53-
public void setColFamily(String colFamily) {
54-
this.colFamily = colFamily;
55-
}
56-
57-
public String getCol() {
58-
return col;
59-
}
60-
61-
public void setCol(String col) {
62-
this.col = col;
63-
}
64-
65-
public String getVal() {
66-
return val;
67-
}
68-
69-
public void setVal(String val) {
70-
this.val = val;
71-
}
72-
73-
@Override
74-
public String toString() {
75-
return "HbaseCellEntity{" + "table='" + table + '\'' + ", row='" + row + '\'' + ", colFamily='" + colFamily
76-
+ '\'' + ", col='" + col + '\'' + ", val='" + val + '\'' + '}';
77-
}
10+
11+
private String table;
12+
13+
private String row;
14+
15+
private String colFamily;
16+
17+
private String col;
18+
19+
private String val;
20+
21+
public HbaseCellEntity() {
22+
}
23+
24+
public HbaseCellEntity(String row, String colFamily, String col, String val) {
25+
this.row = row;
26+
this.colFamily = colFamily;
27+
this.col = col;
28+
this.val = val;
29+
}
30+
31+
public HbaseCellEntity(String table, String row, String colFamily, String col, String val) {
32+
this.table = table;
33+
this.row = row;
34+
this.colFamily = colFamily;
35+
this.col = col;
36+
this.val = val;
37+
}
38+
39+
public String getTable() {
40+
return table;
41+
}
42+
43+
public void setTable(String table) {
44+
this.table = table;
45+
}
46+
47+
public String getRow() {
48+
return row;
49+
}
50+
51+
public void setRow(String row) {
52+
this.row = row;
53+
}
54+
55+
public String getColFamily() {
56+
return colFamily;
57+
}
58+
59+
public void setColFamily(String colFamily) {
60+
this.colFamily = colFamily;
61+
}
62+
63+
public String getCol() {
64+
return col;
65+
}
66+
67+
public void setCol(String col) {
68+
this.col = col;
69+
}
70+
71+
public String getVal() {
72+
return val;
73+
}
74+
75+
public void setVal(String val) {
76+
this.val = val;
77+
}
78+
79+
@Override
80+
public String toString() {
81+
return "HbaseCellEntity{" + "table='" + table + '\'' + ", row='" + row + '\'' + ", colFamily='" + colFamily
82+
+ '\'' + ", col='" + col + '\'' + ", val='" + val + '\'' + '}';
83+
}
84+
7885
}

0 commit comments

Comments
 (0)