Search in sources :

Example 76 with Driver

use of org.h2.Driver in project open-kilda by telstra.

the class FlowJanitor method main.

/**
 * With the right URL, username, password, and method keyword, the methods above can be called.
 */
@SuppressWarnings({ "squid:S106", "squid:S1135" })
public static void main(String[] args) {
    Options options = new Options();
    options.addOption(Option.builder("url").required(true).hasArg().desc("The URL of the Neo4J DB - i.e. bolt://neo..:7474").build());
    options.addOption(Option.builder("u").required(true).hasArg().longOpt("user").desc("The Neo4J username - e.g. neo4j").build());
    options.addOption(Option.builder("p").required(true).hasArg().longOpt("password").desc("The Neo4J password - e.g. neo4j").build());
    options.addOption(Option.builder("nburl").required(true).hasArg().desc("The URL of the Neo4J DB - i.e. http://northboud..:8080").build());
    options.addOption(Option.builder("nbu").required(true).hasArg().longOpt("user").desc("The Neo4J username - e.g. kilda").build());
    options.addOption(Option.builder("nbp").required(true).hasArg().longOpt("password").desc("The Neo4J password - e.g. kilda").build());
    options.addOption(Option.builder("a").required(true).hasArg().longOpt("action").desc("The action to take - e.g. ountDuplicateCookies").build());
    options.addOption(Option.builder("v").required(false).longOpt("verbose").desc("Where appropriate, return a verbose response").build());
    CommandLine commandLine;
    CommandLineParser parser = new DefaultParser();
    Driver driver = null;
    try {
        commandLine = parser.parse(options, args);
        FlowJanitor.Config config = new FlowJanitor.Config();
        config.neoUrl = commandLine.getOptionValue("url");
        config.neoUser = commandLine.getOptionValue("u");
        config.neoPswd = commandLine.getOptionValue("p");
        config.nbUrl = commandLine.getOptionValue("nburl");
        config.nbUser = commandLine.getOptionValue("nbu");
        config.nbPswd = commandLine.getOptionValue("nbp");
        config.action = commandLine.getOptionValue("a");
        driver = GraphDatabase.driver(config.neoUrl, AuthTokens.basic(config.neoUser, config.neoPswd));
        if (config.action.equals("DeDupeFlows")) {
            Session session = driver.session();
            StatementResult result = session.run(DUPLICATE_FLOWS_QUERY);
            Map<String, List<Long>> flowsToUpdate = new HashMap<>();
            for (Record record : result.list()) {
                String flowid = record.get("affected_flow_id").asString();
                List<Long> priors = flowsToUpdate.computeIfAbsent(flowid, empty -> new ArrayList<>());
                priors.add(record.get("affected_flow_cookie").asLong());
            }
            session.close();
            System.out.println("flowsToUpdate.size() = " + flowsToUpdate.size());
            System.out.println("flowsToUpdate = " + flowsToUpdate);
            System.out.println("Will De-Dupe the Flows");
            String authString = config.nbUser + ":" + config.nbPswd;
            String authStringEnc = Base64.getEncoder().encodeToString(authString.getBytes());
            Client client = ClientBuilder.newClient();
            for (String flowid : flowsToUpdate.keySet()) {
                /*
                     * Get the Flows .. call NB for each
                     */
                sleep();
                System.out.println("RUNNING: flowid = " + flowid);
                WebTarget webTarget = client.target(config.nbUrl + "flows").path(flowid);
                Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON).header("Authorization", "Basic " + authStringEnc);
                Response response = invocationBuilder.get(Response.class);
                if (response.getStatus() != 200) {
                    throw new IllegalStateException("Failed : HTTP error code : " + response.getStatus());
                }
                String output = response.readEntity(String.class);
                System.out.println("output = " + output);
                System.exit(0);
            }
        } else {
            // TODO: switch, based on action
            Session session = driver.session();
            StatementResult result = session.run(DUPLICATE_COOKIES_QUERY);
            List<String> flowsToUpdate = new ArrayList<>();
            for (Record record : result.list()) {
                flowsToUpdate.add(record.get("affected_flow_id").asString());
            }
            session.close();
            System.out.println("flowsToUpdate.size() = " + flowsToUpdate.size());
            System.out.println("flowsToUpdate = " + flowsToUpdate);
            System.exit(0);
            FlowJanitor.updateFlows(config, flowsToUpdate);
        }
    } catch (ParseException exception) {
        System.out.print("Parse error: ");
        System.out.println(exception.getMessage());
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("FlowJanitor", options);
    } finally {
        if (driver != null) {
            driver.close();
        }
    }
}
Also used : Options(org.apache.commons.cli.Options) StatementResult(org.neo4j.driver.v1.StatementResult) Invocation(javax.ws.rs.client.Invocation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Driver(org.neo4j.driver.v1.Driver) HelpFormatter(org.apache.commons.cli.HelpFormatter) ArrayList(java.util.ArrayList) List(java.util.List) Record(org.neo4j.driver.v1.Record) CommandLineParser(org.apache.commons.cli.CommandLineParser) Client(javax.ws.rs.client.Client) DefaultParser(org.apache.commons.cli.DefaultParser) Response(javax.ws.rs.core.Response) CommandLine(org.apache.commons.cli.CommandLine) WebTarget(javax.ws.rs.client.WebTarget) ParseException(org.apache.commons.cli.ParseException) Session(org.neo4j.driver.v1.Session)

Example 77 with Driver

use of org.h2.Driver in project tutorials by eugenp.

the class Neo4JServerLiveTest method standAloneDriver.

@Test
public void standAloneDriver() {
    Driver driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic("neo4j", "12345"));
    Session session = driver.session();
    session.run("CREATE (baeldung:Company {name:\"Baeldung\"}) " + "-[:owns]-> (tesla:Car {make: 'tesla', model: 'modelX'})" + "RETURN baeldung, tesla");
    StatementResult result = session.run("MATCH (company:Company)-[:owns]-> (car:Car)" + "WHERE car.make='tesla' and car.model='modelX'" + "RETURN company.name");
    Assert.assertTrue(result.hasNext());
    Assert.assertEquals(result.next().get("company.name").asString(), "Baeldung");
    session.close();
    driver.close();
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 78 with Driver

use of org.h2.Driver in project nzbhydra2 by theotherp.

the class NzbHydra method repairDb.

protected static void repairDb(String databaseFilePath) throws ClassNotFoundException {
    if (!databaseFilePath.contains("mv.db")) {
        databaseFilePath = databaseFilePath + ".mv.db";
    }
    File file = new File(databaseFilePath);
    if (!file.exists()) {
        logger.error("File {} doesn't exist", file.getAbsolutePath());
    }
    databaseFilePath = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 6);
    Flyway flyway = new Flyway();
    flyway.setLocations("classpath:migration");
    Class.forName("org.h2.Driver");
    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:file:" + databaseFilePath);
    dataSource.setUser("sa");
    flyway.setDataSource(dataSource);
    flyway.repair();
}
Also used : Flyway(org.flywaydb.core.Flyway) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) File(java.io.File)

