postgres driver updates use dynamic values
This commit is contained in:
parent
c664aca308
commit
d62a331ca9
@ -3,9 +3,8 @@ package com.stktrk.app;
|
|||||||
import com.arcadedb.gremlin.ArcadeGraph;
|
import com.arcadedb.gremlin.ArcadeGraph;
|
||||||
|
|
||||||
import com.github.javafaker.Faker;
|
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.apache.tinkerpop.gremlin.structure.Vertex;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
@ -14,7 +13,6 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package com.stktrk.app;
|
package com.stktrk.app.db;
|
||||||
|
|
||||||
import com.arcadedb.gremlin.ArcadeGraph;
|
import com.arcadedb.gremlin.ArcadeGraph;
|
||||||
import com.arcadedb.gremlin.ArcadeGraphFactory;
|
import com.arcadedb.gremlin.ArcadeGraphFactory;
|
||||||
@ -12,7 +12,6 @@ import javax.annotation.PostConstruct;
|
|||||||
public class ConnectionPool {
|
public class ConnectionPool {
|
||||||
static ArcadeGraphFactory pool;
|
static ArcadeGraphFactory pool;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
GraphDbConfig graphDbConfig;
|
GraphDbConfig graphDbConfig;
|
||||||
|
|
||||||
34
src/main/java/com/stktrk/app/db/MigrationWrapper.java
Normal file
34
src/main/java/com/stktrk/app/db/MigrationWrapper.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package com.stktrk.app.db;
|
||||||
|
|
||||||
|
import com.arcadedb.gremlin.ArcadeGraphFactory;
|
||||||
|
import com.stktrk.app.configuration.GraphDbConfig;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public interface MigrationWrapper {
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
default void executeQuery(GraphDbConfig graphDbConfig, String query) throws ClassNotFoundException, SQLException {
|
||||||
|
|
||||||
|
Class.forName("org.postgresql.Driver");
|
||||||
|
Properties props = new Properties();
|
||||||
|
|
||||||
|
props.setProperty("user", graphDbConfig.getUser());
|
||||||
|
props.setProperty("password", graphDbConfig.getPassword());
|
||||||
|
props.setProperty("ssl", "false");
|
||||||
|
props.setProperty("sslmode", "disable");
|
||||||
|
|
||||||
|
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://" + graphDbConfig.getHost() + ":" + graphDbConfig.getPostgresPort() + "/" + graphDbConfig.getGraphName(), props)) {
|
||||||
|
Statement st = connection.createStatement();
|
||||||
|
st.execute(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.stktrk.app.db.migrations;
|
||||||
|
|
||||||
|
import com.stktrk.app.configuration.GraphDbConfig;
|
||||||
|
import com.stktrk.app.db.MigrationWrapper;
|
||||||
|
import org.flywaydb.core.api.migration.BaseJavaMigration;
|
||||||
|
import org.flywaydb.core.api.migration.Context;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class V1__CreateTest extends BaseJavaMigration implements MigrationWrapper {
|
||||||
|
@Autowired
|
||||||
|
GraphDbConfig graphDbConfig;
|
||||||
|
public void migrate(Context context) throws Exception {
|
||||||
|
this.executeQuery(graphDbConfig,"CREATE VERTEX TYPE test");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,35 +0,0 @@
|
|||||||
package com.stktrk.app.db.migrations;
|
|
||||||
|
|
||||||
import org.flywaydb.core.api.migration.BaseJavaMigration;
|
|
||||||
import org.flywaydb.core.api.migration.Context;
|
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public class V2__CreateTest extends BaseJavaMigration {
|
|
||||||
public void migrate(Context context) throws Exception {
|
|
||||||
|
|
||||||
Class.forName("org.postgresql.Driver");
|
|
||||||
|
|
||||||
Properties props = new Properties();
|
|
||||||
props.setProperty("user", "root");
|
|
||||||
props.setProperty("password", "playwithdata");
|
|
||||||
props.setProperty("ssl", "false");
|
|
||||||
props.setProperty("sslmode", "disable");
|
|
||||||
|
|
||||||
System.out.println ("migration");
|
|
||||||
|
|
||||||
|
|
||||||
try (Connection connection = DriverManager.getConnection("jdbc:postgresql://192.168.178.50:5432/graph", props)) {
|
|
||||||
|
|
||||||
Statement st = connection.createStatement();
|
|
||||||
st.execute("CREATE VERTEX TYPE test");
|
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
System.out.println (e);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user