Skip to content

Commit 096736e

Browse files
committed
Initial commit
0 parents  commit 096736e

40 files changed

+3681
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.idea/
2+
target/
3+
*.iml
4+
*.ipr
5+
*.iws
6+
.DS_Store
7+
.DS_Store?
8+
Thumbs.db
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
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+
* https://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+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import java.net.*;
18+
import java.io.*;
19+
import java.nio.channels.*;
20+
import java.util.Properties;
21+
22+
public class MavenWrapperDownloader {
23+
24+
private static final String WRAPPER_VERSION = "0.5.5";
25+
/**
26+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
27+
*/
28+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
29+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
30+
31+
/**
32+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
33+
* use instead of the default one.
34+
*/
35+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
36+
".mvn/wrapper/maven-wrapper.properties";
37+
38+
/**
39+
* Path where the maven-wrapper.jar will be saved to.
40+
*/
41+
private static final String MAVEN_WRAPPER_JAR_PATH =
42+
".mvn/wrapper/maven-wrapper.jar";
43+
44+
/**
45+
* Name of the property which should be used to override the default download url for the wrapper.
46+
*/
47+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
48+
49+
public static void main(String args[]) {
50+
System.out.println("- Downloader started");
51+
File baseDirectory = new File(args[0]);
52+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
53+
54+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
55+
// wrapperUrl parameter.
56+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
57+
String url = DEFAULT_DOWNLOAD_URL;
58+
if (mavenWrapperPropertyFile.exists()) {
59+
FileInputStream mavenWrapperPropertyFileInputStream = null;
60+
try {
61+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
62+
Properties mavenWrapperProperties = new Properties();
63+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
64+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
65+
} catch (IOException e) {
66+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
67+
} finally {
68+
try {
69+
if (mavenWrapperPropertyFileInputStream != null) {
70+
mavenWrapperPropertyFileInputStream.close();
71+
}
72+
} catch (IOException e) {
73+
// Ignore ...
74+
}
75+
}
76+
}
77+
System.out.println("- Downloading from: " + url);
78+
79+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
80+
if (!outputFile.getParentFile().exists()) {
81+
if (!outputFile.getParentFile().mkdirs()) {
82+
System.out.println(
83+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
84+
}
85+
}
86+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
87+
try {
88+
downloadFileFromURL(url, outputFile);
89+
System.out.println("Done");
90+
System.exit(0);
91+
} catch (Throwable e) {
92+
System.out.println("- Error downloading");
93+
e.printStackTrace();
94+
System.exit(1);
95+
}
96+
}
97+
98+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
99+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
100+
String username = System.getenv("MVNW_USERNAME");
101+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
102+
Authenticator.setDefault(new Authenticator() {
103+
@Override
104+
protected PasswordAuthentication getPasswordAuthentication() {
105+
return new PasswordAuthentication(username, password);
106+
}
107+
});
108+
}
109+
URL website = new URL(urlString);
110+
ReadableByteChannel rbc;
111+
rbc = Channels.newChannel(website.openStream());
112+
FileOutputStream fos = new FileOutputStream(destination);
113+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
114+
fos.close();
115+
rbc.close();
116+
}
117+
118+
}

.mvn/wrapper/maven-wrapper.jar

49.5 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Roach Demo Data
2+
3+
Collection of small Spring Boot demos using CockroachDB with common data access frameworks and ORMs.
4+
The purpose is to showcase how CockroachDB can be used with a mainstream Enterprise Java framework
5+
stack composed by Spring Boot, Spring Data and Spring HATEOAS.
6+
7+
Data access variants include:
8+
9+
- [JDBC](jdbc/README.md) - using Spring Data JDBC
10+
- [JPA](jpa/README.md) - using Spring Data JPA with Hibernate as ORM provider
11+
- [jOOQ](jooq/README.md) - using Spring Boot with jOOQ (not officially supported by spring-data)
12+
- [MyBatis](mybatis/README.md) - using Spring Data MyBatis/JDBC
13+
14+
All demos are independent and use the same schema and test workload.
15+
16+
Common Spring Boot features in all demos:
17+
18+
- Liquibase Schema versioning
19+
- Hikari Connection Pool
20+
- Executable jar with embedded Jetty container
21+
- Pagination, both manual and via Spring Data JPA
22+
- Transaction retries with exponential backoff using AspectJ
23+
- Hypermedia API via Spring HATEOAS and HAL media type
24+
- Simple HTTP client invoking commands
25+
26+
The most documented demo is the JDBC version. It also includes an extra aspect for setting
27+
transaction attributes including time travel / follower reads.
28+
29+
## Prerequisites
30+
31+
- JDK8+ with 1.8 language level (OpenJDK compatible)
32+
- Maven 3+ (wrapper provided)
33+
- CockroachDB with a database named `roach_demo_data`
34+
35+
## Building
36+
37+
./mvnw clean install
38+
39+
See each respective module for more details.
40+
41+
## Running
42+
43+
All demos do the same thing which is to run through a series of concurrent account
44+
transfer requests. The requests are being intentionally submitted in such a way
45+
it will cause lock contention in the database and thereby trigger aborts and retry's.
46+
That's why the demo starts with a wall of warning messages, which is expected.
47+
It ends with the message:
48+
49+
"All client workers finished but server keeps running. Have a nice day!"
50+
51+
The service remains running after the test is complete and can be access via:
52+
53+
- http://localhost:8080
54+
55+
You could use something like Postman to send requests to the API on your own.
56+
57+
A custom database URL is specified with a config override:
58+
59+
--spring.datasource.url=jdbc:postgresql://192.168.1.99:26257/roach_demo_data?sslmode=disable
60+
61+
### JDBC demo
62+
63+
java -jar jdbc/target/roach-demo-data.jar
64+
65+
### JPA demo
66+
67+
java -jar jpa/target/roach-demo-data.jar
68+
69+
### jOOQ demo
70+
71+
java -jar jooq/target/roach-demo-data.jar
72+
73+
### MyBatis demo
74+
75+
java -jar mybatis/target/roach-demo-data.jar

jdbc/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Roach Demo Data :: JDBC
2+
3+
Spring Boot Demo using CockroachDB with vanilla spring-data-jdbc.
4+
5+

jdbc/pom.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>io.roach.demo.data</groupId>
7+
<artifactId>roach-demo-data-parent</artifactId>
8+
<version>1.0.0.BUILD-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>roach-demo-data-jdbc</artifactId>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-web</artifactId>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-jetty</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-hateoas</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-aop</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-data-jdbc</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-actuator</artifactId>
37+
</dependency>
38+
<!--
39+
<dependency>
40+
<groupId>org.springframework.data</groupId>
41+
<artifactId>spring-data-commons</artifactId>
42+
</dependency>
43+
-->
44+
<dependency>
45+
<groupId>org.liquibase</groupId>
46+
<artifactId>liquibase-core</artifactId>
47+
<scope>runtime</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.postgresql</groupId>
51+
<artifactId>postgresql</artifactId>
52+
<scope>provided</scope>
53+
</dependency>
54+
</dependencies>
55+
56+
<build>
57+
<plugins>
58+
<plugin>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-maven-plugin</artifactId>
61+
<!--
62+
<executions>
63+
<execution>
64+
<configuration>
65+
<executable>true</executable>
66+
<mainClass>io.roach.demo.data.JdbcApplication</mainClass>
67+
</configuration>
68+
</execution>
69+
</executions>
70+
-->
71+
</plugin>
72+
</plugins>
73+
</build>
74+
</project>

0 commit comments

Comments
 (0)