Skip to content

Commit 26d913e

Browse files
committed
created shaded all packages and updated examples.
1 parent 54753c8 commit 26d913e

File tree

10 files changed

+181
-206
lines changed

10 files changed

+181
-206
lines changed

clickhouse-jdbc/pom.xml

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,15 @@
4040
<groupId>${project.parent.groupId}</groupId>
4141
<artifactId>clickhouse-http-client</artifactId>
4242
<version>${revision}</version>
43-
<optional>true</optional>
4443
</dependency>
4544
<dependency>
4645
<groupId>org.apache.commons</groupId>
4746
<artifactId>commons-compress</artifactId>
48-
<optional>true</optional>
4947
</dependency>
5048

5149
<dependency>
5250
<groupId>org.lz4</groupId>
5351
<artifactId>lz4-pure-java</artifactId>
54-
<optional>true</optional>
5552
</dependency>
5653
<dependency>
5754
<groupId>com.google.code.gson</groupId>
@@ -100,7 +97,13 @@
10097
<artifactId>zstd-jni</artifactId>
10198
<scope>provided</scope>
10299
</dependency>
100+
<dependency>
101+
<groupId>org.slf4j</groupId>
102+
<artifactId>slf4j-api</artifactId>
103+
<version>${slf4j.version}</version>
104+
</dependency>
103105

106+
<!-- Test Dependencies -->
104107
<dependency>
105108
<groupId>${project.parent.groupId}</groupId>
106109
<artifactId>clickhouse-client</artifactId>
@@ -530,6 +533,76 @@
530533
</filters>
531534
</configuration>
532535
</execution>
536+
537+
538+
<execution>
539+
<id>shade-all-v2</id>
540+
<phase>package</phase>
541+
<goals>
542+
<goal>shade</goal>
543+
</goals>
544+
<configuration>
545+
<shadedArtifactAttached>true</shadedArtifactAttached>
546+
<createDependencyReducedPom>true</createDependencyReducedPom>
547+
<createSourcesJar>true</createSourcesJar>
548+
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
549+
<shadedClassifierName>shaded-all</shadedClassifierName>
550+
<relocations>
551+
<relocation>
552+
<pattern>com.google</pattern>
553+
<shadedPattern>${shade.base}.google</shadedPattern>
554+
</relocation>
555+
<relocation>
556+
<pattern>io.opencensus</pattern>
557+
<shadedPattern>${shade.base}.opencensus</shadedPattern>
558+
</relocation>
559+
<relocation>
560+
<pattern>io.perfmark</pattern>
561+
<shadedPattern>${shade.base}.perfmark</shadedPattern>
562+
</relocation>
563+
<relocation>
564+
<pattern>net.jpountz</pattern>
565+
<shadedPattern>${shade.base}.jpountz</shadedPattern>
566+
</relocation>
567+
<relocation>
568+
<pattern>okio</pattern>
569+
<shadedPattern>${shade.base}.okio</shadedPattern>
570+
</relocation>
571+
<relocation>
572+
<pattern>org.apache</pattern>
573+
<shadedPattern>${shade.base}.apache</shadedPattern>
574+
</relocation>
575+
</relocations>
576+
<transformers>
577+
<transformer
578+
implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
579+
<transformer
580+
implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer" />
581+
<transformer
582+
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
583+
<transformer
584+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
585+
<manifestEntries>
586+
<Automatic-Module-Name>${project.groupId}.jdbc</Automatic-Module-Name>
587+
<Main-Class>${mainClass}</Main-Class>
588+
<Specification-Title>${spec.title}</Specification-Title>
589+
<Specification-Version>${spec.version}</Specification-Version>
590+
</manifestEntries>
591+
</transformer>
592+
</transformers>
593+
<filters>
594+
<filter>
595+
<artifact>*:*</artifact>
596+
<excludes>
597+
<exclude>google/**</exclude>
598+
<exclude>org/checkerframework/**</exclude>
599+
<exclude>org/codehaus/**</exclude>
600+
<exclude>**/module-info.class</exclude>
601+
</excludes>
602+
</filter>
603+
</filters>
604+
</configuration>
605+
</execution>
533606
</executions>
534607
</plugin>
535608
<plugin>

client-v2/pom.xml

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
<properties>
2020
<apache.httpclient.version>5.3.1</apache.httpclient.version>
21+
<shade.base>${project.groupId}.shaded</shade.base>
2122
</properties>
2223

