2016-10-26 5 views
0

이 경우는 MySQL을 통해 데이터를 검색하고 ArrayList 객체에 저장하는 경우입니다. 동일한 객체가 cypher 쿼리에 필요합니다. junit 테스트로 프로그램을 실행하고 있습니다. `공용 클래스 DummyTest {junit에 대한 neo4j 구성과 cypher 쿼리에서 arraylist 인스턴스 전달

checkMysqlConnection() 위의 코드에서
@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 from 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(); 
    } finally { 
     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) WHERE Distributor.DISTID IN {odhDOs} RETURN Distributor";  
    Map<String, Object> params = new HashMap<>(); 
    List<String> odhDOs = new ArrayList<>(); 
    params.put("odhDOs", odhDOs); 

    //add some names to the names list 
    //params.put(key, value) 

    }` 

있어서 난 데이터를 검색하고 의 ArrayList odhDOs = 새로운 ArrayList를 <에이 데이터를 저장할 수있다>() 객체 나 필요 사이퍼 쿼리에서이 Arraylist 인스턴스를 전달하지만이 클래스와 h에서 neo4j를 구성하고 연결하는 방법을 모릅니다. ow 쿼리에이 arraylist 인스턴스를 전달할 수 있습니까? Distributor.DISTID IN {odhDOs} RETURN Distributor neo4j를 사용하여 junit을 구성하고 cypher 쿼리에서 배열 인스턴스를 전달하는 방법을 알려주십시오. 사전에 ..thanks이 ...

+0

당신이라는 클래스를 가지고 있습니까'Distributor'은 주석 Neo4j-OGM 문서에 따라'@ NodeEntity'? https://github.com/neo4j/neo4j-ogm – digx1

+0

예 OGM 당 대리점 클래스가 있습니다 –

답변

0

당신은 다음과 같은 뭔가 일을해야 OGM reference guide의 설명서에 따라 적절하게 모든 것을 설정 한 경우 :

@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) WHERE Distributor.DISTID IN {odhDOs} RETURN Distributor";  
    Map<String, Object> params = new HashMap<>(); 
    params.put("odhDOs", Arrays.asList(new String[] {"odhDO1", "odhDO2"}); 

    // NOTE: If more than one result use session.query(). 
    //  If just one, use session.queryForObject() 
    Iterable<Distributor> distributors = session.query(Distributor.class, cypher, params); 

    for (Distributor distributor: distributors) { 
     System.out.println(distributor.getDISTID()); 
    } 
} 
+0

고맙습니다. 나는이 작업에 착수했습니다. –