#364 postgres driver updates use dynamic values

This commit is contained in:
Rasmus Neikes 2024-11-10 16:43:46 +01:00
parent c1940875e3
commit 8117640b5a
6 changed files with 49 additions and 24 deletions

View File

@ -3,6 +3,7 @@ package com.stktrk.app;
import com.arcadedb.gremlin.ArcadeGraph;
import com.github.javafaker.Faker;
import com.stktrk.app.configuration.GraphDbConfig;
import com.stktrk.app.db.ConnectionPool;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.springframework.boot.SpringApplication;
@ -19,7 +20,7 @@ import java.util.Random;
import java.util.StringJoiner;
// https://stackoverflow.com/questions/51221777/failed-to-configure-a-datasource-url-attribute-is-not-specified-and-no-embedd
@SpringBootApplication(exclude = { FlywayAutoConfiguration.class})
@SpringBootApplication(exclude = {FlywayAutoConfiguration.class})
@RestController
public class AppApplication extends SpringBootServletInitializer {
@ -33,29 +34,26 @@ public class AppApplication extends SpringBootServletInitializer {
List<Vertex> x = List.of();
ArcadeGraph g = ConnectionPool.getGraph();
x = g.traversal().V().toList();
Vertex target = !x.isEmpty() ? x.get(new Random().nextInt(x.size())) : null;
Faker faker = new Faker();
Vertex res = g.traversal().addV("Profile").property("name", faker.name().firstName()).property("lastName", faker.name().lastName())
.next();
x = g.traversal().V().toList();
Vertex target = x.get(new Random().nextInt(x.size()));
if (target != null) {
g.traversal().V(res.id()).addE("friend").to(target).iterate();
}
g.close();
x.add(res);
x.sort(Comparator.comparing(a -> a.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 + "! Added "+ res.property("name").value() + ". There are " + x.size() + " vertices.<br/>\n" + sj;
x.forEach(v -> sj.add(v.id().toString() + " - " + (String) v.property("name").value() + " " + (String) v.property("lastName").value()));
return "Hello, " + name + "! Added " + res.property("name").value() + ". There are " + x.size() + " vertices.<br/>\n" + sj;
}
@GetMapping("/delete")
public String delete () {
public String delete() {
ArcadeGraph g = ConnectionPool.getGraph();
g.traversal().V().hasLabel("Profile").drop().iterate();
g.close();

View File

@ -1,6 +1,7 @@
package com.stktrk.app.configuration;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

View File

@ -3,6 +3,7 @@ package com.stktrk.app.db;
import com.arcadedb.gremlin.ArcadeGraph;
import com.arcadedb.gremlin.ArcadeGraphFactory;
import com.stktrk.app.configuration.GraphDbConfig;
import org.apache.commons.configuration2.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -19,6 +20,7 @@ public class ConnectionPool {
void init () {
try {
pool = ArcadeGraphFactory.withRemote(graphDbConfig.getHost(), graphDbConfig.getHttpPort(), graphDbConfig.getGraphName(), graphDbConfig.getUser(), graphDbConfig.getPassword());
} catch (Exception e) {
throw new RuntimeException(e);
}

View File

@ -21,6 +21,8 @@ public interface MigrationWrapper {
props.setProperty("ssl", "false");
props.setProperty("sslmode", "disable");
System.out.println ( graphDbConfig.getHost());
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://" + graphDbConfig.getHost() + ":" + graphDbConfig.getPostgresPort() + "/" + graphDbConfig.getGraphName(), props)) {
Statement st = connection.createStatement();
st.execute(query);

View File

@ -10,16 +10,16 @@ springdoc.swagger-ui.path=/swagger-ui.html
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url= jdbc:postgresql://192.168.178.50:7654/flyway_db
spring.datasource.url= jdbc:postgresql://localhost:7654/flyway_db
spring.datasource.username=flyway_user
spring.datasource.password=7e7v55UcYGrY0e3UPYI0qtyMA4YJ1ZkTEaoyZ252GluFkiEMHVT9U5ULS7Rg2rGi
spring.datasource.password=stdUNmu7KTUQV6KGMKjzHIiwQ2gbipArvg02
spring.datasource.defaultSchema=flyway_db
spring.datasource.hikari.schema=flyway_db
graph.user=root
graph.password=playwithdata
graph.connection=jdbc:postgresql://192.168.178.50:5432/graph
graph.connection=jdbc:postgresql://192.168.178.29:5432/graph
graph.http-port:2480
graph.postgres-port:5432
graph.host=192.168.178.50
graph.host=192.168.178.29
graph.graph-name=graph

View File

@ -9,17 +9,39 @@ springdoc.swagger-ui.path=/swagger-ui.html
#spring.flyway.locations=classpath:com/stktrk/app/db/migrations
#spring.datasource.driver-class-name=org.postgresql.Driver
#spring.datasource.url= jdbc:postgresql://192.168.178.50:7654/flyway_db
#spring.datasource.username=flyway_user2
#spring.datasource.password=7e7v55UcYGrY0e3UPYI0qtyMA4YJ1ZkTEaoyZ252GluFkiEMHVT9U5ULS7Rg2rGi
#spring.datasource.defaultSchema=flyway_db
#spring.datasource.hikari.schema=flyway_db
#graph.user=root
##graph.password=playwithdata
#graph.connection=jdbc:postgresql://192.168.178.50:5432/graph
#graph.http-port:2480
#graph.postgres-port:5432
#graph.host=192.168.178.50
#graph.graph-name=graph
#spring.flyway.user=flyway_user
#spring.flyway.password=7e7v55UcYGrY0e3UPYI0qtyMA4YJ1ZkTEaoyZ252GluFkiEMHVT9U5ULS7Rg2rGi
#spring.flyway.schemas=flyway_db
#spring.flyway.url=jdbc:postgresql://192.168.178.50:7654/flyway_db
#spring.flyway.locations=classpath:com/stktrk/app/db/migrations
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url= jdbc:postgresql://192.168.178.50:7654/flyway_db
spring.datasource.username=flyway_user2
spring.datasource.password=7e7v55UcYGrY0e3UPYI0qtyMA4YJ1ZkTEaoyZ252GluFkiEMHVT9U5ULS7Rg2rGi
spring.datasource.url= jdbc:postgresql://localhost:7654/flyway_db
spring.datasource.username=flyway_user
spring.datasource.password=stdUNmu7KTUQV6KGMKjzHIiwQ2gbipArvg02
spring.datasource.defaultSchema=flyway_db
spring.datasource.hikari.schema=flyway_db
graph.user=root
graph.password=playwithdata
graph.connection=jdbc:postgresql://192.168.178.50:5432/graph
graph.connection=jdbc:postgresql://localhost:5432/graph
graph.http-port:2480
graph.postgres-port:5432
graph.host=192.168.178.50
graph.host=localhost
graph.graph-name=graph