Skip to content

Commit 4b99431

Browse files
author
Maksim Kostromin
committed
Initial commit
0 parents  commit 4b99431

20 files changed

+1655
-0
lines changed

.github/workflows/ci.yaml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This workflow will build a Java project with Maven
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
name: CI
4+
on:
5+
push:
6+
branches: [ master ]
7+
pull_request:
8+
branches: [ master ]
9+
jobs:
10+
unit-tests:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/cache@v2
15+
id: ci
16+
with:
17+
path: |
18+
~/.m2/repository
19+
!~/.m2/repository/com/gituhb/daggerok
20+
key: ${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
21+
- uses: actions/setup-java@v1
22+
with:
23+
java-version: 11
24+
- run: ./mvnw -B dependency:resolve-plugins dependency:resolve
25+
- run: ./mvnw -P pg-stop ; ./mvnw -P pg-start
26+
- run: ./mvnw test
27+
- run: ./mvnw -P pg-stop ; ./mvnw -P pg-stop
28+
integration-tests:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v2
32+
- uses: actions/cache@v2
33+
id: ci
34+
with:
35+
path: |
36+
~/.m2/repository
37+
!~/.m2/repository/com/gituhb/daggerok
38+
key: ${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
39+
- uses: actions/cache@v1
40+
with:
41+
path: ~/.n*
42+
key: ${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
43+
- uses: actions/setup-java@v1
44+
with:
45+
java-version: 11
46+
- uses: actions/setup-node@v2
47+
- run: ./mvnw -B dependency:resolve-plugins dependency:resolve
48+
- run: ./mvnw -P pg-stop ; ./mvnw -P pg-start
49+
- run: ./mvnw clean package -DskipTests
50+
- run: java -jar ./target/*.jar &
51+
- run: npx wait-port 8080
52+
- run: sudo apt-get install -y curl
53+
- run: curl -sS localhost:8080/event-stream/00000000-0000-0000-0000-000000000001 &
54+
- run: curl -iv localhost:8080/event-stream &
55+
- run: curl -sSH'Content-Type:application/json' localhost:8080/append-event -d'{"aggregateId":"00000000-0000-0000-0000-000000000001","jsonData":"{\"aggregateId\":\"00000000-0000-0000-0000-000000000001\",\"eventType\":\"VisitorRegisteredEvent\",\"name\":\"Test visitor\"}"}'
56+
- run: curl -sSH'Content-Type:application/json' localhost:8080/append-event -d'{"aggregateId":"00000000-0000-0000-0000-000000000001","jsonData":"{\"aggregateId\":\"00000000-0000-0000-0000-000000000001\",\"eventType\":\"PassCardDeliveredEvent\"}"}'
57+
- run: curl -sSH'Content-Type:application/json' 0:8080/append-event -d'{"aggregateId":"00000000-0000-0000-0000-000000000001","jsonData":"{\"aggregateId\":\"00000000-0000-0000-0000-000000000001\",\"eventType\":\"EnteredTheDoorEvent\",\"doorId\":\"IN-1\"}"}'
58+
- run: curl -sSH'Content-Type:application/json' 0:8080/append-event -d'{"aggregateId":"00000000-0000-0000-0000-000000000001","jsonData":"{\"aggregateId\":\"00000000-0000-0000-0000-000000000001\",\"eventType\":\"EnteredTheDoorEvent\",\"doorId\":\"IN-2\"}"}'
59+
- run: curl -sSH'Content-Type:application/json' 0:8080/append-event -d'{"aggregateId":"00000000-0000-0000-0000-000000000001","jsonData":"{\"aggregateId\":\"00000000-0000-0000-0000-000000000001\",\"eventType\":\"EnteredTheDoorEvent\",\"doorId\":\"OUT-2\"}"}'
60+
- run: ./mvnw -P pg-stop ; ./mvnw -P pg-stop

.gitignore

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
### IntelliJ IDEA ###
2+
.idea
3+
!.idea/
4+
.idea/*
5+
!.idea/codeStyle/
6+
!.idea/runConfigurations/
7+
*/.idea
8+
!*/.idea/
9+
*/.idea/*
10+
!*/.idea/runConfigurations/
11+
!*/.idea/codeStyle/
12+
*.iws
13+
*.iml
14+
*.ipr
15+
*.log*
16+
.gradle/
17+
target/
18+
build/
19+
/out/
20+
**/out/**
21+
22+
### Node JS ###
23+
node_modules/
24+
.cache/
25+
dist/
26+
27+
### STS ###
28+
.apt_generated
29+
.classpath
30+
.factorypath
31+
.project
32+
.settings
33+
.springBeans
34+
.sts4-cache
35+
36+
### NetBeans ###
37+
/nbproject/private/
38+
/nbbuild/
39+
/dist/
40+
/nbdist/
41+
/.nb-gradle/
42+
build/
43+
44+
### VS Code ###
45+
.vscode/
46+
*.suo
47+
*.ntvs*
48+
*.njsproj
49+
*.sln
50+
*.sw?

.idea/runConfigurations/All_in_r2dbc_postgres_json.xml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/pg_start.xml

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/pg_stop.xml

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright 2007-present 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.6";
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.

.mvn/wrapper/maven-wrapper.properties

+2
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.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021-present Maksim Kostromin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# R2DBC EventStore [![CI](https://github.com/daggerok/r2dbc-postgres-json/actions/workflows/ci.yaml/badge.svg)](https://github.com/daggerok/r2dbc-postgres-json/actions/workflows/ci.yaml)
2+
3+
IN PROGRESS: Postgres JSON java application based on Spring Boot and Spring WebFlux with R2DBC, Postgres and nkonev
4+
r2dbc migration tool
5+
6+
## Getting started
7+
8+
```bash
9+
./mvnw -P pg-start
10+
./mvnw spring-boot:run
11+
12+
curl -iv localhost:8080/event-stream/00000000-0000-0000-0000-000000000001
13+
curl -iv localhost:8080/event-stream
14+
15+
curl -sSH'Content-Type:application/json' localhost:8080/append-event -d'{"aggregateId":"00000000-0000-0000-0000-000000000001","jsonData":"{\"aggregateId\":\"00000000-0000-0000-0000-000000000001\",\"eventType\":\"VisitorRegisteredEvent\",\"name\":\"Test visitor\"}"}'
16+
curl -sSH'Content-Type:application/json' localhost:8080/append-event -d'{"aggregateId":"00000000-0000-0000-0000-000000000001","jsonData":"{\"aggregateId\":\"00000000-0000-0000-0000-000000000001\",\"eventType\":\"PassCardDeliveredEvent\"}"}'
17+
curl -sSH'Content-Type:application/json' localhost:8080/append-event -d'{"aggregateId":"00000000-0000-0000-0000-000000000001","jsonData":"{\"aggregateId\":\"00000000-0000-0000-0000-000000000001\",\"eventType\":\"EnteredTheDoorEvent\",\"doorId\":\"IN-1\"}"}'
18+
curl -sSH'Content-Type:application/json' localhost:8080/append-event -d'{"aggregateId":"00000000-0000-0000-0000-000000000001","jsonData":"{\"aggregateId\":\"00000000-0000-0000-0000-000000000001\",\"eventType\":\"EnteredTheDoorEvent\",\"doorId\":\"IN-2\"}"}'
19+
curl -sSH'Content-Type:application/json' localhost:8080/append-event -d'{"aggregateId":"00000000-0000-0000-0000-000000000001","jsonData":"{\"aggregateId\":\"00000000-0000-0000-0000-000000000001\",\"eventType\":\"EnteredTheDoorEvent\",\"doorId\":\"OUT-2\"}"}'
20+
21+
./mvnw -P pg-stop
22+
```
23+
24+
<!--
25+
26+
## Backup & Restore
27+
28+
### Backup
29+
30+
```bash
31+
rm -rf ~/google.drive/r2dbc-postgres-json* ; cd ~/Downloads/_code/r2dbc-postgres-json && zip -r ~/google.drive/r2dbc-postgres-json.zip "../$(basename "$PWD")" && cd -;
32+
# or
33+
cd /tmp ; rm -rf /tmp/r2dbc-postgres-json* ; cd ~/Downloads/_code/r2dbc-postgres-json && zip -r /tmp/r2dbc-postgres-json.zip "../$(basename "$PWD")" && cd -;
34+
```
35+
36+
### Restore
37+
38+
```bash
39+
rm -rf /tmp/r2dbc-postgres-json* ; unzip ~/google.drive/r2dbc-postgres-json.zip -d /tmp
40+
# or
41+
rm -rf /tmp/r2dbc-postgres-json* ; unzip /tmp/r2dbc-postgres-json.zip -d /tmp
42+
```
43+
44+
-->
45+
46+
## RTFM
47+
48+
* https://github.com/pgjdbc/pgjdbc/issues/265#issuecomment-428336719
49+
* http://json-b.net/docs/user-guide.html#mapping-an-object
50+
* https://www.postgresqltutorial.com/postgresql-json/
51+
* https://stackoverflow.com/a/58147091/1490636
52+
* https://projectreactor.io/docs/core/release/reference/#processors

0 commit comments

Comments
 (0)