Skip to content

Commit

Permalink
Reform java client to combine with TiSpark's java client (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
birdstorm authored Oct 21, 2020
1 parent 26121ee commit df03a62
Show file tree
Hide file tree
Showing 190 changed files with 24,697 additions and 464 deletions.
21 changes: 21 additions & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# TiSpark Dev Tools Guide

## Formatting

### Java Format

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.

1. In Intellij IDEA

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`.

2. you may also use [Java-Google-style xml file](./intellij-java-google-style.xml) and export the schema to Intellij:

`Preferences`->`Editor`->`Code Style`->`Import Scheme`->`Intellij IDEA Code Style XML`.

2. You may also run [Java format script](./javafmt) before you commit & push to corresponding dev branch.

```shell script
./dev/javafmt
```
598 changes: 598 additions & 0 deletions dev/intellij-java-google-style.xml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions dev/javafmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

echo $MAVEN_HOME

mvn com.coveo:fmt-maven-plugin:format
69 changes: 68 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.tikv</groupId>
<artifactId>tikv-client-java</artifactId>
<version>2.0-SNAPSHOT</version>
<version>3.0.0</version>
<packaging>jar</packaging>
<name>TiSpark Project TiKV Java Client</name>

Expand All @@ -19,6 +19,7 @@
<powermock.version>1.6.6</powermock.version>
<jackson.version>2.10.0</jackson.version>
<trove4j.version>3.0.1</trove4j.version>
<jetcd.version>0.4.1</jetcd.version>
<joda-time.version>2.9.9</joda-time.version>
<joda-convert.version>1.9.2</joda-convert.version>
<proto.folder>${basedir}/proto</proto.folder>
Expand All @@ -27,6 +28,11 @@
</properties>

<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.7.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand All @@ -51,6 +57,11 @@
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sangupta</groupId>
<artifactId>murmur</artifactId>
<version>1.0.0</version>
</dependency>
<!-- grpc dependencies -->
<dependency>
<groupId>io.grpc</groupId>
Expand All @@ -73,6 +84,35 @@
<version>${grpc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>io.etcd</groupId>
<artifactId>jetcd-core</artifactId>
<exclusions>
<exclusion>
<groupId>io.etcd</groupId>
<artifactId>jetcd-resolver</artifactId>
</exclusion>
<exclusion>
<groupId>io.etcd</groupId>
<artifactId>jetcd-common</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-grpclb</artifactId>
</exclusion>
</exclusions>
<version>${jetcd.version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
Expand All @@ -95,6 +135,12 @@
<version>3.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<resources>
Expand All @@ -110,6 +156,27 @@
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.7.1</version>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
<configuration>
<arguments>
<argument>-package</argument>
<argument>org.tikv.common.parser</argument>
</arguments>
<visitor>true</visitor>
<sourceDirectory>./src/main/java/org/tikv/common/parser</sourceDirectory>
<outputDirectory>./target/generated-sources/antlr4/java/org/tikv/common/parser</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/org/tikv/common/BytePairWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2020 PingCAP, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.tikv.common;

public class BytePairWrapper {
private final byte[] key;
private final byte[] value;

public BytePairWrapper(byte[] key, byte[] value) {
this.key = key;
this.value = value;
}

public byte[] getKey() {
return key;
}

public byte[] getValue() {
return value;
}
}
49 changes: 49 additions & 0 deletions src/main/java/org/tikv/common/ByteWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2020 PingCAP, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.tikv.common;

import java.util.Arrays;

public class ByteWrapper {
private final byte[] bytes;

public ByteWrapper(byte[] bytes) {
this.bytes = bytes;
}

public byte[] getBytes() {
return this.bytes;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

ByteWrapper that = (ByteWrapper) o;

return Arrays.equals(bytes, that.bytes);
}

@Override
public int hashCode() {
return Arrays.hashCode(bytes);
}
}
67 changes: 67 additions & 0 deletions src/main/java/org/tikv/common/ExtendedDateTime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
*
* Copyright 2019 PingCAP, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.tikv.common;

import java.sql.Timestamp;
import org.joda.time.DateTime;

/** Extend joda DateTime to support micro second */
public class ExtendedDateTime {

private final DateTime dateTime;
private final int microsOfMillis;

/**
* if timestamp = 2019-11-11 11:11:11 123456, then dateTime = 2019-11-11 11:11:11 123
* microInMillis = 456
*
* @param dateTime
* @param microsOfMillis
*/
public ExtendedDateTime(DateTime dateTime, int microsOfMillis) {
this.dateTime = dateTime;
this.microsOfMillis = microsOfMillis;
}

public ExtendedDateTime(DateTime dateTime) {
this.dateTime = dateTime;
this.microsOfMillis = 0;
}

public DateTime getDateTime() {
return dateTime;
}

public int getMicrosOfSeconds() {
return dateTime.getMillisOfSecond() * 1000 + microsOfMillis;
}

public int getMicrosOfMillis() {
return microsOfMillis;
}

public Timestamp toTimeStamp() {
Timestamp timestamp = new Timestamp(dateTime.getMillis() / 1000 * 1000);
timestamp.setNanos(dateTime.getMillisOfSecond() * 1000000 + microsOfMillis * 1000);
return timestamp;
}

public long toEpochMicro() {
return toTimeStamp().getTime() * 1000 + getMicrosOfMillis();
}
}
Loading

0 comments on commit df03a62

Please sign in to comment.