mysql - neo4j configuration for junit and passing arraylist instance in cypher query -
this case retrieving data through mysql , save in arraylist object, need same object cypher query ,am running program junit test `public class dummytest {
@test @rollback(true) public void checkmysqlconnection() { connection connection = null; resultset tabledatasrsult = null; try { class.forname("com.mysql.jdbc.driver"); properties properties = new properties(); properties.setproperty("user", "root"); properties.setproperty("password", "root"); string url = "127.0.0.1:3306/unicity"; connection = drivermanager.getconnection("jdbc:mysql://" + url, properties); assert.assertnotnull(connection); string sqlq = "select dist_id,pv_date,post_date odh"; preparedstatement preparedstatement = connection.preparestatement(sqlq); tabledatasrsult = preparedstatement.executequery(); arraylist<odhdo> odhdos = new arraylist<>(); while (tabledatasrsult.next()) { odhdo odhdo = new odhdo(); odhdo.setdistid(tabledatasrsult.getlong("dist_id")); odhdo.setpvdate(tabledatasrsult.getstring("pv_date")); odhdo.setpostdate(tabledatasrsult.getstring("post_date")); odhdos.add(odhdo); map<string, object> params = new hashmap<>(); params.put(odhdo.getdistid().tostring(), odhdo); system.out.println(params); } } catch (classnotfoundexception e) { system.out.println("mysql driver class not found exception"); e.printstacktrace(); } catch (sqlexception e) { system.out.println("sql exception"); e.printstacktrace(); } { try { connection.close(); } catch (sqlexception e) { e.printstacktrace(); } } } @test @rollback(true) public void checkneo4jconnection(){ string url= "http://localhost:7474"; configuration configuration = new configuration(); configuration.driverconfiguration().setdriverclassname("org.neo4j.ogm.drivers.http.driver.httpdriver").seturi(url).setcredentials("neo4j", "admin"); string cypher = "match (distributor) distributor.distid in {odhdos} return distributor"; map<string, object> params = new hashmap<>(); list<string> odhdos = new arraylist<>(); params.put("odhdos", odhdos); //add names names list //params.put(key, value) }`
in above code in checkmysqlconnection() method have retrieved data , save data in arraylist odhdos = new arraylist<>() object, need pass arraylist instance in cypher query, dont know how configure , connect neo4j class , how can pass arraylist instance inside query "match (distributor) distributor.distid in {odhdos} return distributor" please configuration of junit neo4j , how pass array instance in cypher query..thanks in advance...
if have set according documentation in ogm reference guide should work:
@test public void checkneo4jconnection(){ configuration configuration = new configuration(); configuration.driverconfiguration() .setdriverclassname("org.neo4j.ogm.drivers.http.driver.httpdriver") .seturi("http://localhost:7474") .setcredentials("neo4j", "admin"); sessionfactory sessionfactory = new sessionfactory(configuration, "package.where.your.distributor.class.is"); session session = sessionfactory.opensession(); string cypher = "match (distributor) distributor.distid in {odhdos} return distributor"; map<string, object> params = new hashmap<>(); params.put("odhdos", arrays.aslist(new string[] {"odhdo1", "odhdo2"}); // note: if more 1 result use session.query(). // if one, use session.queryforobject() iterable<distributor> distributors = session.query(distributor.class, cypher, params); (distributor distributor: distributors) { system.out.println(distributor.getdistid()); } }
Comments
Post a Comment