diff --git a/src/main/java/com/stktrk/app/AppApplication.java b/src/main/java/com/stktrk/app/AppApplication.java index d750c1b..4964f44 100644 --- a/src/main/java/com/stktrk/app/AppApplication.java +++ b/src/main/java/com/stktrk/app/AppApplication.java @@ -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 { @@ -32,31 +33,28 @@ public class AppApplication extends SpringBootServletInitializer { List x = List.of(); - ArcadeGraph g = ConnectionPool.getGraph(); - + 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())); - - g.traversal().V(res.id()).addE("friend").to(target).iterate(); - + 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("
\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.
\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.
\n" + sj; } @GetMapping("/delete") - public String delete () { - ArcadeGraph g = ConnectionPool.getGraph(); + public String delete() { + ArcadeGraph g = ConnectionPool.getGraph(); g.traversal().V().hasLabel("Profile").drop().iterate(); g.close(); return "Done."; diff --git a/src/main/java/com/stktrk/app/configuration/GraphDbConfig.java b/src/main/java/com/stktrk/app/configuration/GraphDbConfig.java index be5bfc2..a9b77f6 100644 --- a/src/main/java/com/stktrk/app/configuration/GraphDbConfig.java +++ b/src/main/java/com/stktrk/app/configuration/GraphDbConfig.java @@ -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; diff --git a/src/main/java/com/stktrk/app/db/ConnectionPool.java b/src/main/java/com/stktrk/app/db/ConnectionPool.java index 5218f2f..d73f1fa 100644 --- a/src/main/java/com/stktrk/app/db/ConnectionPool.java +++ b/src/main/java/com/stktrk/app/db/ConnectionPool.java @@ -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); } diff --git a/src/main/java/com/stktrk/app/db/MigrationWrapper.java b/src/main/java/com/stktrk/app/db/MigrationWrapper.java index 41cc58a..1d0ac2c 100644 --- a/src/main/java/com/stktrk/app/db/MigrationWrapper.java +++ b/src/main/java/com/stktrk/app/db/MigrationWrapper.java @@ -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); diff --git a/src/main/resources/application-rasmus.properties b/src/main/resources/application-rasmus.properties index 4a5d075..e714dbb 100644 --- a/src/main/resources/application-rasmus.properties +++ b/src/main/resources/application-rasmus.properties @@ -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 \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ae66bf1..434e620 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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 \ No newline at end of file