2324
<dependencies>
@@ -157,29 +158,54 @@
157158
<artifactId>maven-shade-plugin</artifactId>
158159
<executions>
159160
<execution>
160-
<id>shade</id>
161+
<id>shade-all</id>
161162
<phase>package</phase>
162163
<goals>
163164
<goal>shade</goal>
164165
</goals>
165166
<configuration>
166167
<shadedArtifactAttached>true</shadedArtifactAttached>
167-
<shadedClassifierName>shaded</shadedClassifierName>
168+
<shadedClassifierName>all</shadedClassifierName>
168169
<createDependencyReducedPom>true</createDependencyReducedPom>
169170
<createSourcesJar>true</createSourcesJar>
170171
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
171-
<artifactSet>
172-
<includes>
173-
<include>com.clickhouse:clickhouse-data</include>
174-
<include>com.clickhouse:clickhouse-client</include>
175-
<include>org.lz4:lz4-pure-java</include>
176-
</includes>
177-
</artifactSet>
178172
<relocations>
179173
<relocation>
174+
<pattern>org.slf4j</pattern>
175+
<shadedPattern>${shade.base}.org.slf4j</shadedPattern>
176+
</relocation>
177+
178+
<relocation>
179+
<pattern>org.apache</pattern>
180+
<shadedPattern>${shade.base}.org.apache</shadedPattern>
181+
</relocation>
182+
183+
<relocation>
184+
<!-- lz4 -->
180185
<pattern>net.jpountz</pattern>
181-
<shadedPattern>${shade.base}.jpountz</shadedPattern>
186+
<shadedPattern>${shade.base}.net.jpountz.lz4</shadedPattern>
187+
</relocation>
188+
189+
<relocation>
190+
<pattern>org.ow2</pattern>
191+
<shadedPattern>${shade.base}.org.ow2</shadedPattern>
192+
</relocation>
193+
194+
<relocation>
195+
<pattern>com.fasterxml</pattern>
196+
<shadedPattern>${shade.base}.com.fasterxml</shadedPattern>
197+
</relocation>
198+
199+
<relocation>
200+
<pattern>org.roaringbitmap</pattern>
201+
<shadedPattern>${shade.base}.org.roaringbitmap</shadedPattern>
182202
</relocation>
203+
204+
<relocation>
205+
<pattern>org.objectweb</pattern>
206+
<shadedPattern>${shade.base}.org.objectweb</shadedPattern>
207+
</relocation>
208+
183209
</relocations>
184210
<transformers>
185211
<transformer
@@ -199,6 +225,7 @@
199225
</filters>
200226
</configuration>
201227
</execution>
228+
202229
</executions>
203230
</plugin>
204231
<plugin>

examples/client-v2/pom.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,9 @@
7777
<groupId>com.clickhouse</groupId>
7878
<artifactId>client-v2</artifactId>
7979
<version>${clickhouse-java.version}</version>
80+
<classifier>all</classifier>
8081
</dependency>
8182

82-
<!-- If Old implementation needed -->
83-
<!-- <dependency>-->
84-
<!-- <groupId>com.clickhouse</groupId>-->
85-
<!-- <artifactId>clickhouse-http-client</artifactId>-->
86-
<!-- <version>${clickhouse-java.version}</version>-->
87-
<!-- </dependency>-->
88-
89-
9083
<!-- Recommended for JSON parsing -->
9184
<dependency>
9285
<groupId>com.fasterxml.jackson.core</groupId>

