Skip to content

Commit df03a62

Browse files
authored
Reform java client to combine with TiSpark's java client (#91)
1 parent 26121ee commit df03a62

File tree

190 files changed

+24697
-464
lines changed

Some content is hidden

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

190 files changed

+24697
-464
lines changed

dev/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# TiSpark Dev Tools Guide
2+
3+
## Formatting
4+
5+
### Java Format
6+
7+
TiKV Java Client formats its code using [Google-Java-Format Maven Plugin](https://github.com/coveooss/fmt-maven-plugin) which follows Google's code styleguide. It is also checked on CI before build.
8+
9+
1. In Intellij IDEA
10+
11+
1. you should download the [Google-Java-format Plugin](https://plugins.jetbrains.com/plugin/8527-google-java-format) via marketplace. Restart IDE, and enable google-java-format by checking the box in `Other Settings`.
12+
13+
2. you may also use [Java-Google-style xml file](./intellij-java-google-style.xml) and export the schema to Intellij:
14+
15+
`Preferences`->`Editor`->`Code Style`->`Import Scheme`->`Intellij IDEA Code Style XML`.
16+
17+
2. You may also run [Java format script](./javafmt) before you commit & push to corresponding dev branch.
18+
19+
```shell script
20+
./dev/javafmt
21+
```

dev/intellij-java-google-style.xml

Lines changed: 598 additions & 0 deletions
Large diffs are not rendered by default.

dev/javafmt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
echo $MAVEN_HOME
4+
5+
mvn com.coveo:fmt-maven-plugin:format

pom.xml

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.tikv</groupId>
77
<artifactId>tikv-client-java</artifactId>
8-
<version>2.0-SNAPSHOT</version>
8+
<version>3.0.0</version>
99
<packaging>jar</packaging>
1010
<name>TiSpark Project TiKV Java Client</name>
1111

@@ -19,6 +19,7 @@
1919
<powermock.version>1.6.6</powermock.version>
2020
<jackson.version>2.10.0</jackson.version>
2121
<trove4j.version>3.0.1</trove4j.version>
22+
<jetcd.version>0.4.1</jetcd.version>
2223
<joda-time.version>2.9.9</joda-time.version>
2324
<joda-convert.version>1.9.2</joda-convert.version>
2425
<proto.folder>${basedir}/proto</proto.folder>
@@ -27,6 +28,11 @@
2728
</properties>
2829

2930
<dependencies>
31+
<dependency>
32+
<groupId>org.antlr</groupId>
33+
<artifactId>antlr4-runtime</artifactId>
34+
<version>4.7.1</version>
35+
</dependency>
3036
<dependency>
3137
<groupId>org.slf4j</groupId>
3238
<artifactId>slf4j-api</artifactId>
@@ -51,6 +57,11 @@
5157
<version>${slf4j.version}</version>
5258
<scope>provided</scope>
5359
</dependency>
60+
<dependency>
61+
<groupId>com.sangupta</groupId>
62+
<artifactId>murmur</artifactId>
63+
<version>1.0.0</version>
64+
</dependency>
5465
<!-- grpc dependencies -->
5566
<dependency>
5667
<groupId>io.grpc</groupId>
@@ -73,6 +84,35 @@
7384
<version>${grpc.version}</version>
7485
<scope>test</scope>
7586
</dependency>
87+
<dependency>
88+
<groupId>com.fasterxml.jackson.core</groupId>
89+
<artifactId>jackson-annotations</artifactId>
90+
<version>${jackson.version}</version>
91+
</dependency>
92+
<dependency>
93+
<groupId>com.fasterxml.jackson.core</groupId>
94+
<artifactId>jackson-databind</artifactId>
95+
<version>${jackson.version}</version>
96+
</dependency>
97+
<dependency>
98+
<groupId>io.etcd</groupId>
99+
<artifactId>jetcd-core</artifactId>
100+
<exclusions>
101+
<exclusion>
102+
<groupId>io.etcd</groupId>
103+
<artifactId>jetcd-resolver</artifactId>
104+
</exclusion>
105+
<exclusion>
106+
<groupId>io.etcd</groupId>
107+
<artifactId>jetcd-common</artifactId>
108+
</exclusion>
109+
<exclusion>
110+
<groupId>io.grpc</groupId>
111+
<artifactId>grpc-grpclb</artifactId>
112+
</exclusion>
113+
</exclusions>
114+
<version>${jetcd.version}</version>
115+
</dependency>
76116
<dependency>
77117
<groupId>joda-time</groupId>
78118
<artifactId>joda-time</artifactId>
@@ -95,6 +135,12 @@
95135
<version>3.9</version>
96136
<scope>test</scope>
97137
</dependency>
138+
<dependency>
139+
<groupId>org.apache.commons</groupId>
140+
<artifactId>commons-lang3</artifactId>
141+
<version>3.9</version>
142+
<scope>compile</scope>
143+
</dependency>
98144
</dependencies>
99145
<build>
100146
<resources>
@@ -110,6 +156,27 @@
110156
</extension>
111157
</extensions>
112158
<plugins>
159+
<plugin>
160+
<groupId>org.antlr</groupId>
161+
<artifactId>antlr4-maven-plugin</artifactId>
162+
<version>4.7.1</version>
163+
<executions>
164+
<execution>
165+
<goals>
166+
<goal>antlr4</goal>
167+
</goals>
168+
</execution>
169+
</executions>
170+
<configuration>
171+
<arguments>
172+
<argument>-package</argument>
173+
<argument>org.tikv.common.parser</argument>
174+
</arguments>
175+
<visitor>true</visitor>
176+
<sourceDirectory>./src/main/java/org/tikv/common/parser</sourceDirectory>
177+
<outputDirectory>./target/generated-sources/antlr4/java/org/tikv/common/parser</outputDirectory>
178+
</configuration>
179+
</plugin>
113180
<plugin>
114181
<groupId>org.codehaus.mojo</groupId>
115182
<artifactId>exec-maven-plugin</artifactId>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2020 PingCAP, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package org.tikv.common;
17+
18+
public class BytePairWrapper {
19+
private final byte[] key;
20+
private final byte[] value;
21+
22+
public BytePairWrapper(byte[] key, byte[] value) {
23+
this.key = key;
24+
this.value = value;
25+
}
26+
27+
public byte[] getKey() {
28+
return key;
29+
}
30+
31+
public byte[] getValue() {
32+
return value;
33+
}
34+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2020 PingCAP, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package org.tikv.common;
17+
18+
import java.util.Arrays;
19+
20+
public class ByteWrapper {
21+
private final byte[] bytes;
22+
23+
public ByteWrapper(byte[] bytes) {
24+
this.bytes = bytes;
25+
}
26+
27+
public byte[] getBytes() {
28+
return this.bytes;
29+
}
30+
31+
@Override
32+
public boolean equals(Object o) {
33+
if (this == o) {
34+
return true;
35+
}
36+
if (o == null || getClass() != o.getClass()) {
37+
return false;
38+
}
39+
40+
ByteWrapper that = (ByteWrapper) o;
41+
42+
return Arrays.equals(bytes, that.bytes);
43+
}
44+
45+
@Override
46+
public int hashCode() {
47+
return Arrays.hashCode(bytes);
48+
}
49+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
*
3+
* Copyright 2019 PingCAP, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.tikv.common;
19+
20+
import java.sql.Timestamp;
21+
import org.joda.time.DateTime;
22+
23+
/** Extend joda DateTime to support micro second */
24+
public class ExtendedDateTime {
25+
26+
private final DateTime dateTime;
27+
private final int microsOfMillis;
28+
29+
/**
30+
* if timestamp = 2019-11-11 11:11:11 123456, then dateTime = 2019-11-11 11:11:11 123
31+
* microInMillis = 456
32+
*
33+
* @param dateTime
34+
* @param microsOfMillis
35+
*/
36+
public ExtendedDateTime(DateTime dateTime, int microsOfMillis) {
37+
this.dateTime = dateTime;
38+
this.microsOfMillis = microsOfMillis;
39+
}
40+
41+
public ExtendedDateTime(DateTime dateTime) {
42+
this.dateTime = dateTime;
43+
this.microsOfMillis = 0;
44+
}
45+
46+
public DateTime getDateTime() {
47+
return dateTime;
48+
}
49+
50+
public int getMicrosOfSeconds() {
51+
return dateTime.getMillisOfSecond() * 1000 + microsOfMillis;
52+
}
53+
54+
public int getMicrosOfMillis() {
55+
return microsOfMillis;
56+
}
57+
58+
public Timestamp toTimeStamp() {
59+
Timestamp timestamp = new Timestamp(dateTime.getMillis() / 1000 * 1000);
60+
timestamp.setNanos(dateTime.getMillisOfSecond() * 1000000 + microsOfMillis * 1000);
61+
return timestamp;
62+
}
63+
64+
public long toEpochMicro() {
65+
return toTimeStamp().getTime() * 1000 + getMicrosOfMillis();
66+
}
67+
}

0 commit comments

Comments
 (0)