Example 79 with Driver

use of org.h2.Driver in project symmetric-ds by JumpMind.

the class DbSqlCommand method executeWithOptions.

@Override
protected boolean executeWithOptions(CommandLine line) throws Exception {
    BasicDataSource basicDataSource = getDatabasePlatform(false).getDataSource();
    String url = basicDataSource.getUrl();
    String user = basicDataSource.getUsername();
    String password = basicDataSource.getPassword();
    String driver = basicDataSource.getDriverClassName();
    Shell shell = new Shell();
    if (line.hasOption(OPTION_SQL)) {
        String sql = line.getOptionValue(OPTION_SQL);
        shell.runTool("-url", url, "-user", user, "-password", password, "-driver", driver, "-sql", sql);
    } else {
        shell.runTool("-url", url, "-user", user, "-password", password, "-driver", driver);
    }
    return true;
}
Also used : Shell(org.h2.tools.Shell) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 80 with Driver

use of org.h2.Driver in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method beforeAll.

@BeforeAll
public static void beforeAll() throws Exception {
    Driver h2Driver = new Driver();
    DriverManager.registerDriver(h2Driver);
}
Also used : Driver(org.h2.Driver) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

Driver (org.neo4j.driver.v1.Driver)41 Test (org.junit.Test)38 Session (org.neo4j.driver.v1.Session)30 Connection (java.sql.Connection)23 StatementResult (org.neo4j.driver.v1.StatementResult)17 Statement (java.sql.Statement)14 SQLException (java.sql.SQLException)11 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)10 Record (org.neo4j.driver.v1.Record)10 IOException (java.io.IOException)9 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)9 Driver (org.h2.Driver)8 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 HashSet (java.util.HashSet)5 Server (org.h2.tools.Server)5 File (java.io.File)4 PrintStream (java.io.PrintStream)4 Transaction (org.neo4j.driver.v1.Transaction)4 SessionExpiredException (org.neo4j.driver.v1.exceptions.SessionExpiredException)4