examples/demo-kotlin-service/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ dependencies {
3333
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
3434

3535
// https://mvnrepository.com/artifact/com.clickhouse/client-v2
36-
implementation("com.clickhouse:client-v2:0.7.1-patch1-SNAPSHOT")
37-
// implementation("com.clickhouse:client-v2:0.7.1") // release version
36+
implementation("com.clickhouse:client-v2:0.7.1-patch1-SNAPSHOT:all")
37+
// implementation("com.clickhouse:client-v2:0.7.1-patch1:all") // release version
3838

3939
testImplementation("io.ktor:ktor-server-test-host-jvm")
4040
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")

examples/demo-service/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ dependencies {
2929

3030
// -- clickhouse dependencies
3131
// Main dependency
32-
implementation("com.clickhouse:client-v2:0.7.1-patch1-SNAPSHOT") // local or nightly build
33-
// implementation("com.clickhouse:client-v2:0.7.1") // release version
32+
implementation("com.clickhouse:client-v2:0.7.1-patch1-SNAPSHOT:all") // local or nightly build
33+
// implementation("com.clickhouse:client-v2:0.7.1-patch1:all") // release version
3434

3535
// -- clickhouse-http-client dependencies if old implementation is needed
3636
// implementation("com.clickhouse:clickhouse-http-client:0.7.1-SNAPSHOT")

examples/jdbc/README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ To run simplified example:
1818
mvn exec:java -Dexec.mainClass="com.clickhouse.examples.jdbc.Basic"
1919
```
2020

21-
To run example with jdbc-all packaging (fat-jar):
22-
```shell
23-
mvn -Pfatjar exec:java -Dexec.mainClass="com.clickhouse.examples.jdbc.Basic"
24-
```
25-
26-
To run example with jdbc-shaded packaging:
27-
```shell
28-
mvn -Pshaded exec:java -Dexec.mainClass="com.clickhouse.examples.jdbc.Basic"
29-
```
30-
3121
Addition options can be passed to the application:
32-
- `-DchUrl` - ClickHouse JDBC URL. Default is `jdbc:clickhouse://localhost:8123/default`
22+
- `-DchUrl` - ClickHouse JDBC URL. Default is `jdbc:clickhouse://localhost:8123/default`
23+
- `-Dclickhouse.jdbc.v2=true` - Use JDBC V2 implementation

examples/jdbc/pom.xml

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,6 @@
2727
</license>
2828
</licenses>
2929

30-
<developers>
31-
<developer>
32-
<id>zhicwu</id>
33-
<name>Zhichun Wu</name>
34-
<email>[email protected]</email>
35-
<timezone>+8</timezone>
36-
</developer>
37-
</developers>
38-
3930
<scm>
4031
<url>https://github.com/ClickHouse/clickhouse-java</url>
4132
<connection>scm:[email protected]:ClickHouse/clickhouse-java.git</connection>
@@ -73,56 +64,29 @@
7364
<compiler-plugin.version>3.8.1</compiler-plugin.version>
7465

7566
<minJdk>1.8</minJdk>
67+
<clickhouse-packages.classifier>all</clickhouse-packages.classifier>
7668
</properties>
7769

78-
<profiles>
79-
<profile>
80-
<id>http</id>
81-
<activation>
82-
<activeByDefault>true</activeByDefault>
83-
</activation>
84-
<dependencies>
85-
<dependency>
86-
<groupId>com.clickhouse</groupId>
87-
<artifactId>clickhouse-jdbc</artifactId>
88-
<version>${clickhouse-java.version}</version>
89-
<classifier>http</classifier>
90-
</dependency>
91-
</dependencies>
92-
</profile>
93-
94-
<profile>
95-
<id>shaded</id>
96-
<dependencies>
97-
<dependency>
98-
<groupId>com.clickhouse</groupId>
99-
<artifactId>clickhouse-jdbc</artifactId>
100-
<version>${clickhouse-java.version}</version>
101-
<classifier>shaded</classifier>
102-
</dependency>
103-
</dependencies>
104-
</profile>
105-
106-
<profile>
107-
<id>fatjar</id>
108-
<dependencies>
109-
<dependency>
110-
<groupId>com.clickhouse</groupId>
111-
<artifactId>clickhouse-jdbc</artifactId>
112-
<version>${clickhouse-java.version}</version>
113-
<classifier>all</classifier>
114-
</dependency>
115-
</dependencies>
116-
</profile>
117-
118-
</profiles>
119-
12070
<dependencies>
12171
<dependency>
12272
<groupId>com.zaxxer</groupId>
12373
<artifactId>HikariCP</artifactId>
12474
<version>${hikaricp.version}</version>
12575
</dependency>
76+
77+
<dependency>
78+
<groupId>com.clickhouse</groupId>
79+
<artifactId>clickhouse-jdbc</artifactId>
80+
<version>${clickhouse-java.version}</version>
81+
<classifier>${clickhouse-packages.classifier}</classifier>
82+
</dependency>
83+
84+
<dependency>
85+
<groupId>org.slf4j</groupId>
86+
<artifactId>slf4j-simple</artifactId>
87+
<version>2.0.13</version>
88+
<scope>runtime</scope>
89+
</dependency>
12690
</dependencies>
12791

12892
<build>

examples/jdbc/src/main/java/com/clickhouse/examples/jdbc/Advanced.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,6 @@ static String exteralTables(String url) throws SQLException {
8282
}
8383
}
8484

85-
static String manualTransaction(String url) throws SQLException {
86-
Properties props = new Properties();
87-
// props.setProperty(JdbcConfig.PROP_AUTO_COMMIT, "false");
88-
props.setProperty("autoCommit", "false");
89-
// props.setProperty(JdbcConfig.PROP_TX_SUPPORT, "true");
90-
props.setProperty("transactionSupport", "true");
91-
try (Connection conn = getConnection(url, props)) {
92-
if (!((ClickHouseConnection) conn).isTransactionSupported()) {
93-
System.out.println("Re-establishing connection until transaction is supported...");
94-
return manualTransaction(url);
95-
}
96-
97-
conn.commit();
98-
return "Transaction committed!";
99-
}
100-
}
101-
10285
static String namedParameter(String url) throws SQLException {
10386
Properties props = new Properties();
10487
// props.setProperty(JdbcConfig.PROP_NAMED_PARAM, "true");
@@ -172,19 +155,14 @@ static String unwrapToUseClientApi(String url) throws SQLException {
172155
public static void main(String[] args) {
173156
// randomly pick one of the two endpoints to connect to,
174157
// fail over to the other when there's connection issue
175-
String url = System.getProperty("chUrl",
176-
"jdbc:ch://(https://[email protected]:443),"
177-
+ "(https://demo:[email protected])"
178-
+ "/default?failover=1&load_balancing_policy=random");
158+
String url = System.getProperty("chUrl", "jdbc:ch://localhost");
179159

180160
try {
181161
System.out.println(exteralTables(url));
182162
System.out.println(namedParameter(url));
183163
System.out.println(renameResponseColumn(url));
184164
System.out.println(unwrapToUseClientApi(url));
185165

186-
// requires ClickHouse 22.6+ with transaction enabled
187-
System.out.println(manualTransaction(url));
188166
} catch (SQLException e) {
189167
e.printStackTrace();
190168
}

0 commit comments

Comments
 (0)