BAEL-7259
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>java-harperdb</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>persistence-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>java-harperdb</artifactId>
|
||||
<version>4.2</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/cdata.jdbc.harperdb.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers-bom</artifactId>
|
||||
<version>1.19.3</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>19</maven.compiler.source>
|
||||
<maven.compiler.target>19</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,41 @@
|
||||
@startuml
|
||||
'https://gist.github.com/QuantumGhost/0955a45383a0b6c0bc24f9654b3cb561
|
||||
' uncomment the line below if you're using computer with a retina display
|
||||
' skinparam dpi 300
|
||||
!theme sketchy-outline
|
||||
!define Table(name,desc) class name as "desc" << (T, #63b175) >>
|
||||
' we use bold for primary key
|
||||
' green color for unique
|
||||
' and underscore for not_null
|
||||
!define primary_key(x) <b>x</b>
|
||||
!define unique(x) <color:green>x</color>
|
||||
!define not_null(x) <u>x</u>
|
||||
' other tags available:
|
||||
' <i></i>
|
||||
' <back:COLOR></color>, where color is a color name or html color code
|
||||
' (#FFAACC)
|
||||
' see: http://plantuml.com/classes.html#More
|
||||
hide methods
|
||||
hide stereotypes
|
||||
|
||||
' entities
|
||||
|
||||
|
||||
Table(Teacher, "Teacher") {
|
||||
primary_key(Id) Number
|
||||
Name Varchar
|
||||
joining_date Date
|
||||
}
|
||||
Table(Subject, "Subject") {
|
||||
primary_key(Id) Number
|
||||
Name Varchar
|
||||
}
|
||||
Table(Teacher_Details, "Teacher_Details") {
|
||||
primary_key(Id) Number
|
||||
teacher_id Number
|
||||
subject_id Number
|
||||
}
|
||||
|
||||
Teacher_Details "*" -left-> "1" Subject: " "
|
||||
Teacher "1" -left-> "*" Teacher_Details: " "
|
||||
@enduml
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package com.baledung.harperdb;
|
||||
|
||||
import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.classic.methods.HttpPost;
|
||||
import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
||||
import com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
||||
import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.ClassicHttpRequest;
|
||||
import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.HttpEntity;
|
||||
import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.io.entity.StringEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
|
||||
public class HarperDBApiService {
|
||||
private String url;
|
||||
private String base64auth;
|
||||
|
||||
public HarperDBApiService(String url, String user, String password) {
|
||||
this.url = url;
|
||||
this.base64auth = Base64.getEncoder()
|
||||
.encodeToString(new StringBuilder().append(user).append(":").append(password).toString().getBytes());
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(HarperDBApiService.class);
|
||||
|
||||
public void createSchema(String schema) throws IOException {
|
||||
String requestBody = "{\"operation\":\"create_schema\", \"" + "schema\":\"" + schema + "\"" + "}";
|
||||
executeHttpPostRequest(requestBody);
|
||||
}
|
||||
|
||||
public void createTable(String schema, String table, String ... attributes) throws IOException {
|
||||
String createTableReq = "{\"operation\":\"create_table\","
|
||||
+ "\"schema\":\"" + schema
|
||||
+ "\",\"table\":\"" + table
|
||||
+ "\",\"hash_attribute\":\"id\""
|
||||
+ "}";
|
||||
executeHttpPostRequest(createTableReq);
|
||||
LOGGER.info("created table:" + table);
|
||||
for (String attribute : attributes) {
|
||||
String createAttrReq = "{\"operation\":\"create_attribute\",\"schema\":\""
|
||||
+ schema + "\",\"table\":\""
|
||||
+ table + "\",\"attribute\":\""
|
||||
+ attribute + "\""
|
||||
+ "}";
|
||||
executeHttpPostRequest(createAttrReq);
|
||||
LOGGER.info("created attribute:" + attribute + " in table:" + table);
|
||||
}
|
||||
}
|
||||
|
||||
public void insertRecords(String schema, String table, String records) throws IOException {
|
||||
String requestBody = "{\"table\":" + "\"" + table + "\","
|
||||
+ "\"schema\":" + "\"" + schema + "\"" + ","
|
||||
+ "\"operation\":" + "\"" + "insert" + "\"" + ","
|
||||
+ "\"records\":" + records
|
||||
+ "}";
|
||||
executeHttpPostRequest(requestBody);
|
||||
}
|
||||
|
||||
private void executeHttpPostRequest(String httpRequest) throws IOException {
|
||||
LOGGER.info("Post request body:" + httpRequest);
|
||||
|
||||
try (CloseableHttpClient closeableHttpClient = HttpClientBuilder.create().build()) {
|
||||
HttpPost request = new HttpPost(this.url);
|
||||
request.addHeader("Authorization", "Basic " + this.base64auth);
|
||||
request.addHeader("Content-Type", "application/json");
|
||||
request.setEntity((HttpEntity) new StringEntity(httpRequest));
|
||||
CloseableHttpResponse response = closeableHttpClient.execute((ClassicHttpRequest) request);
|
||||
LOGGER.info("REST API response:" + response.toString());
|
||||
assert(200 == response.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.baledung.harperdb;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class HarperDBContainer {
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(HarperDBContainer.class);
|
||||
|
||||
|
||||
|
||||
private static final Map<String, String> DEFAULT_ENV_MAP = Map.of(
|
||||
"HDB_ADMIN_USERNAME", "admin",
|
||||
"HDB_ADMIN_PASSWORD", "password",
|
||||
"OPERATIONSAPI_NETWORK_PORT", "9925",
|
||||
"ROOTPATH", "/home/harperdb/hdb",
|
||||
"LOGGING_STDSTREAMS", "true"
|
||||
);
|
||||
|
||||
private static final Integer[] DEFAULT_EXPOSED_PORTS = {9925, 9926};
|
||||
|
||||
private static final String HARPER_DOCKER_IMAGE = "harperdb/harperdb:latest";
|
||||
|
||||
public void stop() {
|
||||
harperDBContainer.stop();
|
||||
}
|
||||
GenericContainer harperDBContainer;
|
||||
public GenericContainer installHarperDB() {
|
||||
harperDBContainer = new GenericContainer(HARPER_DOCKER_IMAGE)
|
||||
.withEnv(DEFAULT_ENV_MAP)
|
||||
.withExposedPorts(DEFAULT_EXPOSED_PORTS);
|
||||
return harperDBContainer;
|
||||
}
|
||||
|
||||
public GenericContainer installHarperDB(String dockerImgage, final Map<String, String> envMap, final Integer ... exposedPorts) {
|
||||
return new GenericContainer(dockerImgage)
|
||||
.withEnv(envMap)
|
||||
.withExposedPorts(exposedPorts);
|
||||
}
|
||||
}
|
||||
+336
File diff suppressed because it is too large
Load Diff
+356
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user