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();
}
}
}
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();
}
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();
}
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;
}
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);
}
Aggregations