Skip to content

Commit dd7b0d7

Browse files
committed
Preparation for release
1 parent 03a1fef commit dd7b0d7

File tree

10 files changed

+242
-5
lines changed

10 files changed

+242
-5
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# OBKV Table Client
22
OBKV Table Client is Java Library that can be used to access table data from [OceanBase](https://github.com/oceanbase/oceanbase) storage layer. Its access method is different from JDBC, it skips the SQL parsing layer, so it has significant performance advantage.
33

4-
## Quick start
4+
## Quick Start
55

66
Create table in the OceanBase database:
77

@@ -54,6 +54,9 @@ The code demo:
5454
1. param_url is generated by ConfigServer (link TODO).
5555
2. More example [Demo](https://github.com/oceanbase/obkv-table-client-java/tree/master/example)
5656

57+
## Release Notes
58+
Latest release notes could be found in [Release notes](https://github.com/oceanbase/obkv-table-client-java/wiki#release-notes)
59+
5760
## Documentation
5861

5962
- English [Coming soon]

example/simple-mutation/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
obkv-table-client-java demo project.
2+
3+
## Notice
4+
* **ObTableFilter** is not available now, similarly, mutation with filter cannot be used since the observer has not supported related functions.

example/simple-mutation/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.oceanbase.example</groupId>
8+
<artifactId>simple-mutation</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
12+
<properties>
13+
<maven.compiler.source>8</maven.compiler.source>
14+
<maven.compiler.target>8</maven.compiler.target>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.oceanbase</groupId>
20+
<artifactId>obkv-table-client</artifactId>
21+
<version>1.0.0</version>
22+
</dependency>
23+
</dependencies>
24+
25+
26+
</project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*-
2+
* #%L
3+
* OBKV Table Client Framework
4+
* %%
5+
* Copyright (C) 2021 OceanBase
6+
* %%
7+
* OBKV Table Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
18+
package com.oceanbase.example;
19+
20+
import com.alipay.oceanbase.rpc.ObTableClient;
21+
22+
import java.util.Map;
23+
import java.util.List;
24+
25+
/* table schema:
26+
CREATE TABLE IF NOT EXISTS `kv_table` (
27+
`key` varchar(20) NOT NULL,
28+
`val` varchar(20) DEFAULT NULL,
29+
PRIMARY KEY (`key`)
30+
);
31+
*/
32+
33+
public class MutationUtil {
34+
private ObTableClient obTableClient = null;
35+
private String tableName = "kv_table";
36+
37+
public boolean initial() {
38+
try {
39+
obTableClient = new ObTableClient();
40+
obTableClient.setFullUserName("your user name"); // e.g. root@sys#ocp
41+
obTableClient.setParamURL("your configurl + database=xxx"); // e.g. http://ip:port/services?Action=ObRootServiceInfo&ObRegion=ocp&database=test
42+
obTableClient.setPassword("your user passwd");
43+
obTableClient.setSysUserName("your sys user"); // e.g. proxyro@sys
44+
obTableClient.setSysPassword("your sys user passwd");
45+
obTableClient.init();
46+
} catch (Exception e) {
47+
e.printStackTrace();
48+
System.out.println("fail to init OBKV client, " + e);
49+
obTableClient = null;
50+
return false;
51+
}
52+
System.out.println("initial OBKV client success");
53+
return true;
54+
}
55+
56+
public void close() {
57+
if (obTableClient == null) {
58+
return;
59+
}
60+
try {
61+
obTableClient.close();
62+
} catch (Exception e) {
63+
e.printStackTrace();
64+
System.out.println("fail to close OBKV client, " + e);
65+
}
66+
}
67+
68+
public ObTableClient getClient() {
69+
return this.obTableClient;
70+
}
71+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*-
2+
* #%L
3+
* OBKV Table Client Framework
4+
* %%
5+
* Copyright (C) 2021 OceanBase
6+
* %%
7+
* OBKV Table Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
18+
package com.oceanbase.example;
19+
20+
import com.alipay.oceanbase.rpc.Mutation;
21+
22+
/* table schema:
23+
CREATE TABLE IF NOT EXISTS `kv_table` (
24+
`key` varchar(20) NOT NULL,
25+
`val` varchar(20) DEFAULT NULL,
26+
PRIMARY KEY (`key`)
27+
);
28+
*/
29+
30+
public class SimpleMutation {
31+
32+
public static void main(String[] args) {
33+
MutationUtil mutationUtil = new MutationUtil();
34+
ObTableClient tableClient = null;
35+
try {
36+
if (!mutationUtil.initial()) {
37+
return;
38+
}
39+
tableClient = mutationUtil.getClient();
40+
41+
// ColumnValue -> key-value pair
42+
ColumnValue columnValue = colval("key", "value");
43+
44+
// Row -> multi-ColumnValue (row)
45+
Row row = row(columnValue, new ColumnValue("other_key", "other_value"));
46+
47+
// insert
48+
Insert insert = tableClient.insert("kv_table")
49+
.setRowKey(row(colVal("key", "key_0")))
50+
.addMutateColVal(colVal("val", "val_0"));
51+
MutationResult result = insert.execute();
52+
System.out.println("insert " + (result.getAffectedRows()) + " rows");
53+
54+
// update
55+
Update update = tableClient.update("kv_table")
56+
.setRowKey(row(colVal("key", "key_0")))
57+
.addMutateColVal(colVal("val", "val_1"))
58+
.setFilter(compareVal(ObCompareOp.EQ, "val", "val_0")); // not available, coming soon
59+
MutationResult result = update.execute();
60+
System.out.println("update " + result.getAffectedRows() + " rows");
61+
62+
// delete
63+
Delete delete = tableClient.delete("kv_table")
64+
.setRowKey(row(colVal("key", "key_0")))
65+
.setFilter(compareVal(ObCompareOp.EQ, "val", "val_0")); // not available, coming soon
66+
MutationResult result = delete.execute();
67+
System.out.println("delete " + (result.getAffectedRows()) + " rows");
68+
69+
// insertOrUpdate
70+
InsertOrUpdate insertOrUpdate = tableClient.insertOrUpdate("kv_table")
71+
.setRowKey(row(colVal("key", "key_0")))
72+
.addMutateColVal(colVal("val", "val_0"));
73+
MutationResult result = insertOrUpdate.execute();
74+
System.out.println("insertOrUpdate " + (result.getAffectedRows()) + " rows");
75+
76+
// replace
77+
Replace replace = tableClient.replace("kv_table")
78+
.setRowKey(row(colVal("key", "key_0")))
79+
.addMutateColVal(colVal("val", "val_0"));
80+
MutationResult result = replace.execute();
81+
System.out.println("replace " + (result.getAffectedRows()) + " rows");
82+
83+
// increment
84+
Increment increment = tableClient.increment("kv_table")
85+
.setRowKey(row(colVal("key", "key_0")))
86+
.addMutateColVal(colVal("val", "val_1"))
87+
.setFilter(compareVal(ObCompareOp.EQ, "val", "val_0")); // not available, coming soon
88+
MutationResult result = increment.execute();
89+
System.out.println("increment " + result.getAffectedRows() + " rows");
90+
91+
// append
92+
Append append = tableClient.append("kv_table")
93+
.setRowKey(row(colVal("key", "key_0")))
94+
.addMutateColVal(colVal("val", "val_1"))
95+
.setFilter(compareVal(ObCompareOp.EQ, "val", "val_0")); // not available, coming soon
96+
MutationResult result = append.execute();
97+
System.out.println("append " + result.getAffectedRows() + " rows");
98+
99+
100+
// batch operation
101+
// construct single mutation
102+
// filter could not be used in all operation in batchOperation
103+
Insert insert_0 = insert().setRowKey(colVal("key", "key_1"))
104+
.addMutateColVal(colVal("val", "val_1"))
105+
106+
Insert insert_1 = insert().setRowKey(colVal("key", "key_1"))
107+
.addMutateColVal(colVal("val", "val_1"))
108+
109+
Update update_0 = update().setRowKey(colVal("key", "key_1"))
110+
.addMutateColVal(colVal("val", "val_2"))
111+
112+
// construct batch operation
113+
BatchMutationResult batchResult = client.batchMutation("kv_table")
114+
.addMutation(insert_0)
115+
.addMutation(insert_1, update_0)
116+
.execute();
117+
118+
// print output
119+
for (int idx : batchResult.size()) {
120+
System.out.println(String.format("the %dth mutation affect %d rows", idx,
121+
batchResult.get(idx).getAffectedRows()));
122+
}
123+
124+
} finally {
125+
if (tableClient != null) {
126+
tableClient.close();
127+
}
128+
}
129+
}
130+
}

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@
7272
<dependency>
7373
<groupId>io.netty</groupId>
7474
<artifactId>netty-all</artifactId>
75-
<version>4.1.45.Final</version>
75+
<version>4.1.87.Final</version>
7676
</dependency>
7777

7878
<dependency>
7979
<groupId>com.google.guava</groupId>
8080
<artifactId>guava</artifactId>
81-
<version>30.1.1-jre</version>
81+
<version>31.1-jre</version>
8282
</dependency>
8383

8484
<dependency>
@@ -110,7 +110,7 @@
110110
<dependency>
111111
<groupId>mysql</groupId>
112112
<artifactId>mysql-connector-java</artifactId>
113-
<version>8.0.28</version>
113+
<version>8.0.32</version>
114114
</dependency>
115115

116116
<dependency>

src/test/java/com/alipay/oceanbase/rpc/ObTableClientPartitionHashTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public void testQuery() throws Exception {
167167
TableQuery tableQuery = obTableClient.query("testHash");
168168
tableQuery.addScanRange(new Object[] { timeStamp, "partition".getBytes(), timeStamp },
169169
new Object[] { timeStamp, "partition".getBytes(), timeStamp });
170+
tableQuery.select("Q", "T", "K", "V");
170171
QueryResultSet result = tableQuery.execute();
171172
Assert.assertEquals(1L, result.cacheSize());
172173

src/test/java/com/alipay/oceanbase/rpc/ObTableClientPartitionKeyTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ public void testQuery() throws Exception {
207207
tableQuery.addScanRange(
208208
new Object[] { "key1_1".getBytes(), ObObj.getMin(), ObObj.getMin() }, new Object[] {
209209
"key1_8".getBytes(), ObObj.getMax(), ObObj.getMax() });
210+
tableQuery.select("Q", "T", "K", "V");
210211
result = tableQuery.execute();
211212
Assert.assertTrue(result.cacheSize() >= 2);
212213
} else {

src/test/java/com/alipay/oceanbase/rpc/ObTableClientPartitionRangeTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public void testQuery() throws Exception {
206206
TableQuery tableQuery = obTableClient.query("testRange");
207207
tableQuery.addScanRange(new Object[] { "ah", "partition".getBytes(), timeStamp },
208208
new Object[] { "az", "partition".getBytes(), timeStamp });
209+
tableQuery.select("Q", "T", "K", "V");
209210
QueryResultSet result = tableQuery.execute();
210211
Assert.assertEquals(1, result.cacheSize());
211212
Assert.assertTrue(result.next());

src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ public void testBatchMutation() throws Exception {
19411941
BatchOperation batchOperation = client.batchOperation("test_mutation");
19421942
for (int i = 0; i < c1Vals.length; i++) {
19431943
Row rowKey1 = row(colVal("c1", c1Vals[i]), colVal("c2", c2Vals[i]));
1944-
TableQuery query = query().setRowKey(rowKey1);
1944+
TableQuery query = query().setRowKey(rowKey1).select("c1", "c2", "c3", "c4");
19451945
batchOperation.addOperation(query);
19461946
}
19471947
BatchOperationResult result = batchOperation.execute();

0 commit comments

Comments
 (0)