Merge pull request 'static pool provider, cleaned test and added fake-data library to play with.' (#4) from connectionPool into main

Reviewed-on: binarygolem/stktrk#4
This commit is contained in:
rasmus 2024-08-19 02:27:08 +02:00
commit 209696539a
4 changed files with 57 additions and 8 deletions

View File

@ -162,6 +162,11 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
<build>

View File

@ -9,8 +9,8 @@ Might have to
- mvn spring-boot:run
- in IntelliJ: Run Icon in `src/main/java/com/stktrk/app/AppApplication.java`
http://localhost:9090/swagger-ui/index.html#/app-application/sayHello
http://localhost:9090/hello?myName=Rasmus
http://localhost:9090/swagger-ui/index.html
http://localhost:9090/actuator

View File

@ -1,8 +1,8 @@
package com.stktrk.app;
import com.arcadedb.gremlin.ArcadeGraph;
import com.arcadedb.gremlin.ArcadeGraphFactory;
import com.github.javafaker.Faker;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.List;
import java.util.StringJoiner;
@ -29,15 +30,37 @@ public class AppApplication extends SpringBootServletInitializer {
List<Vertex> x = List.of();
try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("192.168.178.50", 2480, "graph", "root", "playwithdata")) {
/* try (ArcadeGraphFactory pool = ArcadeGraphFactory.withRemote("192.168.178.50", 2480, "graph", "root", "playwithdata")) {
try (ArcadeGraph graph = pool.get()) {
x = graph.traversal().V().toList();
}
}
StringJoiner sj = new StringJoiner(", ");
x.forEach(v -> sj.add((String) v.property("name").value()));
}*/
ArcadeGraph g = ConnectionPool.getGraph();
Faker faker = new Faker();
g.traversal().addV("Profile").property("name", faker.name().firstName()).property("lastName", faker.name().lastName())
.iterate();
x = g.traversal().V().toList();
g.close();
x.sort((a, b) -> a.id().toString().compareTo(b.id().toString()));
StringJoiner sj = new StringJoiner("<br />\n");
x.forEach(v -> sj.add(v.id().toString()+ " - " +(String) v.property("name").value() + " " + (String) v.property("lastName").value() ));
return "Hello, " + name + "! There are " + x.size() + " vertices.<br/>\n" + sj;
}
@GetMapping("/delete")
public String delete () {
ArcadeGraph g = ConnectionPool.getGraph();
g.traversal().V().hasLabel("Profile").drop().iterate();
g.close();
return "Done.";
return "Hello, " + name + "! There are " + x.size() + " vertices.\n" + sj;
}
}

View File

@ -0,0 +1,21 @@
package com.stktrk.app;
import com.arcadedb.gremlin.ArcadeGraph;
import com.arcadedb.gremlin.ArcadeGraphFactory;
public class ConnectionPool {
static final ArcadeGraphFactory pool;
static {
try {
pool = ArcadeGraphFactory.withRemote("192.168.178.50", 2480, "graph", "root", "playwithdata");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static ArcadeGraph getGraph(){
return pool.get();
}
}